:root {
  --bg: #0c0d0f;
  --surface: #141518;
  --surface-2: #1c1e22;
  --border: rgba(255,255,255,0.06);
  --text-primary: #f0f0f0;
  --text-secondary: #888;
  --text-muted: #555;
  --accent: #e8c97a;
  --accent-dim: rgba(232,201,122,0.10);
  --accent-glow: rgba(232,201,122,0.25);
  --timer: #7ab8e8;
  --timer-dim: rgba(122,184,232,0.08);
  --highlight: #f5e6c0;
  --green: #7ecfa0;
  --green-dim: rgba(100,200,140,0.07);
  --green-border: rgba(100,200,140,0.15);
  --radius: 13px;
}

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

html, body { height: 100%; overflow: hidden; touch-action: none; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  overflow: hidden;
  padding: 0 0.9rem;
}

.bg-grid {
  position: fixed; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.015) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none; z-index: 0;
}

.container {
  position: relative; z-index: 1;
  width: 100%; max-width: 460px;
  height: 100dvh; max-height: 100dvh;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top, 0.5rem) 0 env(safe-area-inset-bottom, 0.5rem);
  overflow: hidden;
}

header {
  text-align: center; flex-shrink: 0;
  padding: clamp(0.4rem,2vh,0.9rem) 0 clamp(0.3rem,1.2vh,0.6rem);
}

.star-icon {
  font-size: 0.75rem; color: var(--accent);
  margin-bottom: clamp(0.1rem,0.5vh,0.25rem);
  display: block; letter-spacing: 6px; opacity: 0.7;
}

h1 {
  font-family: 'DM Serif Display', serif;
  font-size: clamp(1.6rem,5.5vh,2.4rem);
  font-weight: 400; color: var(--text-primary);
  line-height: 1; margin-bottom: clamp(0.1rem,0.4vh,0.25rem);
}

.subtitle {
  font-size: clamp(0.55rem,1.4vh,0.67rem);
  color: var(--text-muted); letter-spacing: 0.11em; text-transform: uppercase;
}

.cards {
  flex: 1; display: flex; flex-direction: column;
  gap: clamp(0.28rem,0.9vh,0.5rem); overflow: hidden;
}

.cards > .card, .cards > .card-row { flex: 1; min-height: 0; }

.card-row {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: clamp(0.28rem,0.9vh,0.5rem); flex: 1; min-height: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(0.45rem,1.4vh,0.85rem) clamp(0.7rem,2.5vw,1rem);
  display: flex; flex-direction: column; justify-content: center; min-height: 0;
}

.card--highlight { background: var(--accent-dim); border-color: rgba(232,201,122,0.18); }
.card--highlight .card-label { color: var(--accent); opacity: 0.85; }
.card--highlight .counter { color: var(--highlight); }

.card--timer { background: var(--timer-dim); border-color: rgba(122,184,232,0.12); }
.card--timer .card-label { color: var(--timer); opacity: 0.85; }
.card--timer .counter { color: #a8d4f5; }

.card--countries {
  background: var(--green-dim); border-color: var(--green-border);
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: border-color 0.2s, background 0.2s;
}
.card--countries:active { background: rgba(100,200,140,0.13); }

.card-label {
  font-size: clamp(0.52rem,1.3vh,0.62rem); font-weight: 500;
  letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: clamp(0.08rem,0.35vh,0.2rem);
  white-space: nowrap; flex-shrink: 0;
}

.counter {
  font-family: 'DM Serif Display', serif;
  font-size: clamp(1.15rem,3.8vh,1.9rem);
  font-weight: 400; color: var(--text-primary); line-height: 1.1; white-space: nowrap;
}
.counter--sm { font-size: clamp(0.9rem,2.8vh,1.35rem); }
.counter--mono {
  font-family: 'DM Sans', monospace;
  font-size: clamp(0.85rem,2.6vh,1.2rem);
  font-weight: 300; letter-spacing: 0.03em; white-space: nowrap;
}
.counter--milestone {
  font-family: 'DM Serif Display', serif;
  font-size: clamp(1.1rem,3.6vh,1.7rem);
  font-weight: 400; color: var(--highlight); line-height: 1.15;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.progress-bar-bg {
  background: var(--surface-2); border-radius: 100px; height: 4px;
  margin: clamp(0.2rem,0.7vh,0.4rem) 0; position: relative; overflow: visible; flex-shrink: 0;
}
.progress-bar-fill {
  height: 100%; border-radius: 100px;
  background: linear-gradient(90deg, var(--accent) 0%, #f5d98a 100%);
  transition: width 0.8s cubic-bezier(0.4,0,0.2,1); position: relative;
}
.progress-bar-fill::after {
  content: ''; position: absolute; right: -1px; top: 50%; transform: translateY(-50%);
  width: 7px; height: 7px; border-radius: 50%; background: #f5e6c0;
  box-shadow: 0 0 5px 2px var(--accent-glow);
}
.progress-label {
  font-size: clamp(0.58rem,1.4vh,0.7rem); color: var(--text-secondary); line-height: 1.35;
}

/* Countries card summary */
.countries-flags {
  font-size: clamp(1.2rem,3.5vh,1.6rem);
  line-height: 1; letter-spacing: 0.1em;
  margin: clamp(0.1rem,0.4vh,0.25rem) 0 clamp(0.06rem,0.25vh,0.15rem);
}
.countries-count {
  font-size: clamp(0.62rem,1.6vh,0.75rem); font-weight: 500; color: var(--text-primary);
}
.flip-hint {
  font-size: clamp(0.5rem,1.2vh,0.58rem); color: var(--green);
  opacity: 0.6; margin-top: clamp(0.06rem,0.25vh,0.12rem); letter-spacing: 0.05em;
}

footer {
  text-align: center; flex-shrink: 0;
  padding: clamp(0.2rem,0.8vh,0.45rem) 0 clamp(0.3rem,1vh,0.5rem);
}
footer p {
  font-size: clamp(0.55rem,1.4vh,0.67rem); color: var(--text-muted); letter-spacing: 0.06em;
}

/* ── Countries Overlay ─────────────────────────────────────────────────── */
.countries-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0);
  pointer-events: none;
  transition: background 0.35s ease;
  overflow: hidden;
  visibility: hidden;
}
.countries-overlay.active {
  background: rgba(0,0,0,0.65);
  pointer-events: all;
  visibility: visible;
}

.overlay-sheet {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: #171a1d;
  border-radius: 22px 22px 0 0;
  border-top: 1px solid rgba(255,255,255,0.08);
  padding: 0 0 env(safe-area-inset-bottom, 1.5rem);
  transform: translateY(110%);
  transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 88dvh;
  display: flex; flex-direction: column;
}
.countries-overlay.active .overlay-sheet {
  transform: translateY(0);
}

.overlay-handle {
  width: 36px; height: 4px; border-radius: 2px;
  background: rgba(255,255,255,0.15);
  margin: 0.75rem auto 0;
  flex-shrink: 0;
}

.overlay-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.9rem 1.4rem 0.2rem;
  flex-shrink: 0;
}

.overlay-title {
  font-family: 'DM Serif Display', serif;
  font-size: 1.5rem; font-weight: 400; color: var(--text-primary);
}

.overlay-close {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-muted); border-radius: 50%;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.overlay-subtitle {
  font-size: 0.75rem; color: var(--text-muted);
  padding: 0 1.4rem 0.9rem; letter-spacing: 0.05em; flex-shrink: 0;
}

.overlay-list {
  overflow-y: auto; overflow-x: hidden;
  padding: 0 1.2rem 1.5rem;
  display: flex; flex-direction: column; gap: 0.85rem;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.overlay-item {
  display: flex; gap: 1rem; align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.85rem 1rem;
}

.overlay-photo {
  width: 72px; height: 72px; border-radius: 10px;
  object-fit: cover; flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.08);
}

.overlay-photo--placeholder {
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem;
}

.overlay-info {
  display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0;
}

.overlay-item-top {
  display: flex; align-items: center; gap: 0.4rem;
}

.overlay-flag { font-size: 1.2rem; line-height: 1; }

.overlay-name {
  font-size: 1rem; font-weight: 600; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.overlay-note {
  font-size: 0.78rem; color: var(--green); font-weight: 500;
}

.overlay-age {
  font-size: 0.72rem; color: var(--text-muted);
}

.overlay-date {
  font-size: 0.7rem;
  color: var(--accent);
  opacity: 0.8;
  letter-spacing: 0.02em;
}

/* ── Book button ────────────────────────────────────────────────── */
.overlay-item { position: relative; padding-right: 3.2rem; }

.capsule-btn {
  position: absolute; top: 50%; right: 0.6rem;
  transform: translateY(-50%);
  background: rgba(232,201,122,0.1);
  border: 1px solid rgba(232,201,122,0.25);
  border-radius: 8px; padding: 0.3rem 0.45rem;
  font-size: 1rem; cursor: pointer; line-height: 1;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s;
}
.capsule-btn:active { background: rgba(232,201,122,0.2); }

/* ── Capsule Overlay Shell ───────────────────────────────────────── */
.capsule-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0);
  pointer-events: none;
  transition: background 0.3s ease;
  overflow: hidden; visibility: hidden;
}
.capsule-overlay.active {
  background: rgba(0,0,0,0.8);
  pointer-events: all; visibility: visible;
}

.capsule-sheet {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: #0f1114;
  border-radius: 24px 24px 0 0;
  border-top: 1px solid rgba(255,255,255,0.07);
  max-height: 93dvh;
  display: flex; flex-direction: column;
  transform: translateY(110%);
  transition: transform 0.45s cubic-bezier(0.32, 0.72, 0, 1);
  padding-bottom: env(safe-area-inset-bottom, 1.5rem);
}
.capsule-overlay.active .capsule-sheet { transform: translateY(0); }

/* Handle + Header */
.capsule-sheet .overlay-handle {
  width: 36px; height: 4px; border-radius: 2px;
  background: rgba(255,255,255,0.12);
  margin: 0.7rem auto 0; flex-shrink: 0;
}

.capsule-sheet .overlay-header {
  display: flex; align-items: flex-start;
  justify-content: space-between;
  padding: 0.85rem 1.3rem 0; flex-shrink: 0;
}

.capsule-sheet .overlay-title {
  font-family: "DM Serif Display", serif;
  font-size: 1.5rem; font-weight: 400;
  color: var(--text-primary); line-height: 1.1;
}

.capsule-sheet .overlay-close {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text-muted); border-radius: 50%;
  width: 28px; height: 28px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; cursor: pointer;
  -webkit-tap-highlight-color: transparent; margin-top: 4px;
}

.capsule-age-line {
  font-size: 0.7rem; color: var(--accent);
  opacity: 0.75; padding: 0.2rem 1.3rem 0;
  letter-spacing: 0.04em; flex-shrink: 0;
}

/* ── Tabs ────────────────────────────────────────────────────────── */
.capsule-body {
  display: flex; flex-direction: column;
  flex: 1; min-height: 0; overflow: hidden;
}

.tc-tabs {
  display: flex; gap: 0; flex-shrink: 0;
  padding: 0.7rem 1.1rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.tc-tab {
  flex: 1; background: none; border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: "DM Sans", sans-serif;
  font-size: 0.68rem; font-weight: 500;
  letter-spacing: 0.06em; text-transform: uppercase;
  padding: 0 0.2rem 0.55rem; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.2s, border-color 0.2s;
  white-space: nowrap;
}
.tc-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Tab Panels ──────────────────────────────────────────────────── */
.tc-tab-panels {
  flex: 1; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem 1.1rem 1.5rem;
}

/* ── Flight Tab ──────────────────────────────────────────────────── */
.tc-flight-group { margin-bottom: 1.1rem; }

.tc-group-label {
  font-size: 0.6rem; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase;
  padding: 0.3rem 0.6rem;
  border-radius: 5px; display: inline-block;
  margin-bottom: 0.55rem;
}
.tc-group-label.outbound { color: var(--green); background: rgba(126,207,160,0.08); border: 1px solid rgba(126,207,160,0.15); }
.tc-group-label.cancelled-label { color: #ff7070; background: rgba(255,100,100,0.07); border: 1px solid rgba(255,100,100,0.15); text-decoration: line-through; }
.tc-group-label.emergency-label { color: var(--accent); background: var(--accent-dim); border: 1px solid rgba(232,201,122,0.2); }

.tc-flight-leg {
  background: #1a1d21;
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  margin-bottom: 0.5rem;
  transition: opacity 0.2s;
}
.tc-flight-leg.cancelled { opacity: 0.45; }

.tc-leg-header {
  display: flex; justify-content: space-between;
  align-items: center; margin-bottom: 0.7rem;
}
.tc-leg-airline { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.tc-leg-num {
  font-size: 0.78rem; font-weight: 700;
  color: var(--text-primary); letter-spacing: 0.05em;
  font-family: "DM Sans", monospace;
}
.tc-leg-airline-name { font-size: 0.65rem; color: var(--text-muted); }
.tc-leg-date { font-size: 0.6rem; color: var(--text-muted); white-space: nowrap; }

.tc-badge {
  font-size: 0.55rem; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
  padding: 0.12rem 0.4rem; border-radius: 4px;
}
.tc-badge.cancelled { background: rgba(255,100,100,0.12); color: #ff7070; border: 1px solid rgba(255,100,100,0.2); }
.tc-badge.reroute { background: var(--accent-dim); color: var(--accent); border: 1px solid rgba(232,201,122,0.25); }

.tc-leg-route {
  display: flex; align-items: center; gap: 0.5rem;
}
.tc-leg-point { flex-shrink: 0; min-width: 38px; }
.tc-leg-point.right { text-align: right; }
.tc-leg-iata {
  font-size: 1.25rem; font-weight: 700; line-height: 1;
  color: var(--text-primary);
  font-family: "DM Serif Display", serif;
}
.tc-leg-city { font-size: 0.55rem; color: var(--text-muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60px; }
.tc-leg-time { font-size: 0.62rem; color: var(--accent); margin-top: 3px; font-weight: 500; }

.tc-leg-middle {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; gap: 3px; min-width: 0;
}
.tc-leg-dur { font-size: 0.58rem; color: var(--text-muted); letter-spacing: 0.03em; }
.tc-leg-line {
  width: 100%; display: flex; align-items: center; gap: 2px;
}
.tc-leg-dot {
  width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0;
  background: var(--text-muted);
}
.tc-leg-dash { flex: 1; height: 1px; background: rgba(255,255,255,0.15); }
.tc-plane-icon {
  width: 13px; height: 13px; color: var(--accent);
  flex-shrink: 0; transform: rotate(0deg);
}
.tc-leg-seat {
  font-size: 0.55rem; color: var(--text-muted);
  letter-spacing: 0.03em;
}
.tc-leg-seat.note { color: var(--accent); opacity: 0.7; }

/* ── Story Tab ───────────────────────────────────────────────────── */
.tc-story-location {
  background: linear-gradient(135deg, rgba(232,201,122,0.07) 0%, rgba(122,184,232,0.04) 100%);
  border: 1px solid rgba(232,201,122,0.12);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
}
.tc-story-city {
  font-family: "DM Serif Display", serif;
  font-size: 1rem; color: var(--text-primary); line-height: 1.2;
  margin-bottom: 0.35rem;
}
.tc-story-weather {
  display: flex; align-items: flex-start; gap: 0.3rem;
  font-size: 0.72rem; color: var(--timer); line-height: 1.4;
}
.tc-weather-icon { flex-shrink: 0; }

.tc-story-section { margin-bottom: 1rem; }

.tc-story-section-label {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.62rem; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 0.6rem;
}
.tc-dot {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
}
.tc-dot.good { background: var(--green); }
.tc-dot.bad  { background: var(--accent); }

.tc-story-items { display: flex; flex-direction: column; gap: 0.5rem; }

.tc-story-item {
  display: flex; gap: 0.7rem; align-items: flex-start;
  background: #1a1d21;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
}
.tc-story-section.good .tc-story-item { border-left: 2px solid rgba(126,207,160,0.35); }
.tc-story-section.bad  .tc-story-item { border-left: 2px solid rgba(232,201,122,0.3); }

.tc-item-num {
  font-size: 0.62rem; font-weight: 700;
  color: var(--text-muted); font-family: "DM Sans", monospace;
  flex-shrink: 0; margin-top: 1px; letter-spacing: 0.03em;
}
.tc-story-section.good .tc-item-num { color: var(--green); opacity: 0.7; }
.tc-story-section.bad  .tc-item-num { color: var(--accent); opacity: 0.6; }

.tc-item-text {
  font-size: 0.78rem; color: var(--text-secondary);
  line-height: 1.55;
}

/* ── Diary Tab ───────────────────────────────────────────────────── */
.tc-diary-entry {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.tc-diary-num {
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--text-muted);
  font-family: 'DM Sans', monospace;
  letter-spacing: 0.05em;
  flex-shrink: 0;
  margin-top: 0.9rem;
  width: 18px;
  text-align: right;
}

.tc-diary-bubble {
  flex: 1;
  background: #1a1d21;
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 16px 16px 16px 4px;
  padding: 0.75rem 0.9rem;
  position: relative;
}

.tc-diary-bubble.milestone {
  background: rgba(232,201,122,0.06);
  border-color: rgba(232,201,122,0.15);
  border-radius: 16px 16px 16px 4px;
}

.tc-diary-bubble.sweet {
  background: rgba(126,207,160,0.05);
  border-color: rgba(126,207,160,0.12);
}

.tc-diary-bubble.funny {
  background: rgba(122,184,232,0.05);
  border-color: rgba(122,184,232,0.12);
}

.tc-diary-bubble.reflection {
  background: rgba(180,150,255,0.05);
  border-color: rgba(180,150,255,0.12);
}

.tc-diary-emoji {
  display: block;
  font-size: 1.2rem;
  line-height: 1;
  margin-bottom: 0.4rem;
}

.tc-diary-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.65;
  margin: 0;
}

.tc-diary-sig {
  text-align: center;
  font-family: 'DM Serif Display', serif;
  font-style: italic;
  font-size: 0.82rem;
  color: var(--accent);
  opacity: 0.6;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255,255,255,0.06);
  letter-spacing: 0.02em;
}
