:root {
  --bg: #FFFFFF; --surface: #F3F5F8; --line: #E4E8EE; --ink: #0E1A2B; --muted: #5B6778;
  --accent: #C2410C; --on-accent: #FFFFFF;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --pad: 20px;
}
/* Each country gets its own tone. Colour and paper only. */
[data-country="jp"] { --bg: #F7F3EA; --surface: #EDE6D8; --line: #E2D9C7; --ink: #1C2541; --muted: #585D6C; --accent: #B42A2F; }
[data-country="cn"] { --bg: #FBF6EE; --surface: #F2E8D9; --line: #E8DCC8; --ink: #2A1B14; --muted: #68584C; --accent: #A11D1D; }
[data-country="kr"] { --bg: #FAFAF7; --surface: #EDEFF2; --line: #E3E6EA; --ink: #10223F; --muted: #566072; --accent: #1F4E9C; }

* { box-sizing: border-box; }
html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  color: var(--ink); background: var(--bg);
  transition: background-color 500ms var(--ease);
}
button, a.btn, [role="tab"] { touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); }

#app { height: 100dvh; display: flex; flex-direction: column; }
.scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.page {
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) var(--pad) 32px;
  display: flex; flex-direction: column; gap: 18px;
  animation: rise 280ms var(--ease) both;
}
.footer { display: flex; gap: 10px; padding: 12px var(--pad) calc(env(safe-area-inset-bottom, 0px) + 12px); border-top: 1px solid var(--line); background: var(--bg); }
.footer > * { flex: 1; }

h1 { font-size: 30px; line-height: 1.1; letter-spacing: -0.03em; margin: 0; text-wrap: balance; }
h2 { font-size: 19px; margin: 0; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.num { font-variant-numeric: tabular-nums; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.wrap { display: flex; flex-wrap: wrap; gap: 6px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

.choice { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; width: 100%; padding: 18px; border-radius: 18px; background: var(--surface); text-align: left; font-size: 17px; transition: transform 120ms var(--ease); }
.choice:active { transform: scale(0.98); }
.chip { min-height: 40px; padding: 0 14px; border-radius: 999px; font-size: 15px; font-weight: 600; background: var(--surface); transition: transform 120ms var(--ease), background-color 150ms; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.chip:active { transform: scale(0.96); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface); }
.seg button { min-height: 40px; border-radius: 9px; font-weight: 600; font-size: 15px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--bg); color: var(--ink); box-shadow: 0 1px 3px rgb(14 26 43 / 0.14); }

.primary, .secondary, a.btn { display: grid; place-items: center; min-height: 50px; border-radius: 14px; font-weight: 600; width: 100%; text-decoration: none; transition: transform 120ms var(--ease); }
.primary { background: var(--ink); color: var(--bg); }
.secondary, a.btn { box-shadow: inset 0 0 0 1px var(--ink); color: var(--ink); }
.danger { box-shadow: inset 0 0 0 1px #9B1C1C; color: #9B1C1C; }
.primary:active, .secondary:active, a.btn:active { transform: scale(0.98); }
.primary:disabled { opacity: 0.45; }
.field { width: 100%; min-height: 48px; padding: 12px 14px; border: 0; border-radius: 14px; background: var(--surface); appearance: none; -webkit-appearance: none; }
label.lbl { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }

.row { display: flex; align-items: center; gap: 12px; min-height: 54px; padding: 6px 0; border-bottom: 1px solid var(--line); width: 100%; text-align: left; }
button.row:active { opacity: 0.6; }
.grow { flex: 1; min-width: 0; }
.title { font-weight: 600; }
.check { width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--muted); flex: none; display: grid; place-items: center; color: var(--on-accent); font-size: 14px; font-weight: 700; }
[aria-checked="true"] > .check { background: var(--accent); border-color: var(--accent); }
.stepper { display: flex; align-items: center; gap: 10px; }
.round { width: 44px; height: 44px; border-radius: 12px; background: var(--surface); font-size: 20px; font-weight: 600; }

.kind { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--surface); font-size: 15px; }
.kind-flight { background: var(--ink); color: var(--bg); }
.kind-hotel { background: var(--accent); color: var(--on-accent); }
.time { width: 46px; flex: none; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; line-height: 1.3; }
.leg { display: flex; align-items: center; gap: 8px; min-height: 40px; padding-left: 58px; font-size: 14px; font-weight: 600; text-decoration: none; }
.leg::before { content: ""; width: 2px; height: 22px; background-image: linear-gradient(var(--muted) 50%, transparent 0); background-size: 2px 6px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions .primary { grid-column: 1 / -1; }
.note { padding: 12px 14px; border-radius: 14px; background: var(--surface); font-size: 14px; color: var(--muted); }

/* Time chart: one column per day, blocks placed by time of day (06–24). */
.chart { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px 0 4px; scroll-snap-type: x proximity; }
.chart::-webkit-scrollbar { display: none; }
.hours { flex: none; display: flex; flex-direction: column; justify-content: space-between; padding: 40px 2px 0 0; height: 182px; font-size: 10px; color: var(--muted); }
.cday { flex: none; width: 46px; display: flex; flex-direction: column; align-items: center; gap: 6px; scroll-snap-align: center; }
.clabel { font-size: 11px; color: var(--muted); text-align: center; line-height: 1.15; }
.clabel b { display: block; font-size: 16px; color: var(--ink); }
.cday[aria-pressed="true"] .clabel b { color: var(--accent); }
.ccol { position: relative; width: 100%; height: 140px; border-radius: 10px; background: var(--surface); overflow: hidden; }
.cday[aria-pressed="true"] .ccol { box-shadow: inset 0 0 0 2px var(--accent); }
.cblock { position: absolute; left: 6px; right: 6px; border-radius: 4px; background: var(--muted); }
.cblock.kind-flight { background: var(--ink); }
.cblock.kind-hotel { background: var(--accent); }
.cstay { position: absolute; left: 0; right: 0; top: 0; height: 6px; background: var(--accent); opacity: 0.45; }

/* Bottom sheet */
.scrim { position: fixed; inset: 0; background: rgb(14 26 43 / 0.45); z-index: 10; animation: fade 200ms both; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; max-width: 560px; margin: 0 auto; max-height: 85dvh;
  display: flex; flex-direction: column; background: var(--bg); border-radius: 24px 24px 0 0;
  box-shadow: 0 -8px 32px rgb(14 26 43 / 0.18);
  padding: 10px var(--pad) calc(env(safe-area-inset-bottom, 0px) + 16px);
  animation: up 340ms var(--ease) both;
}
.grab { align-self: center; width: 40px; height: 5px; border-radius: 999px; background: var(--line); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0 12px; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 10px; padding-bottom: 4px; }
.x { width: 44px; height: 44px; border-radius: 12px; background: var(--surface); font-size: 18px; flex: none; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(100%); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
@media (hover: hover) and (pointer: fine) {
  .chip:hover, .choice:hover { filter: brightness(0.97); }
}

/* swipe right to remove */
.swipe { position: relative; overflow: hidden; }
.swipe-under { position: absolute; inset: 0; display: flex; align-items: center; padding-left: 20px; background: #9B1C1C; color: #fff; font-weight: 600; opacity: 0; transition: opacity 120ms; }
.swipe.dragging .swipe-under, .swipe.gone .swipe-under { opacity: 1; }
.swipe > .row { position: relative; background: var(--bg); touch-action: pan-y; transition: transform 220ms var(--ease); }
.swipe.dragging > .row { transition: none; }
.swipe.gone > .row { transform: translateX(110%) !important; }
.undo { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 14px; background: var(--ink); color: var(--bg); animation: rise 240ms var(--ease) both; }
.undo button { min-height: 40px; padding: 0 12px; border-radius: 10px; background: var(--bg); color: var(--ink); font-weight: 600; }
.leg { flex-direction: column; align-items: flex-start; justify-content: center; gap: 0; color: var(--muted); font-weight: 500; position: relative; }
.leg::before { position: absolute; left: 24px; top: 9px; }
.leg.tight { color: #9B1C1C; }
.linkish { text-align: left; padding: 4px 0; min-height: 32px; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- trip toolbar ---------- */
.toolbar { display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; padding: 4px 6px calc(env(safe-area-inset-bottom, 0px) + 4px); border-top: 1px solid var(--line); background: var(--bg); }
.tb { display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 52px; justify-content: center; font-size: 11px; font-weight: 600; color: var(--muted); }
.tb span { font-size: 20px; line-height: 1; }
.tb[aria-current="page"] { color: var(--accent); }
.tb:active, .tb-add:active { transform: scale(0.94); }
.tb-add { justify-self: center; width: 52px; height: 52px; border-radius: 16px; background: var(--ink); color: var(--bg); font-size: 26px; display: grid; place-items: center; box-shadow: 0 4px 12px rgb(14 26 43 / 0.2); transition: transform 120ms var(--ease); }
.toast-wrap { position: fixed; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom, 0px) + 72px); padding: 0 var(--pad); z-index: 5; max-width: 560px; margin: 0 auto; }

/* ---------- plan details ---------- */
.round:disabled { opacity: 0.35; }
.warn { color: #9B1C1C; font-weight: 600; }
.gap { display: block; width: 100%; text-align: left; min-height: 40px; padding: 8px 0 8px 58px; font-size: 14px; color: var(--muted); border-bottom: 1px dashed var(--line); }
.gap u { color: var(--accent); text-underline-offset: 3px; }
.cday.empty .ccol { background: repeating-linear-gradient(135deg, var(--surface) 0 6px, transparent 6px 12px); }
textarea.field { resize: vertical; min-height: 64px; line-height: 1.4; }

/* ---------- map ---------- */
.map-slot { height: min(58dvh, 520px); border-radius: 16px; overflow: hidden; background: var(--surface); display: grid; place-items: center; color: var(--muted); font-size: 14px; }
.map { width: 100%; height: 100%; }
.pin { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--muted); color: #fff; font: 700 13px/1 -apple-system, system-ui, sans-serif; border: 2px solid #fff; box-shadow: 0 2px 6px rgb(0 0 0 / 0.3); }
.pin-flight { background: #0E1A2B; }
.pin-hotel { background: var(--accent); }
.pin-place, .pin-activity { background: #1F4E9C; }
.pin.approx { opacity: 0.55; border-style: dashed; }
.route { stroke: var(--accent); }
.leaflet-container { font: inherit; }

/* ---------- dark mode ---------- */
@media (prefers-color-scheme: dark) {
  :root, [data-country] { --bg: #0F141C; --surface: #1A212C; --line: #283140; --ink: #EEF1F5; --muted: #A3ADBB; --on-accent: #0F141C; }
  :root { --accent: #FF8A50; }
  [data-country="jp"] { --bg: #141A2E; --surface: #1E2640; --line: #2A3352; --accent: #F0776A; }
  [data-country="cn"] { --bg: #1E1411; --surface: #2A1E19; --line: #3A2A22; --accent: #F07D6B; }
  [data-country="kr"] { --bg: #0F1A2E; --surface: #18253D; --line: #24324D; --accent: #8AAEF2; }
  .warn, .leg.tight, .danger { color: #F4A3A3; }
  .danger { box-shadow: inset 0 0 0 1px #F4A3A3; }
  .swipe-under { background: #7A1F1F; }
  .leaflet-tile-pane { filter: brightness(0.75) contrast(1.1); }
}

/* ---------- map stop list, checklist, photos ---------- */
.stops { list-style: none; margin: 0; padding: 0; counter-reset: stop; }
.stops li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); counter-increment: stop; }
.stops li::before { content: counter(stop); min-width: 22px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.stops b { display: block; font-weight: 600; }
.check-btn { display: flex; flex: 1; align-items: center; gap: 10px; min-height: 44px; text-align: left; }
.strike { text-decoration: line-through; }
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.ph { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--surface); }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph .x { position: absolute; top: 2px; right: 2px; width: 32px; height: 32px; min-height: 0; border-radius: 50%; background: rgb(0 0 0 / 0.55); color: #fff; }
label.chip { cursor: pointer; }
