/* 旅途繪本｜和紙、墨線與柔和大地色 */
:root {
  color-scheme: light;
  --bg: #FFFCF6;
  --card: #FFFEFA;
  --soft: #F5F0E7;
  --ink: #3E3A39;
  --muted: #625B54;
  --line: #3E3A39;
  --quiet-line: #D7CFC2;
  --pink: #F2A497;
  --yellow: #F6D27A;
  --blue: #A8D3E6;
  --green: #B9DAA5;
  --shadow: #3E3A391A;
  --focus: #235E89;
  --on-accent: #302D29;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #292923;
  --card: #494336;
  --soft: #38372F;
  --ink: #F7F1E7;
  --muted: #E0D5C6;
  --line: #8D806D;
  --quiet-line: #6E6557;
  --pink: #D6A094;
  --yellow: #E1BE78;
  --blue: #A5BCB4;
  --green: #B1BE91;
  --shadow: #19191366;
  --focus: #F4D487;
  --on-accent: #292923;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Huninn, ui-rounded, "Noto Sans TC", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: not-allowed; }
a { color: inherit; }
a, button, input, select, textarea { min-width: 0; }
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { overflow-wrap: anywhere; }
h1 { font-size: clamp(2.15rem, 7vw, 4.15rem); line-height: 1.16; letter-spacing: -.025em; }
h2 { font-size: clamp(1.6rem, 4.5vw, 2.3rem); line-height: 1.3; letter-spacing: -.015em; }
h3 { font-size: 1.2rem; line-height: 1.4; }
small, .subtle, .muted { color: var(--muted); }
.wrap { width: min(calc(100% - 36px), 1100px); margin-inline: auto; }

/* 固定選單：手機只捲動選單，不撐寬整頁。 */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top);
  background: var(--bg);
  border-bottom: 2px solid var(--line);
}
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 70px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.08rem; font-weight: 900; letter-spacing: .04em; white-space: nowrap; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 35px;
  height: 35px;
  flex: none;
  border: 2px solid var(--line);
  border-radius: 11px;
  background: var(--yellow);
  color: var(--on-accent);
  transform: rotate(-5deg);
}
.theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 7px 13px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font-weight: 800;
  white-space: nowrap;
}
.theme-btn svg { width: 19px; height: 19px; }
.nav-scroll { overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scrollbar-width: none; }
.nav-scroll::-webkit-scrollbar { display: none; }
.tabs { display: flex; width: max-content; gap: 5px; padding-bottom: 8px; }
.tabs button {
  min-height: 44px;
  padding: 8px 15px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}
.tabs button[aria-selected="true"] { border-color: var(--line); background: var(--yellow); color: var(--on-accent); }

main { min-height: 70vh; padding-block: clamp(24px, 4vw, 42px) 65px; }
section.page[hidden] { display: none !important; }
.page { animation: page-in .2s ease-out; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 15px; margin-bottom: 24px; }
.page-head h2 { margin: 0; }
.eyebrow { margin-bottom: 6px; color: var(--muted); font-size: .73rem; font-weight: 900; letter-spacing: .18em; }

/* 平塗卡片與輕微手繪感，保留清楚的閱讀層級。 */
.card {
  min-width: 0;
  padding: clamp(18px, 3.5vw, 28px);
  border: 2px solid var(--line);
  border-radius: 24px;
  background: var(--card);
  box-shadow: 4px 5px 0 var(--shadow);
  transition: transform .14s ease, box-shadow .14s ease;
}
.card:active { transform: translateY(2px); box-shadow: 2px 3px 0 var(--shadow); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 18px; }
.stack { display: grid; gap: 18px; }
.pill, .tag {
  display: inline-block;
  max-width: 100%;
  padding: 4px 11px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--yellow);
  color: var(--on-accent);
  font-size: .78rem;
  font-weight: 900;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.tag.blue { background: var(--blue); }
.tag.green { background: var(--green); }
.tag.pink { background: var(--pink); }
.tag.neutral { background: var(--soft); color: var(--ink); }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 9px 16px;
  border: 2px solid var(--line);
  border-radius: 13px;
  background: var(--yellow);
  color: var(--on-accent);
  font-weight: 900;
  line-height: 1.3;
  text-align: center;
  text-decoration: none;
  overflow-wrap: anywhere;
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn:active { transform: translateY(2px) scale(.98); }
.btn.secondary { background: var(--card); color: var(--ink); }
.btn.soft { background: var(--green); }
.btn.danger { background: var(--pink); }
.btn.small { min-height: 42px; padding: 8px 12px; font-size: .9rem; }
.actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 17px; }
.actions.full { grid-column: 1 / -1; }
.btn.full { grid-column: 1 / -1; }
.empty {
  padding: 42px 20px;
  border: 2px dashed var(--quiet-line);
  border-radius: 23px;
  background: var(--soft);
  text-align: center;
}
.empty p { margin-bottom: 14px; }
.empty .emoji { margin-bottom: 7px; font-size: 2.1rem; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 185px), 1fr)); gap: 10px; }
.info { min-width: 0; padding: 12px 14px; border: 1px solid var(--quiet-line); border-radius: 14px; background: var(--soft); }
.info b { display: block; margin-bottom: 3px; color: var(--muted); font-size: .78rem; letter-spacing: .035em; }
.info span { overflow-wrap: anywhere; white-space: pre-line; }
.break { overflow-wrap: anywhere; white-space: pre-line; }
.section-title { margin: 30px 0 13px; font-size: 1.12rem; }
.notice { padding: 12px 15px; border-left: 4px solid var(--pink); border-radius: 0 12px 12px 0; background: var(--soft); }

.hero { display: grid; grid-template-columns: 1fr; max-width: 1020px; margin: auto; overflow: hidden; padding: 0; }
.hero-copy { padding: clamp(26px, 5vw, 52px); }
.hero h1 { margin: 14px 0 18px; }
.hero .lead { font-size: 1.12rem; }
.hero-meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 23px 0; }
.hero-art { display: flex; align-items: end; min-height: 270px; border-top: 2px solid var(--line); background: var(--blue); }
.hero-art svg { display: block; width: 100%; height: auto; }
.countdown {
  display: inline-block;
  max-width: 100%;
  margin-top: 10px;
  padding: 12px 17px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--green);
  color: var(--on-accent);
  font-size: 1.04rem;
  font-weight: 900;
}
.home-note { max-width: 1020px; margin: 18px auto 0; }
:root[data-theme="dark"] .hero-art svg { filter: brightness(.9) saturate(.88); }
.cloud-a { animation: drift 6s ease-in-out infinite alternate; }
.cloud-b { animation: drift 8s ease-in-out infinite alternate-reverse; }
.train { transform-origin: 50% 80%; animation: rock 4.5s ease-in-out infinite; }

.day-tabs, .category-tabs { display: flex; gap: 8px; overflow-x: auto; padding: 3px 2px 12px; scrollbar-width: thin; overscroll-behavior-x: contain; }
.day-tabs button, .category-tabs button {
  flex: none;
  min-height: 46px;
  padding: 8px 15px;
  border: 2px solid var(--line);
  border-radius: 13px;
  background: var(--card);
  color: var(--ink);
  font-weight: 900;
  white-space: nowrap;
}
.day-tabs button[aria-selected="true"], .category-tabs button[aria-selected="true"] { background: var(--pink); color: var(--on-accent); }
.timeline { display: grid; gap: 18px; margin: 12px 0 0 15px; padding-left: 23px; border-left: 2px solid var(--quiet-line); }
.timeline-card { position: relative; animation: day-pop .25s ease-out; }
.timeline-card::before { position: absolute; top: 29px; left: -34px; width: 17px; height: 17px; border: 2px solid var(--line); border-radius: 50%; background: var(--yellow); content: ""; }
.time { margin-bottom: 9px; font-size: clamp(1.7rem, 5vw, 2rem); font-weight: 1000; line-height: 1.15; letter-spacing: .025em; font-variant-numeric: tabular-nums; }
.meta-line { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin: 10px 0; }
.timeline-card p { margin: 8px 0; }
.route { display: flex; align-items: center; gap: 12px; margin: 15px 0; }
.route .arrow { color: var(--muted); font-size: 1.4rem; }
.route .place { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.route .place strong { display: block; font-size: 1.2rem; }
.route .place small { display: block; }
.flight-mark { display: inline-grid; place-items: center; width: 50px; height: 50px; flex: none; border: 2px solid var(--line); border-radius: 14px; background: var(--blue); color: var(--on-accent); font-size: 1.65rem; }

.expense-layout { display: grid; gap: 22px; }
.form-card { background: var(--soft); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.field { min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { display: block; margin-bottom: 5px; font-size: .88rem; font-weight: 900; }
.field input, .field select, .field textarea {
  width: 100%;
  max-width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font-size: 16px;
}
.field textarea { min-height: 94px; resize: vertical; }
.field input[type="file"] { padding: 8px; }
.share-mode-tabs { margin-bottom: 17px; }
.share-code-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; }
.share-code-row input { background: var(--soft); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9rem; }
.share-code-row .btn { white-space: nowrap; }
#share-preview { display: block; margin-top: 7px; overflow-wrap: anywhere; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr)); gap: 11px; }
.stat { padding: 15px; border: 1.5px solid var(--line); border-radius: 15px; background: var(--card); }
.stat b { display: block; font-size: 1.35rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat small { display: block; }
.expense-row { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 14px 0; border-bottom: 1px dashed var(--quiet-line); }
.expense-row:last-child { border-bottom: 0; }
.expense-row > div, .expense-row strong, .expense-row .amount { min-width: 0; overflow-wrap: anywhere; }
.expense-row .amount { font-size: 1.1rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.mini-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.mini-actions button { min-height: 38px; padding: 5px 11px; border: 1px solid var(--quiet-line); border-radius: 9px; background: var(--soft); color: var(--ink); }
.summary-row { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--quiet-line); overflow-wrap: anywhere; }
.summary-row:last-child { border-bottom: 0; }
.summary-row b { text-align: right; }

.todo-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 290px), 1fr)); gap: 15px; }
.todo-item { display: flex; align-items: flex-start; gap: 10px; padding: 11px 0; border-bottom: 1px dashed var(--quiet-line); }
.todo-item:last-child { border-bottom: 0; }
.todo-item input { width: 24px; height: 24px; flex: none; margin: 2px 0; accent-color: #607E54; }
.todo-item span { flex: 1; overflow-wrap: anywhere; }
.todo-item.done span { color: var(--muted); text-decoration: line-through; }
.todo-item button { min-width: 38px; min-height: 38px; border: 0; background: transparent; color: var(--ink); font-size: 1.1rem; }

dialog {
  width: min(640px, calc(100vw - 28px));
  max-width: calc(100vw - 28px);
  max-height: min(88dvh, 780px);
  margin: auto;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 22px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 7px 9px 0 var(--shadow);
  animation: modal-in .18s ease-out;
}
dialog::backdrop { background: #201F1BBA; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 22px 11px; }
.modal-head h2 { margin: 0; font-size: 1.45rem; }
.modal-body { max-height: calc(88dvh - 80px); padding: 3px 22px 25px; overflow-y: auto; overscroll-behavior: contain; }
.modal-close { width: 42px; height: 42px; flex: none; border: 2px solid var(--line); border-radius: 11px; background: var(--soft); color: var(--ink); font-size: 1.1rem; }
.detail-row { padding: 11px 0; border-bottom: 1px dashed var(--quiet-line); overflow-wrap: anywhere; }
.detail-row b { display: block; color: var(--muted); font-size: .8rem; }
.detail-row:last-child { border-bottom: 0; }
.toast {
  position: fixed;
  z-index: 50;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 11px 15px;
  transform: translateX(-50%);
  border: 2px solid var(--line);
  border-radius: 13px;
  background: var(--green);
  color: var(--on-accent);
  box-shadow: 4px 4px 0 var(--shadow);
  font-weight: 900;
  overflow-wrap: anywhere;
}
.toast[hidden] { display: none; }
.foot { padding: 22px 0 32px; border-top: 1px solid var(--quiet-line); color: var(--muted); font-size: .88rem; }

/* 唯讀分享頁不顯示編輯操作。 */
.shared [data-add], .shared [data-edit], .shared [data-delete],
.shared [data-expense-edit], .shared [data-expense-delete], .shared [data-todo-delete],
.shared [data-page="expenses"], .shared [data-page="todos"],
.shared #expense-form, .shared #todo-form { display: none !important; }

@media (hover: hover) {
  .btn:not(:disabled):hover, .theme-btn:hover, .day-tabs button:hover,
  .category-tabs button:hover { box-shadow: 3px 3px 0 var(--shadow); transform: translateY(-1px); }
  .tabs button:not([aria-selected="true"]):hover { background: var(--soft); color: var(--ink); }
}
@media (min-width: 760px) {
  .hero { grid-template-columns: 1.05fr .95fr; }
  .hero-art { min-height: 465px; border-top: 0; border-left: 2px solid var(--line); }
  .expense-layout { grid-template-columns: minmax(300px, .9fr) minmax(0, 1.1fr); align-items: start; }
  .form-card { position: sticky; top: 145px; }
}
@media (max-width: 520px) {
  .wrap { width: calc(100% - 28px); }
  .header-row { min-height: 62px; }
  .brand { font-size: 1rem; }
  .page-head { align-items: flex-start; flex-direction: column; }
  .page-head .btn { align-self: flex-start; }
  .form-grid { grid-template-columns: 1fr; }
  .share-code-row { grid-template-columns: 1fr; }
  .share-code-row .btn { justify-self: start; }
  .card { border-radius: 20px; }
  .route { gap: 7px; }
  .route .place strong { font-size: 1rem; }
  .modal-head, .modal-body { padding-right: 16px; padding-left: 16px; }
}
@media (max-width: 360px) {
  .theme-btn { padding-inline: 9px; }
  .theme-btn span { font-size: .84rem; }
  .timeline { margin-left: 8px; padding-left: 18px; }
  .timeline-card::before { left: -29px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
@keyframes drift { to { transform: translateX(12px); } }
@keyframes rock { 50% { transform: rotate(1deg) translateY(-2px); } }
@keyframes page-in { from { opacity: .65; transform: translateY(5px); } to { opacity: 1; transform: none; } }
@keyframes modal-in { from { opacity: .5; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes day-pop { from { opacity: .6; transform: scale(.99); } to { opacity: 1; transform: scale(1); } }
