/* ==========================================================================
   th-design.css - the TripHero design system.

   This file is the source of truth for how TripHero looks and behaves.
   The written standard describes the intent; this file enforces it.

   Rules of the road:
     1. Pages do not invent colors. Use a --th- token or add one here.
     2. Every colour pair below is contrast-checked. Do not mix pairs.
     3. Anything reusable belongs here, not in a page's <style> block.

   Load it before any page styles:
     <link rel="stylesheet" href="th-design.css">
   ========================================================================== */

/* --------------------------------------------------------------- 1. tokens */

:root {
  /* Brand. Two core colours plus ink. Everything else is a neutral. */
  --th-blue:        #1E09E0;
  --th-blue-dark:   #1409A8;   /* pressed / hover */
  --th-blue-soft:   #EEF0FE;   /* tinted surface */
  --th-navy:        #0B0D17;   /* dark sections */

  /* Neutrals, light to dark. */
  --th-page:        #FAFAFC;
  --th-surface:     #FFFFFF;
  --th-line:        #ECEEF6;
  --th-faint:       #68708F;   /* 4.88:1 on white. #8189A8 failed at 3.46:1 */
  --th-muted:       #4A5578;   /* body text */
  --th-ink:         #0E1330;   /* headings */

  /* Semantic. Each has a text colour, a surface and a border. */
  --th-good:        #008136;   /* 4.51:1 on --th-good-bg. #12994E failed at 3.33:1 */
  --th-good-bg:     #EAF6EF;
  --th-good-line:   #BFE3CD;
  --th-warn:        #8A5A00;
  --th-warn-bg:     #FDF4E3;
  --th-warn-line:   #EFD9A8;
  --th-bad:         #B4232C;
  --th-bad-bg:      #FDEDEE;
  --th-bad-line:    #F3C7CA;

  /* On-dark text. Only these two are legible on --th-navy. */
  --th-on-dark:     #EEF0FB;
  --th-on-dark-dim: #98A2C8;

  /* Focus. One ring, everywhere, never removed. */
  --th-focus:       #A9A0FF;
  --th-focus-ring:  0 0 0 3px var(--th-focus);

  /* Type scale. Clamped so it works from 320px to desktop with no jumps. */
  --th-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --th-t-hero:  clamp(36px, 5.5vw, 56px);
  --th-t-h2:    clamp(26px, 3.4vw, 38px);
  --th-t-h3:    18px;
  --th-t-body:  16px;
  --th-t-small: 13.5px;
  --th-t-micro: 12px;   /* floor. Nothing smaller ships. */

  --th-lh-tight: 1.15;
  --th-lh-head:  1.25;
  --th-lh-body:  1.65;

  /* Spacing. A 4px base, so vertical rhythm stays consistent. */
  --th-s1: 4px;  --th-s2: 8px;  --th-s3: 12px; --th-s4: 16px;
  --th-s5: 24px; --th-s6: 32px; --th-s7: 56px; --th-s8: 96px;

  /* Rectangular, dashboard-style geometry. Pills are retired: the pill token is
     now a small radius so buttons and chips read as crisp rectangles. */
  --th-r-sm: 5px; --th-r-md: 6px; --th-r-lg: 8px; --th-r-pill: 4px;

  --th-shadow-1: 0 1px 2px rgba(20,20,43,.03), 0 4px 12px rgba(20,20,43,.03);
  --th-shadow-2: 0 1px 2px rgba(20,20,43,.04), 0 12px 32px rgba(20,20,43,.06);
  --th-shadow-hover: 0 2px 4px rgba(20,20,43,.05), 0 20px 48px rgba(20,20,43,.10);

  /* Layout */
  --th-measure: 68ch;   /* longest comfortable line of text */
  --th-wrap:    820px;
  --th-wrap-wide: 1120px;

  /* Minimum comfortable touch target. Apple and Google both say 44px. */
  --th-tap: 44px;

  --th-ease: cubic-bezier(.2,.7,.3,1);
  --th-fast: .12s;
  --th-slow: .28s;
}

/* ------------------------------------------------------------- 2. baseline */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--th-page);
  color: var(--th-ink);
  font-family: var(--th-font);
  font-size: var(--th-t-body);
  line-height: var(--th-lh-body);
  -webkit-font-smoothing: antialiased;
  /* Respect the notch and the home indicator on phones. */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

h1, h2, h3, h4 { color: var(--th-ink); letter-spacing: -0.025em; margin: 0 0 var(--th-s3); font-weight: 600; }
h1 { font-size: var(--th-t-hero); line-height: 1.08; letter-spacing: -0.04em; text-wrap: balance; }
h2 { font-size: var(--th-t-h2);   line-height: 1.15; letter-spacing: -0.03em; text-wrap: balance; }
h3 { font-size: var(--th-t-h3);   line-height: var(--th-lh-head); }

p { margin: 0 0 var(--th-s3); color: var(--th-muted); }
p, li { max-width: var(--th-measure); }

a { color: var(--th-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

img, svg, video { max-width: 100%; height: auto; }

/* One focus ring for the whole product. Keyboard only, so mouse users
   never see it, which is the usual reason people delete focus styles. */
:focus-visible {
  outline: none;
  box-shadow: var(--th-focus-ring);
  border-radius: var(--th-r-sm);
}

/* Skip link. Required for keyboard users on every page. */
.th-skip {
  position: absolute; left: -9999px; top: 0; z-index: 999;
  background: var(--th-surface); color: var(--th-blue);
  padding: var(--th-s3) var(--th-s4); border-radius: 0 0 var(--th-r-md) 0;
  font-weight: 600;
}
.th-skip:focus { left: 0; }

.th-visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ------------------------------------------------------------- 3. layout */

.th-wrap { max-width: var(--th-wrap); margin: 0 auto; padding: 0 var(--th-s5); }
.th-wrap-wide { max-width: var(--th-wrap-wide); margin: 0 auto; padding: 0 var(--th-s5); }
.th-section { padding: var(--th-s8) 0; border-top: 1px solid var(--th-line); }
.th-stack > * + * { margin-top: var(--th-s4); }

/* ------------------------------------------------------------- 4. buttons */

.th-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--th-s2);
  min-height: var(--th-tap);
  padding: var(--th-s3) var(--th-s5);
  border: 1px solid transparent; border-radius: var(--th-r-pill);
  font: inherit; font-size: var(--th-t-body); font-weight: 600;
  cursor: pointer; text-align: center;
  transition: background var(--th-fast) var(--th-ease),
              border-color var(--th-fast) var(--th-ease),
              transform var(--th-fast) var(--th-ease);
}
.th-btn:hover { text-decoration: none; }
.th-btn:active { transform: translateY(1px); }
.th-btn[disabled], .th-btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }

.th-btn-primary   { background: var(--th-blue); color: #fff; box-shadow: 0 8px 20px rgba(30,9,224,.22); }
.th-btn-primary:hover { background: var(--th-blue-dark); color: #fff; transform: translateY(-1px); box-shadow: 0 12px 28px rgba(30,9,224,.28); }

.th-btn-secondary { background: var(--th-surface); color: var(--th-ink); border-color: var(--th-line); }
.th-btn-secondary:hover { border-color: #C3C9E2; }

.th-btn-ghost     { background: transparent; color: var(--th-blue); }
.th-btn-ghost:hover { background: var(--th-blue-soft); }

/* One primary action per view. Enforced by eye, flagged in review. */

/* ------------------------------------------------------------- 5. surfaces */

.th-card {
  background: var(--th-surface);
  border: 1px solid var(--th-line);
  border-radius: var(--th-r-lg);
  padding: var(--th-s6);
  box-shadow: var(--th-shadow-2);
  transition: box-shadow var(--th-slow) var(--th-ease), transform var(--th-slow) var(--th-ease);
}
.th-card:hover { box-shadow: var(--th-shadow-hover); transform: translateY(-2px); }
.th-card-flat { box-shadow: var(--th-shadow-1); }

/* HUD card. A dark, dashboard-style surface for feature and result cards,
   sitting on light pages so it reads like a readout. Solid fills only (no
   gradients). Add the class to any card; text inside flips to the on-dark
   palette automatically. For all four corner brackets, drop a
   <span class="th-cnr"></span> inside; without it you still get two. */
.th-hud {
  position: relative; isolation: isolate;
  background: #0d1330;
  border: 1px solid rgba(169,182,255,.22);
  border-radius: 6px;
  padding: var(--th-s6);
  color: var(--th-on-dark);
  box-shadow: inset 0 1px 0 0 rgba(169,182,255,.28), 0 12px 30px rgba(8,11,30,.26);
  transition: border-color var(--th-fast) var(--th-ease),
              box-shadow var(--th-slow) var(--th-ease),
              transform var(--th-slow) var(--th-ease);
}
.th-hud:hover {
  transform: translateY(-2px);
  border-color: rgba(169,182,255,.4);
  box-shadow: inset 0 1px 0 0 rgba(169,182,255,.36), 0 18px 44px rgba(8,11,30,.4);
}
/* Text on the dark card. */
.th-hud h1, .th-hud h2, .th-hud h3, .th-hud h4 { color: var(--th-on-dark); }
.th-hud p, .th-hud li { color: var(--th-on-dark-dim); }
.th-hud a:not(.th-btn):not(.thx-cta) { color: #a9b6ff; }
.th-hud strong { color: var(--th-on-dark); }
/* Corner brackets. Two from the card itself; the optional .th-cnr adds two more. */
.th-hud::before, .th-hud::after,
.th-hud > .th-cnr::before, .th-hud > .th-cnr::after {
  content: ''; position: absolute; width: 12px; height: 12px; pointer-events: none;
  border: 0 solid rgba(169,182,255,.5); z-index: 2;
}
.th-hud::before { top: 9px; left: 9px; border-top-width: 1.5px; border-left-width: 1.5px; }
.th-hud::after  { bottom: 9px; right: 9px; border-bottom-width: 1.5px; border-right-width: 1.5px; }
.th-hud > .th-cnr::before { top: 9px; right: 9px; border-top-width: 1.5px; border-right-width: 1.5px; }
.th-hud > .th-cnr::after  { bottom: 9px; left: 9px; border-bottom-width: 1.5px; border-left-width: 1.5px; }
/* The energized variant, for a recommended / primary card. */
.th-hud-pick {
  border-color: rgba(92,225,255,.55);
  background: #0f1838;
  box-shadow: inset 0 1px 0 0 rgba(92,225,255,.55), 0 0 0 1px rgba(92,225,255,.2), 0 16px 40px rgba(10,40,64,.38);
}
.th-hud-pick::before, .th-hud-pick::after,
.th-hud-pick > .th-cnr::before, .th-hud-pick > .th-cnr::after { border-color: rgba(122,232,255,.9); }
/* HUD detail helpers, reusable across cards. */
.th-hud-eyebrow { font-size: 11px; font-weight: 600; letter-spacing: .2em; text-transform: uppercase; color: rgba(169,182,255,.72); }
.th-hud-num { font-size: 12px; font-weight: 700; letter-spacing: .1em; color: #8fe9ff; font-variant-numeric: tabular-nums; }

.th-note { border-radius: var(--th-r-md); padding: var(--th-s4); border: 1px solid var(--th-line); background: #F8F9FD; }
.th-note-good { background: var(--th-good-bg); border-color: var(--th-good-line); }
.th-note-warn { background: var(--th-warn-bg); border-color: var(--th-warn-line); }
.th-note-bad  { background: var(--th-bad-bg);  border-color: var(--th-bad-line);  }

/* --------------------------------------------------------------- 6. forms */

.th-field { margin-bottom: var(--th-s4); }
.th-label { display: block; font-size: var(--th-t-small); font-weight: 600; color: var(--th-ink); margin-bottom: var(--th-s2); }
.th-hint  { font-size: var(--th-t-micro); color: var(--th-faint); margin-top: var(--th-s1); }

.th-input, .th-select, .th-textarea {
  width: 100%; min-height: var(--th-tap);
  padding: var(--th-s3);
  background: var(--th-surface); color: var(--th-ink);
  border: 1px solid var(--th-line); border-radius: var(--th-r-sm);
  /* 16px stops iOS Safari zooming in when the field is focused. */
  font: inherit; font-size: 16px;
}
.th-input:focus-visible, .th-select:focus-visible, .th-textarea:focus-visible { border-color: var(--th-blue); }
.th-input[aria-invalid="true"] { border-color: var(--th-bad); }
.th-error { font-size: var(--th-t-small); color: var(--th-bad); margin-top: var(--th-s1); }

/* Chip-style radio group. The label wraps the input, so the whole chip is
   clickable and arrow keys move between options for free. */
.th-chips { display: flex; flex-wrap: wrap; gap: var(--th-s2); }
.th-chip { position: relative; }
.th-chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.th-chip span {
  display: flex; align-items: center; min-height: var(--th-tap);
  padding: var(--th-s2) var(--th-s4);
  background: #F3F5FB; border: 1px solid var(--th-line); color: #3A4468;
  border-radius: var(--th-r-pill); font-size: var(--th-t-body); font-weight: 500;
  cursor: pointer;
  transition: background var(--th-fast), border-color var(--th-fast), color var(--th-fast);
}
.th-chip input:checked + span { background: var(--th-blue); border-color: var(--th-blue); color: #fff; }
.th-chip input:focus-visible + span { box-shadow: var(--th-focus-ring); }

/* --------------------------------------------------------------- 7. dialog */

/* Use <dialog> where possible: the browser gives you the focus trap,
   Esc to close, and inertness of the page behind, all for free. */
.th-dialog {
  border: 0; border-radius: var(--th-r-lg); padding: 0;
  max-width: 480px; width: calc(100% - var(--th-s6));
  box-shadow: 0 24px 64px rgba(11,13,23,.28);
}
.th-dialog::backdrop { background: rgba(11,13,23,.55); }
.th-dialog-body { padding: var(--th-s5); }
.th-dialog-close {
  position: absolute; top: var(--th-s3); right: var(--th-s3);
  width: var(--th-tap); height: var(--th-tap);
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: 0; border-radius: 50%;
  font-size: 20px; color: var(--th-muted); cursor: pointer;
}
.th-dialog-close:hover { background: var(--th-page); }

/* ------------------------------------------------------- 8. dark sections */

.th-dark {
  background: var(--th-navy);
  color: var(--th-on-dark);
}
.th-dark h1, .th-dark h2, .th-dark h3 { color: var(--th-on-dark); }
.th-dark p, .th-dark li { color: var(--th-on-dark-dim); }
.th-dark a { color: #A9B6FF; }

/* Text sitting on a photo needs its own backdrop, otherwise contrast is
   whatever the photo happens to be that day. */
.th-on-image { position: relative; }
.th-on-image::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(11,13,23,.25) 0%, rgba(11,13,23,.72) 100%);
}
.th-on-image > * { position: relative; }

/* --------------------------------------------------------- 9. feedback */

.th-spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--th-line); border-top-color: var(--th-blue);
  animation: th-spin .7s linear infinite;
}
@keyframes th-spin { to { transform: rotate(360deg); } }

/* Skeleton, so a slow API reads as loading rather than broken. */
.th-skeleton {
  background: linear-gradient(90deg, #EEF1F8 25%, #F7F9FD 37%, #EEF1F8 63%);
  background-size: 400% 100%;
  animation: th-shimmer 1.4s ease infinite;
  border-radius: var(--th-r-sm); color: transparent;
}
@keyframes th-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* Every list that can be empty needs one of these. An empty screen with no
   explanation is the most common way a working feature looks broken. */
.th-empty { text-align: center; padding: var(--th-s7) var(--th-s5); color: var(--th-muted); }
.th-empty h3 { color: var(--th-ink); }

/* ------------------------------------------------ 10. motion + preferences */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

@media (prefers-contrast: more) {
  :root { --th-muted: #2B3557; --th-faint: #4A5578; --th-line: #C9CFE4; }
}

/* --------------------------------------------------------- 11. app shell */

/* Capacitor builds run edge to edge. These keep content clear of the notch
   and the home indicator without hardcoding device sizes. */
.th-app-top    { padding-top: max(var(--th-s4), env(safe-area-inset-top)); }
.th-app-bottom { padding-bottom: max(var(--th-s4), env(safe-area-inset-bottom)); }

/* In the native app there is no hover, so hover-only affordances are traps.
   Anything that must work on touch gets a visible resting state. */
@media (hover: none) {
  .th-btn:hover { text-decoration: none; }
}

/* --------------------------------------------------------------- 12. print */

@media print {
  .th-skip, .th-dialog, th-nav, th-footer { display: none !important; }
  body { background: #fff; color: #000; }
}
