:root {
  --bg: #f7f6f2;
  --card: #ffffff;
  --glass: rgba(255, 255, 255, .86);
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --faint: #a7a59e;
  --line: #e2e0d9;
  --track: #e8e6df;
  --pull: #1f6fb2;
  --pull-soft: #e3eef8;
  --push: #c2552d;
  --push-soft: #f8e7df;
  --ring: #4e9a6b;
  --ring-soft: #d5eadb;
  --err: #9a3412;
  --on-accent: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 6px 20px rgba(0, 0, 0, .07);
  --kb: 0px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141414; --card: #1f1f1f; --glass: rgba(31, 31, 31, .88); --ink: #ededed; --muted: #a0a0a0; --faint: #5f5f5f;
    --line: #2e2e2e; --track: #2a2a2a; --pull: #5aa2e0; --pull-soft: #1c2b3a; --push: #e07a55; --push-soft: #3a241c;
    --ring: #6bbf88; --ring-soft: #1f3527; --err: #f59e7a; --on-accent: #111111; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.35;
  -webkit-font-smoothing: antialiased; -webkit-user-select: none; user-select: none; touch-action: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.hidden { display: none !important; }

#map { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; cursor: grab; }
#map.dragging { cursor: grabbing; }

/* top: a small floating card */
.hud {
  position: fixed; z-index: 5; left: 10px; right: 10px; top: calc(10px + env(safe-area-inset-top));
  padding: 10px 12px 12px 14px; border-radius: 16px;
  background: var(--glass); box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.hud-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 26px; }
.route { font-weight: 700; font-size: 17px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: inline-flex; align-items: center; gap: 6px; }
.route svg { width: 16px; height: 16px; flex: none; fill: none; stroke: var(--faint); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.route .tgt { color: var(--ring); }
.route { min-width: 0; flex: 1; text-overflow: clip; }
.route .st { color: var(--muted); font-weight: 600; }
.route .mys { color: var(--ring); letter-spacing: .08em; }
.route .gave { text-decoration: underline dotted; text-underline-offset: 3px; }
.route .fold { color: var(--faint); }
.icon-btn { width: 32px; height: 32px; margin: -4px -4px -4px 0; border-radius: 10px; display: grid; place-items: center; color: var(--muted); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.icon-btn[aria-expanded="true"] { background: var(--track); color: var(--ink); }
.link-btn { color: var(--muted); font-weight: 600; font-size: 14px; padding: 4px 2px; }
.stats { margin-top: 2px; }
.close { font-size: 15px; font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.close b { font-size: 22px; font-weight: 700; color: var(--ink); letter-spacing: -.02em; }
.moves { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.delta { margin-left: 8px; font-size: 12px; font-weight: 600; padding: 2px 7px; border-radius: 9px; background: var(--track); color: var(--muted); vertical-align: 2px; }
.delta:empty { display: none; }
.delta.up { background: var(--ring-soft); color: var(--ring); }
.bar { position: relative; height: 5px; margin-top: 8px; border-radius: 3px; background: var(--track); }
.bar-band { display: none; position: absolute; top: 0; bottom: 0; left: 85%; right: 0; background: var(--ring-soft); border-radius: 0 3px 3px 0; border-left: 2px solid var(--ring); }
.bar-fill { position: absolute; top: 0; bottom: 0; left: 0; width: 0; border-radius: 3px; background: var(--ink); transition: width .6s cubic-bezier(.3, .7, .2, 1), background .3s; }
.bar-fill.in { background: var(--ring); }

/* the one small menu */
.menu {
  position: fixed; z-index: 11; right: 10px; min-width: 180px; padding: 6px; border-radius: 14px;
  background: var(--card); box-shadow: 0 8px 28px rgba(0, 0, 0, .16); animation: pop .16s ease;
}
.menu button { display: block; width: 100%; text-align: left; padding: 11px 12px; border-radius: 9px; font-weight: 500; font-size: 15px; }
.menu button:active { background: var(--track); }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }

/* bottom: a floating card with the input and the two actions */
.dock {
  position: fixed; left: 10px; right: 10px; bottom: calc(var(--kb) + 10px + env(safe-area-inset-bottom)); z-index: 5;
  padding: 10px; border-radius: 18px; background: var(--glass); box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  transition: transform .35s ease, opacity .25s;
}
.dock.away { transform: translateY(calc(100% + 30px)); opacity: 0; pointer-events: none; }
.card { padding: 2px 4px 10px; transition: opacity .2s; }
.card .land, .card .tip, .card .step, .card .undo { transition: opacity .25s; }
.card.pending .land, .card.pending .tip, .card.pending .step, .card.pending .undo { opacity: 0; transition: none; }
.res { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.res .sg { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; font-size: 14px; }
.res .sg svg { width: 20px; height: 20px; flex: none; }
.sg.push { color: var(--push); } .sg.pull { color: var(--pull); }
.undo { color: var(--muted); font-weight: 600; font-size: 14px; padding: 4px 2px 4px 10px; display: inline-flex; align-items: center; gap: 4px; }
.undo svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.card .land { font-weight: 700; font-size: 17px; margin-top: 3px; font-variant-numeric: tabular-nums; }
.card .land span { font-weight: 500; color: var(--muted); font-size: 15px; }
.card .tip { font-size: 13.5px; color: var(--muted); margin-top: 4px; }
.card .lead { font-size: 15px; color: var(--muted); }
.card .step { font-size: 16px; font-weight: 600; margin-top: 4px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card .btn { margin-top: 10px; }
.chip { height: 32px; padding: 0 12px; border-radius: 16px; border: 1.5px solid var(--line); background: var(--card); font-weight: 600; font-size: 14px; }

.form { display: block; }
.word {
  display: block; width: 100%; height: 48px; padding: 0 14px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-size: 17px; outline: none; -webkit-user-select: text; user-select: text;
}
.word:focus { border-color: var(--muted); }
.word.bad { border-color: var(--err); }
/* refusals float just above the card, so nothing shifts and the map frame stays put */
.err {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 8px); padding: 9px 12px; border-radius: 12px;
  background: var(--card); box-shadow: var(--shadow); font-size: 14px; font-weight: 500; color: var(--err); animation: pop .16s ease;
}
.err:empty { display: none; }
.acts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.act {
  height: 54px; border-radius: 13px; display: flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 700; font-size: 16px; color: var(--on-accent); transition: opacity .2s, transform .08s;
}
.act svg { width: 26px; height: 26px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.act svg .dot { fill: currentColor; stroke: none; }
.act.push { background: var(--push); }
.act.pull { background: var(--pull); }
.act:active { transform: scale(.97); }
.act.idle { opacity: .4; }
.act:disabled { opacity: .3; }
.act.nudge { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ink); opacity: 1; }
.t-pull { color: var(--pull); } .t-push { color: var(--push); }

.btn { display: block; width: 100%; height: 48px; border-radius: 12px; font-weight: 700; font-size: 16px; }
.btn.primary { background: var(--ink); color: var(--bg); }
.btn.primary.done { background: var(--ring); color: var(--on-accent); }
.btn.more { background: var(--ring); color: var(--on-accent); }
.btn.more.done { background: var(--ink); color: var(--bg); }
.btn.quiet { background: var(--track); color: var(--ink); }
.btn.quiet.done { background: var(--ring-soft); color: var(--ring); }
.end-acts { display: flex; flex-direction: column; gap: 8px; }
.end-acts.free { flex-direction: column-reverse; }
.mode { margin-right: 8px; padding: 2px 8px; border-radius: 9px; background: var(--ring-soft); color: var(--ring); font-size: 12px; font-weight: 700; vertical-align: 1px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 8; max-width: calc(100vw - 32px);
  padding: 9px 14px; border-radius: 12px; background: var(--ink); color: var(--bg); font-size: 14px; font-weight: 500; text-align: center;
}
.banner {
  position: fixed; left: 16px; right: 16px; z-index: 8; text-align: center; padding: 12px 14px; border-radius: 14px;
  background: var(--card); box-shadow: var(--shadow); font-weight: 700; font-size: 17px; animation: rise .35s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.catcher { position: fixed; inset: 0; z-index: 9; background: transparent; }
.sheet {
  position: fixed; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 10; max-height: 70vh; overflow-y: auto;
  padding: 14px 14px 14px; border-radius: 18px;
  background: var(--glass); box-shadow: 0 8px 28px rgba(0, 0, 0, .16); animation: up .35s cubic-bezier(.3, .7, .2, 1);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  touch-action: pan-y; -webkit-user-select: text; user-select: text;
}
.sheet.end { z-index: 6; }
@keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.sheet h2 { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0 10px; }
.stats-grid div { display: flex; flex-direction: column; align-items: center; padding: 5px 0; border-radius: 12px; background: var(--track); }
.st-num { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.st-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.fine { font-size: 13px; color: var(--muted); }
.fine.center { text-align: center; margin-top: 10px; }
.share-preview {
  margin: 8px 0; padding: 8px 12px; border-radius: 10px; background: var(--track); font: 12.5px/1.4 ui-monospace, "SF Mono", Menlo, monospace;
  white-space: pre-wrap; color: var(--ink); font-variant-ligatures: none;
}
.end-pill {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 6;
  display: flex; align-items: center; gap: 6px; height: 44px; padding: 0 16px; border-radius: 22px; background: var(--card); box-shadow: var(--shadow);
  font-weight: 600; font-size: 15px; white-space: nowrap;
}
.pill-part.strong { font-weight: 700; }
.pill-dot { color: var(--muted); }
.hist { list-style: none; margin-top: 4px; }
.hist li { display: grid; grid-template-columns: 20px 1fr auto; gap: 2px 10px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 14.5px; font-variant-numeric: tabular-nums; }
.hist .n { color: var(--muted); }
.hist .mv .sg { font-weight: 600; }
.hist .mv .to { color: var(--muted); }
.hist .pc { text-align: right; }
.hist li.undone .mv, .hist li.undone .pc { text-decoration: line-through; color: var(--faint); }
.hist li.undone .sg { color: var(--faint); }
.hist .empty { display: block; color: var(--muted); border-top: 0; }
.help { margin: 8px 0 4px 18px; font-size: 15px; }
.help li { margin: 7px 0; }

.loading { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: var(--bg); color: var(--muted); font-weight: 500; }
