:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1d1d1b;
  --muted: #7a776f;
  --line: #e4e0d6;
  --accent: #c2410c;
  --accent-ink: #fff;
  --chip: #f1ede4;
  --danger: #b91c1c;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1a;
    --card: #242424;
    --ink: #ecebe7;
    --muted: #9b988f;
    --line: #353535;
    --accent: #fb923c;
    --accent-ink: #1a1a1a;
    --chip: #2f2f2f;
    --danger: #f87171;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--font);
  padding-bottom: env(safe-area-inset-bottom);
}
#app { max-width: 720px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
main { padding: 12px 12px 72px; display: flex; flex-direction: column; gap: 12px; }
a { color: inherit; }
h1, h2 { margin: 0; line-height: 1.3; }
h1 { font-size: 18px; }
h2 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; padding: 24px; }
.error { color: var(--danger); }

/* レイアウト */
.row { display: flex; align-items: center; }
.row.gap, .gap { gap: 8px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 0; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }

/* ヘッダー */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
}
.bar .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar h1:only-of-type:not(.title) { flex: 1; }
.tabs { display: flex; gap: 4px; padding: 0 12px; border-bottom: 1px solid var(--line); position: sticky; top: 52px; z-index: 4; background: var(--bg); }
.tabs a { flex: 1; text-align: center; padding: 10px 0; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 600; font-size: 14px; }
.tabs a.active { color: var(--ink); border-color: var(--accent); }

/* 入力 */
button, input, select, textarea { font: inherit; color: inherit; }
button, .ghost {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 9px 14px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 40px;
}
button:disabled { opacity: .5; }
button, .chip { white-space: nowrap; flex-shrink: 0; }
.grow { flex-shrink: 1; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
button.small { min-height: 34px; padding: 5px 10px; font-size: 14px; }
button.block { width: 100%; }
button.icon { min-height: 36px; min-width: 36px; padding: 0; border-color: transparent; background: transparent; }
.ghost { border-color: transparent; background: transparent; font-size: 22px; padding: 4px 10px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label input, label select { color: var(--ink); }
input, select, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px; width: 100%;
  font-size: 16px; /* iOS のズーム防止 */
}
select { width: auto; }
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); flex: none; }
textarea { resize: vertical; }
textarea.memo { font: 14px/1.6 var(--mono); white-space: pre; }

/* 一覧 */
.list { gap: 10px; }
.list h2 { margin-top: 12px; color: var(--muted); font-size: 13px; }
.trip-card { display: flex; flex-direction: column; text-decoration: none; gap: 2px; }
.login { margin: 15vh 16px 0; display: flex; flex-direction: column; gap: 14px; }

/* 行程 */
.day h2 { margin-bottom: 8px; }
.entries, .items, .results, .mini { list-style: none; margin: 0; padding: 0; }
.entry { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); align-items: baseline; }
.entry:last-child { border-bottom: none; }
.entry .time { font: 600 15px var(--mono); width: 3.2em; flex: none; font-variant-numeric: tabular-nums; }
.entry .text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.entry.note .text { color: var(--muted); }
.entry .links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.entry.edit { align-items: center; gap: 6px; }
.entry.edit .time { width: 6.6em; font-family: var(--font); font-weight: 400; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: 13px; line-height: 1.2;
  padding: 5px 9px; border-radius: 999px; background: var(--chip); text-decoration: none; white-space: nowrap;
}
.day > .row { margin-top: 10px; }
.day-foot { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }

/* 宿 */
.hotel h2 a { text-decoration: none; }
.hotel h2 a::after { content: " ↗"; color: var(--muted); font-size: 13px; }
.hotel dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 10px 0 0; }
.hotel dt { color: var(--muted); font-size: 13px; padding-top: 2px; }
.hotel dd { margin: 0; overflow-wrap: anywhere; }
.meta { display: flex; flex-direction: column; gap: 10px; }

/* 候補 */
.list-card h2 { margin-bottom: 6px; }
.item { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); flex-wrap: wrap; }
.item:last-child { border-bottom: none; }
.item .text { flex: 1; min-width: 0; text-decoration: none; }
.item .rating, .result .rating { color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }
.item .note { flex-basis: 100%; padding-left: 32px; font-size: 13px; }
.item.done .text { text-decoration: line-through; color: var(--muted); }
.item.edit { gap: 6px; }
.item.edit .rating { width: 4.5em; flex: none; }
.item.edit .note { padding-left: 0; }
.list-card > .row { margin-top: 10px; }

/* モーダル（スマホは下から出るシート） */
#modal { position: fixed; inset: 0; background: rgb(0 0 0 / .45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
#modal[hidden] { display: none; }
.sheet {
  background: var(--bg); width: 100%; max-width: 720px; max-height: 92dvh; overflow: auto;
  border-radius: 16px 16px 0 0; padding: 14px 14px calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px;
}
@media (min-width: 760px) {
  #modal { align-items: center; }
  .sheet { border-radius: 16px; max-height: 85vh; }
}
.results { display: flex; flex-direction: column; gap: 8px; }
.result { width: 100%; flex-direction: column; align-items: flex-start; text-align: left; gap: 2px; }
.route { display: flex; flex-direction: column; gap: 8px; }
.mini li { display: flex; gap: 8px; font-size: 14px; padding: 2px 0; }
.mini .time { font-family: var(--mono); width: 3.2em; flex: none; }
.swap { align-self: flex-end; }

/* 保存状態・通知 */
.status-bar { position: fixed; bottom: calc(10px + env(safe-area-inset-bottom)); left: 0; right: 0; text-align: center; pointer-events: none; z-index: 3; }
#status { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--chip); color: var(--muted); }
#status[data-state="offline"], #status[data-state="error"] { color: var(--danger); }
#status[data-state="saved"] { opacity: .7; }
#toast {
  position: fixed; left: 50%; bottom: calc(50px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 30; font-size: 14px; max-width: 90vw; width: max-content;
}
