:root {
  color-scheme: light;
  --ink: #102a43;
  --ink-soft: #334e68;
  --paper: #f7f1e6;
  --paper-deep: #eee3d2;
  --card: #fffdf8;
  --red: #d4573d;
  --red-dark: #ac3f2b;
  --gold: #c7973c;
  --green: #3d755b;
  --line: rgba(16, 42, 67, 0.13);
  --shadow: 0 18px 45px rgba(16, 42, 67, 0.09);
  --radius: 22px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Noto Sans TC", "Noto Sans JP", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body { margin: 0; min-width: 320px; background: var(--paper); color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
[hidden] { display: none !important; }

.auth-screen { min-height: 100dvh; display: grid; align-content: end; background: var(--ink); position: relative; overflow: hidden; }
.auth-art { position: absolute; inset: 0 0 42%; overflow: hidden; background: linear-gradient(180deg, #102a43 0%, #244b66 100%); }
.sun { position: absolute; width: 110px; height: 110px; border-radius: 50%; background: var(--red); top: 13%; right: 16%; box-shadow: 0 0 0 14px rgba(212,87,61,.09); }
.mountain { position: absolute; width: 85%; height: 85%; left: 8%; bottom: -40%; background: #d7d3c6; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.mountain::after { content: ""; position: absolute; width: 35%; height: 35%; left: 33%; top: 0; background: #f8f4e9; clip-path: polygon(50% 0, 100% 100%, 65% 76%, 48% 94%, 30% 75%, 0 100%); }
.mountain-back { transform: translate(-25%, 18%) scale(.72); opacity: .28; }
.mountain-front { transform: translate(12%, 10%); }
.auth-card { position: relative; background: var(--paper); border-radius: 34px 34px 0 0; padding: 30px 24px max(28px, env(safe-area-inset-bottom)); box-shadow: 0 -20px 60px rgba(0,0,0,.18); }
.auth-card h1, .topbar h1 { font-family: Georgia, "Noto Serif TC", serif; letter-spacing: .12em; margin: 0; }
.auth-card h1 { font-size: 48px; }
.eyebrow { margin: 0 0 7px; color: var(--red); font-size: 11px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }
.muted { color: var(--ink-soft); line-height: 1.65; }
.stack { display: grid; gap: 14px; margin-top: 18px; }
.register-form { padding: 18px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); }
.auth-help { margin-top: 18px; font-size: 13px; color: var(--ink-soft); }
.auth-help p { line-height: 1.6; }

.app-shell { min-height: 100dvh; max-width: 760px; margin: 0 auto; background: var(--paper); }
.topbar { position: sticky; z-index: 500; top: 0; display: flex; align-items: center; justify-content: space-between; padding: max(16px, env(safe-area-inset-top)) 20px 14px; background: rgba(247,241,230,.92); backdrop-filter: blur(18px); border-bottom: 1px solid rgba(16,42,67,.06); }
.topbar h1 { font-size: 30px; }
.top-actions { display: flex; align-items: center; gap: 9px; }
.network-pill { font-size: 11px; font-weight: 750; padding: 6px 9px; border-radius: 99px; color: var(--green); background: rgba(61,117,91,.1); }
.network-pill.offline { color: var(--red-dark); background: rgba(212,87,61,.12); }
.avatar-button { border: 0; width: 42px; height: 42px; border-radius: 50%; color: #fff; background: var(--ink); font-weight: 800; }
main { padding: 14px 18px calc(104px + env(safe-area-inset-bottom)); }
.view { display: none; animation: view-in .22s ease-out; }
.view.active { display: block; }
@keyframes view-in { from { opacity: 0; transform: translateY(5px); } }
.section-heading, .subheading-row, .modal-header { display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.section-heading { margin: 12px 1px 17px; }
.section-heading h2, .modal-header h2 { margin: 0; font-family: Georgia, "Noto Serif TC", serif; font-size: 27px; }
.subheading-row { margin: 22px 1px 10px; }
.subheading-row h3 { margin: 0; font-size: 18px; }
.round-action { border: 0; border-radius: 50%; width: 44px; height: 44px; color: #fff; background: var(--red); font-size: 26px; box-shadow: 0 10px 24px rgba(212,87,61,.3); }

.date-tabs, .filter-chips { display: flex; gap: 9px; overflow-x: auto; scrollbar-width: none; padding: 2px 1px 8px; scroll-snap-type: x proximity; }
.date-tabs::-webkit-scrollbar, .filter-chips::-webkit-scrollbar { display: none; }
.date-tab { flex: 0 0 auto; min-width: 58px; border: 1px solid var(--line); background: rgba(255,253,248,.72); padding: 9px 10px; border-radius: 16px; display: grid; gap: 2px; text-align: center; scroll-snap-align: start; }
.date-tab small { font-size: 10px; color: var(--ink-soft); }
.date-tab strong { font-size: 17px; }
.date-tab.active { color: #fff; background: var(--ink); border-color: var(--ink); box-shadow: 0 8px 20px rgba(16,42,67,.2); }
.date-tab.active small { color: rgba(255,255,255,.7); }
.day-summary { margin: 9px 0 20px; padding: 18px 20px; color: #fff; border-radius: var(--radius); background: linear-gradient(135deg, var(--ink), #274f6d); box-shadow: var(--shadow); }
.day-summary h3 { margin: 0 0 5px; font-family: Georgia, "Noto Serif TC", serif; font-size: 22px; }
.day-summary p { margin: 0; color: rgba(255,255,255,.72); font-size: 13px; }

.timeline { position: relative; padding-left: 25px; }
.timeline::before { content: ""; position: absolute; left: 8px; top: 6px; bottom: 12px; width: 1px; background: rgba(16,42,67,.18); }
.timeline-item { position: relative; margin: 0 0 14px; padding: 17px; border-radius: 19px; background: var(--card); box-shadow: 0 8px 28px rgba(16,42,67,.06); border: 1px solid rgba(16,42,67,.06); }
.timeline-item::before { content: ""; position: absolute; width: 11px; height: 11px; left: -23px; top: 23px; border-radius: 50%; background: var(--red); border: 3px solid var(--paper); box-shadow: 0 0 0 1px rgba(212,87,61,.25); }
.timeline-top { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; }
.timeline-time { color: var(--red); font-size: 12px; font-weight: 800; letter-spacing: .03em; }
.timeline-item h3 { margin: 4px 0 4px; font-size: 17px; line-height: 1.35; }
.timeline-item p { margin: 0; line-height: 1.55; font-size: 13px; color: var(--ink-soft); }
.timeline-meta { display: grid; gap: 7px; margin-top: 12px; padding-top: 11px; border-top: 1px solid var(--line); }
.status-select { width: auto; max-width: 108px; border: 0; border-radius: 99px; padding: 6px 25px 6px 10px; font-size: 11px; font-weight: 800; background-color: var(--paper-deep); }
.status-select[data-status="已預約"], .status-select[data-status="已完成"] { color: var(--green); background-color: rgba(61,117,91,.11); }
.status-select[data-status="待確認"], .status-select[data-status="待預約"] { color: #956611; background-color: rgba(199,151,60,.13); }
.card-actions { display: flex; gap: 10px; margin-top: 11px; }
.text-button { border: 0; background: transparent; padding: 5px; color: var(--red-dark); font-size: 13px; font-weight: 750; }

.map-controls, .food-toolbar { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; }
.map-controls .compact-field { flex: 1; }
.map-canvas { height: min(60vh, 520px); border-radius: 24px; overflow: hidden; border: 1px solid var(--line); box-shadow: var(--shadow); background: #d8e3df; }
.map-credit { margin: 8px 4px 16px; font-size: 10px; color: var(--ink-soft); }
.compact-list { display: grid; gap: 8px; }
.compact-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: 14px; background: var(--card); font-size: 13px; }
.compact-row span { color: var(--ink-soft); }

select, input, textarea { width: 100%; border: 1px solid var(--line); border-radius: 13px; background: var(--card); padding: 12px 13px; outline: none; }
select:focus, input:focus, textarea:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(212,87,61,.11); }
label { display: grid; gap: 7px; color: var(--ink-soft); font-size: 13px; font-weight: 650; }
.compact-field select { padding: 9px 12px; }
.button { border: 1px solid transparent; border-radius: 14px; padding: 12px 15px; font-weight: 800; cursor: pointer; }
.button.primary { color: #fff; background: var(--red); box-shadow: 0 9px 24px rgba(212,87,61,.22); }
.button.secondary { color: var(--ink); background: var(--card); border-color: var(--line); }
.button.ghost { background: transparent; border-color: var(--line); }
.button.danger { color: var(--red-dark); }
.wide { width: 100%; margin-top: 10px; }
.filter-chips button { flex: 0 0 auto; border: 1px solid var(--line); border-radius: 99px; padding: 9px 13px; background: var(--card); font-size: 12px; font-weight: 750; }
.filter-chips button.active { color: #fff; border-color: var(--red); background: var(--red); }
.filter-chips.subtle button.active { color: var(--ink); border-color: var(--gold); background: rgba(199,151,60,.18); }
.food-toolbar select { flex: 1; }
.food-toolbar .button { flex: 0 0 auto; }
.helper-text, .form-message { min-height: 18px; margin: 6px 2px; font-size: 12px; color: var(--ink-soft); }
.food-featured, .food-list { display: grid; gap: 13px; }
.food-card { position: relative; overflow: hidden; padding: 18px; border: 1px solid rgba(16,42,67,.07); border-radius: var(--radius); background: var(--card); box-shadow: 0 9px 30px rgba(16,42,67,.07); }
.food-card.featured:first-child { background: linear-gradient(145deg, #153651, #102a43); color: #fff; }
.food-card.featured:first-child .muted, .food-card.featured:first-child .food-details { color: rgba(255,255,255,.72); }
.food-photo { position: relative; margin: -18px -18px 15px; overflow: hidden; background: #d9e1e5; }
.food-photo img { display: block; width: 100%; aspect-ratio: 3 / 2; object-fit: cover; }
.food-photo figcaption { position: absolute; right: 10px; bottom: 9px; left: 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.photo-label, .photo-source { border-radius: 99px; padding: 6px 9px; color: #fff; background: rgba(8,25,40,.78); backdrop-filter: blur(8px); font-size: 10px; font-weight: 800; line-height: 1; text-decoration: none; }
.food-photo.traveler .photo-label { background: rgba(61,117,91,.9); }
.food-photo.official_menu .photo-label { background: rgba(16,42,67,.88); }
.food-photo.illustration .photo-label { background: rgba(152,66,47,.92); }
.photo-source:hover, .photo-source:focus-visible { background: rgba(8,25,40,.96); text-decoration: underline; }
.badge-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 9px; }
.badge { display: inline-flex; align-items: center; border-radius: 99px; padding: 5px 8px; font-size: 10px; font-weight: 800; color: var(--ink-soft); background: var(--paper-deep); }
.badge.must { color: #fff; background: var(--red); }
.badge.distance { color: var(--green); background: rgba(61,117,91,.12); }
.food-card h3 { margin: 0 0 4px; font-size: 18px; }
.food-card .local-name { font-size: 11px; color: var(--ink-soft); }
.food-card .signature { margin: 12px 0; line-height: 1.55; font-weight: 650; }
.food-details { display: grid; gap: 6px; color: var(--ink-soft); font-size: 12px; line-height: 1.5; }
.food-actions, .vote-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 13px; }
.small-action { border: 1px solid var(--line); border-radius: 11px; padding: 8px 10px; background: transparent; font-size: 12px; font-weight: 750; text-decoration: none; }
.small-action.selected.yes { color: #fff; background: var(--green); border-color: var(--green); }
.small-action.selected.no { color: #fff; background: var(--red-dark); border-color: var(--red-dark); }
.vote-summary { margin-top: 8px; font-size: 11px; color: var(--ink-soft); }
.all-results { margin-top: 16px; }
.all-results summary { cursor: pointer; margin-bottom: 12px; color: var(--ink-soft); font-size: 13px; font-weight: 750; }

.notice { display: grid; gap: 4px; padding: 15px 17px; border-radius: 17px; background: rgba(199,151,60,.13); border: 1px solid rgba(199,151,60,.23); }
.notice span { font-size: 12px; color: var(--ink-soft); }
.debt-summary { display: grid; grid-template-columns: repeat(2, 1fr); gap: 11px; margin: 15px 0; }
.currency-card { padding: 16px; border-radius: 19px; color: #fff; background: var(--ink); }
.currency-card:nth-child(2) { background: var(--red-dark); }
.currency-card small { color: rgba(255,255,255,.7); }
.currency-card strong { display: block; margin-top: 5px; font-size: 22px; }
.transfer-list, .expense-list { display: grid; gap: 10px; }
.transfer-card, .expense-row { padding: 14px 15px; border-radius: 17px; background: var(--card); border: 1px solid rgba(16,42,67,.06); }
.transfer-card { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.transfer-route { font-weight: 800; }
.transfer-route span { color: var(--red); margin: 0 5px; }
.transfer-amount { white-space: nowrap; font-weight: 850; }
.expense-row-top { display: flex; justify-content: space-between; gap: 10px; }
.expense-row h4 { margin: 0; }
.expense-amount { font-weight: 850; }
.expense-meta { margin-top: 5px; font-size: 11px; color: var(--ink-soft); line-height: 1.5; }
.queued-count { font-size: 11px; color: var(--red-dark); }

.member-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.member-card { display: grid; justify-items: center; gap: 7px; padding: 15px 6px; border-radius: 18px; background: var(--card); border: 1px solid rgba(16,42,67,.06); text-align: center; }
.member-avatar { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; color: #fff; background: var(--ink); font-weight: 850; }
.member-card:nth-child(2) .member-avatar { background: var(--red); }
.member-card:nth-child(3) .member-avatar { background: var(--green); }
.member-card small { color: var(--ink-soft); font-size: 10px; }
.settings-card { margin-top: 14px; padding: 18px; border-radius: var(--radius); background: var(--card); border: 1px solid rgba(16,42,67,.06); }
.settings-card h3 { margin: 0 0 7px; }
.inline-form { display: flex; gap: 8px; align-items: end; }
.inline-form select { flex: 1; }
.inline-form .button { flex: 0 0 auto; }
.recovery-list, .audit-list { display: grid; gap: 8px; margin-top: 13px; }
.recovery-row, .audit-row { padding: 12px; border-radius: 13px; background: var(--paper); font-size: 12px; line-height: 1.55; }
.audit-row { display: flex; justify-content: space-between; gap: 8px; }

.bottom-nav { position: fixed; z-index: 800; left: 50%; bottom: 0; width: min(760px, 100%); transform: translateX(-50%); display: grid; grid-template-columns: repeat(5, 1fr); padding: 8px 8px max(8px, env(safe-area-inset-bottom)); background: rgba(255,253,248,.94); backdrop-filter: blur(20px); border-top: 1px solid var(--line); box-shadow: 0 -12px 35px rgba(16,42,67,.08); }
.nav-item { border: 0; background: transparent; display: grid; justify-items: center; gap: 2px; padding: 5px 2px; color: #8293a1; }
.nav-item span { display: grid; place-items: center; width: 31px; height: 25px; border-radius: 99px; font-size: 18px; font-weight: 800; }
.nav-item small { font-size: 10px; font-weight: 700; }
.nav-item.active { color: var(--red); }
.nav-item.active span { background: rgba(212,87,61,.11); }

.modal { width: min(620px, calc(100% - 24px)); max-height: calc(100dvh - 30px); border: 0; padding: 0; border-radius: 26px; background: var(--paper); box-shadow: 0 30px 90px rgba(0,0,0,.35); }
.modal::backdrop { background: rgba(8,25,40,.58); backdrop-filter: blur(3px); }
.modal-form { display: grid; gap: 14px; padding: 22px; overflow-y: auto; max-height: calc(100dvh - 30px); }
.icon-button { width: 38px; height: 38px; border: 0; border-radius: 50%; background: var(--paper-deep); font-size: 23px; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
fieldset { border: 1px solid var(--line); border-radius: 15px; padding: 12px; }
legend { padding: 0 6px; color: var(--ink-soft); font-size: 12px; font-weight: 700; }
.participant-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.participant-chip { display: flex; align-items: center; gap: 6px; padding: 8px; border-radius: 11px; background: var(--paper); font-size: 12px; }
.participant-chip input, .switch input { width: auto; }
.switch { display: flex; align-items: center; gap: 8px; }
.custom-shares { display: grid; gap: 8px; }
.custom-share-row { display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: 10px; }
.toast { position: fixed; z-index: 2000; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); max-width: calc(100% - 32px); transform: translate(-50%, 20px); padding: 11px 16px; border-radius: 13px; color: #fff; background: var(--ink); box-shadow: 0 15px 35px rgba(0,0,0,.22); opacity: 0; pointer-events: none; transition: .2s ease; font-size: 13px; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) {
  body { background: #e7dfd2; }
  .app-shell { box-shadow: 0 0 80px rgba(16,42,67,.15); }
  main { padding-left: 30px; padding-right: 30px; }
  .food-featured { grid-template-columns: repeat(3, 1fr); }
  .food-card.featured { min-height: 300px; }
  .food-list { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
