:root {
  color-scheme: dark;
  --bg: #0e1014;
  --surface: #181b22;
  --surface-2: #232731;
  --line: #2f3440;
  --text: #f4f2ec;
  --muted: #a9acb6;
  --gold: #f6b73c;
  --gold-ink: #231a05;
  --sea: #4fd1c5;
  --coral: #ff9580;
  --green: #74e0a3;
  --radius: 16px;
  --tap: 52px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* Layout */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  background: rgba(14, 16, 20, .94);
  border-bottom: 1px solid var(--line);
}
.top-title { flex: 1; min-width: 0; }
.top-title h1 { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-title p { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
main {
  max-width: 640px; margin: 0 auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 104px);
  display: grid; gap: 16px;
}
main > * { min-width: 0; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: #14171d;
  border-top: 1px solid var(--line);
}
.tab {
  min-height: 64px; padding: 8px 2px 6px;
  display: grid; justify-items: center; align-content: center; gap: 3px;
  background: none; border: 0; color: var(--muted);
  font-size: 12px; font-weight: 600;
}
.tab[aria-current="page"] { color: var(--gold); }
.icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Buttons */
.btn {
  min-height: var(--tap); padding: 10px 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text);
  font-weight: 600; text-decoration: none; text-align: center;
}
.btn:active { filter: brightness(1.25); }
.btn:disabled { opacity: .55; }
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--gold-ink); }
.btn.danger { color: var(--coral); background: none; border-color: #5a3a35; }
.btn.danger.armed { background: var(--coral); color: #2a0d07; border-color: var(--coral); }
.btn.block { width: 100%; }
.btn.small { min-height: 48px; padding: 8px 14px; }
.icon-btn { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 14px; background: none; border: 0; color: var(--muted); }
.icon-btn.spin .icon { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .icon-btn.spin .icon { animation: none; opacity: .5; } }
.claude-link { min-height: 48px; padding: 8px 12px; font-size: 15px; white-space: nowrap; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; }
.card > * { min-width: 0; }
details.card { display: block; }
.section-title { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); }
.small-text { font-size: 15px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack { display: grid; gap: 12px; }
.stack > * { min-width: 0; }
.banner { padding: 10px 14px; border-radius: 12px; background: #2c2412; color: #f7dc9f; font-size: 15px; }

/* Today */
.day-head h2 { font-size: 30px; line-height: 1.15; letter-spacing: -.01em; }
.day-head p { color: var(--muted); }
.count-card { background: linear-gradient(135deg, #2a2110, #1a1c22 70%); border-color: #4c3c17; }
.count-label { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--gold); }
.count-value { font-size: clamp(38px, 12vw, 52px); font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.count-title { font-size: 19px; font-weight: 600; overflow-wrap: anywhere; }
.now-chip { padding: 10px 14px; border-radius: 12px; background: #12302c; color: #a5f0e7; font-size: 15px; overflow-wrap: anywhere; }

/* Events */
.event { display: grid; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.event > * { min-width: 0; }
.event.past { opacity: .62; }
.event-time { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--gold); }
.event-title { font-size: 19px; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.event-detail { font-size: 15px; color: var(--muted); overflow-wrap: anywhere; white-space: pre-line; }
.event-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.event-actions .primary { grid-column: 1 / -1; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.pill.booked { background: #143323; color: var(--green); }
.pill.to_book { background: #3a1f19; color: var(--coral); }
.flight { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 14px; background: #1b2230; border: 1px solid #2d3a52; }
.flight strong { font-variant-numeric: tabular-nums; }
.note { padding: 12px 14px; border-left: 3px solid var(--gold); background: var(--surface-2); border-radius: 0 12px 12px 0; white-space: pre-line; overflow-wrap: anywhere; }
.empty { padding: 20px 14px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 14px; }

/* Trip */
.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat strong { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 14px; color: var(--muted); }
.base { border-left: 4px solid var(--sea); }
.base.bkk { border-left-color: var(--gold); }
.base h3 { font-size: 19px; }
.day { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.day summary {
  list-style: none; cursor: pointer; min-height: 68px; padding: 12px 14px;
  display: grid; grid-template-columns: 6px 1fr auto; gap: 12px; align-items: center;
}
.day summary::-webkit-details-marker { display: none; }
.rail { align-self: stretch; border-radius: 3px; background: var(--sea); }
.rail.bkk { background: var(--gold); }
.rail.move { background: linear-gradient(var(--sea), var(--gold)); }
.day-name { font-weight: 700; }
.day-sub { font-size: 14px; color: var(--muted); }
.day.is-today { border-color: var(--gold); }
.chev { color: var(--muted); transition: transform .15s; }
.day[open] .chev { transform: rotate(90deg); }
.day-body { padding: 0 12px 14px; display: grid; gap: 12px; }
.day-body > * { min-width: 0; }
.day-body .event { background: var(--surface-2); }

/* Money */
.convert-grid { display: grid; gap: 10px; }
.convert-input { display: grid; grid-template-columns: 64px 1fr; align-items: center; background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.convert-input span { text-align: center; font-weight: 700; color: var(--gold); }
.convert-input input { min-width: 0; width: 100%; height: 64px; padding: 0 14px; border: 0; background: none; font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.convert-input input:focus { outline: none; }
.convert-input:focus-within { border-color: var(--gold); }
.owes { font-size: 28px; font-weight: 800; line-height: 1.2; }
.owes .amount { color: var(--gold); font-variant-numeric: tabular-nums; }
.expense-row {
  width: 100%; min-height: 64px; padding: 10px 14px;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; text-align: left;
}
.expense-row b { font-weight: 600; overflow-wrap: anywhere; }
.expense-row .amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.expense-row small { grid-column: 1 / -1; font-size: 14px; color: var(--muted); }

/* Phrases */
.phrase { width: 100%; display: grid; gap: 14px; padding: 22px 18px; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.phrase .thai { font-size: clamp(32px, 9.5vw, 46px); line-height: 1.45; font-weight: 700; }
.phrase .english { color: var(--gold); font-weight: 600; }
.phrase-full {
  position: fixed; inset: 0; z-index: 20; width: 100%; height: 100%;
  padding: calc(env(safe-area-inset-top) + 24px) 24px calc(env(safe-area-inset-bottom) + 24px);
  display: grid; align-content: center; gap: 24px;
  background: #000; border: 0; color: #fff; text-align: center;
}
.phrase-full .thai { font-size: clamp(44px, 13vw, 96px); line-height: 1.4; font-weight: 800; }
.phrase-full .english { font-size: 19px; color: var(--gold); }
.phrase-full .hint { font-size: 15px; color: var(--muted); }

/* Info */
.flight-big { display: grid; gap: 4px; padding: 14px; border-radius: 14px; background: var(--surface-2); }
.flight-big .time { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.warn { color: var(--coral); font-weight: 700; }
.tel { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; padding: 10px 16px; border-radius: 14px; background: #33191a; border: 1px solid #5c2b2c; text-decoration: none; font-weight: 600; }
.tel b { font-size: 26px; color: #ffb4a6; font-variant-numeric: tabular-nums; }

/* Forms */
dialog.sheet {
  width: 100%; max-width: 640px; max-height: 92dvh; margin: auto auto 0; padding: 0;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-bottom: 0; border-radius: 22px 22px 0 0;
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, .65); }
.sheet form { display: grid; gap: 14px; padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px); }
.sheet form > * { min-width: 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet-head h2 { font-size: 21px; overflow-wrap: anywhere; }
.field { display: grid; gap: 6px; font-size: 15px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea, .gate-input {
  width: 100%; min-width: 0; min-height: 52px; padding: 12px 14px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  font-size: 17px; font-weight: 400; /* 16px or more stops iPhones zooming in on focus */
  -webkit-appearance: none; appearance: none;
}
.field input[type="time"], .field input[type="date"] { display: block; }
.field textarea { min-height: 96px; resize: vertical; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.two > * { min-width: 0; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 14px; }
.segmented label { position: relative; }
.segmented input { position: absolute; inset: 0; opacity: 0; margin: 0; }
.segmented span { display: grid; place-items: center; min-height: 48px; border-radius: 11px; font-weight: 600; color: var(--muted); }
.segmented input:checked + span { background: var(--gold); color: var(--gold-ink); }
.segmented input:focus-visible + span { outline: 3px solid var(--gold); outline-offset: 2px; }
.check { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.check input { width: 24px; height: 24px; accent-color: var(--gold); }
.error { padding: 10px 14px; border-radius: 12px; background: #3a1f19; color: #ffc4b8; font-size: 15px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 80px); z-index: 30;
  max-width: 480px; margin: 0 auto; padding: 12px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-weight: 600; text-align: center;
}

/* Passcode screen */
.gate { min-height: 100dvh; padding: 24px 16px; display: grid; align-content: center; justify-items: center; }
.gate form { width: 100%; max-width: 400px; display: grid; gap: 14px; }
.gate img { width: 88px; height: 88px; border-radius: 20px; }
.gate h1 { font-size: 30px; line-height: 1.15; }
