/* Route Doodle, sketchbook palette, fixed (the same in light and dark OS modes). */
:root {
  --bg: #eeeae1;
  --paper: #fcfaf4;
  --surface: #fcfaf4;
  --surface2: #e2ddd0;
  --line: rgba(44, 48, 56, .14);
  --ink: #2c3038;
  --muted: #787a80;
  --accent: #2f7d74;          /* you (teal) */
  --lane: #5b6068;
  --track: #7a4b32;
  --bad: #c4453a;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #e7b247;
  --tut-accent-ink: #2c3038;
  --tut-bubble: #fffdf8;
  --tut-ink: #2c3038;
  --tut-muted: #787a80;
  --tut-dim: rgba(34, 36, 42, .55);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; touch-action: manipulation; min-height: 100vh; overflow-x: hidden; }
button { font: inherit; color: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { position: relative; max-width: 560px; margin: 0 auto; padding: 0 12px 12px; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }

/* ---------- top bar + menu ---------- */
.topbar { display: flex; align-items: center; gap: 4px; height: 48px; }
.back, .iconbtn { width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 12px; color: var(--muted); text-decoration: none; font-size: 22px; background: none; border: 0; cursor: pointer; padding: 0; }
.back:hover, .iconbtn:hover, .iconbtn[aria-expanded="true"] { color: var(--ink); background: var(--surface2); }
.brand { flex: 1; text-align: center; font: 800 19px/1 system-ui, sans-serif; letter-spacing: .06em; text-transform: uppercase; color: var(--ink); }
.menu { position: absolute; right: 12px; top: 44px; z-index: 45; min-width: 190px; padding: 6px; background: var(--surface); border-radius: 14px; box-shadow: 0 14px 36px rgba(44, 48, 56, .22); display: flex; flex-direction: column; animation: pop .14s ease-out; }
.menu button { min-height: 46px; text-align: left; padding: 0 14px; border: 0; background: none; border-radius: 10px; cursor: pointer; font-weight: 600; }
.menu button:hover, .menu button:focus-visible { background: var(--surface2); }
@keyframes pop { from { transform: translateY(-4px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- buttons ---------- */
.btn { min-height: 44px; padding: 8px 16px; border-radius: 12px; border: 0; background: var(--surface2); color: var(--ink); cursor: pointer; font-weight: 650; transition: background .15s, transform .1s, opacity .15s; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover:not(:disabled) { background: #d6d0c1; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #266a62; }
.btn.quiet { background: transparent; }
.btn.small { min-height: 40px; padding: 4px 14px; font-size: 14px; }

/* ---------- chips ---------- */
.chips { display: flex; gap: 6px; margin: 0 0 2px; }
.pchip { position: relative; flex: 1 1 0; min-width: 0; min-height: 44px; display: flex; align-items: center; gap: 7px; padding: 4px 8px; border: 0; border-radius: 14px; background: var(--surface); cursor: pointer; text-align: left; }
.pchip.cur { box-shadow: inset 0 -3px 0 var(--pc); }
.pchip .av { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--pc); color: #fff; font-weight: 800; font-size: 13px; }
.pchip .cinfo { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; flex: 1; }
.pchip .nm { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pchip .sc { font-size: 17px; font-weight: 800; }
.bubble { position: absolute; inset: 0; z-index: 2; border-radius: inherit; display: flex; align-items: center; justify-content: center; background: var(--surface); box-shadow: inset 0 0 0 2px var(--pc); animation: bubble 2.6s ease-out forwards; pointer-events: none; font-weight: 800; font-size: 16px; color: var(--pc); }
@keyframes bubble { 0% { opacity: 0; transform: scale(.9); } 8% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- status ---------- */
.status { min-height: 32px; display: flex; align-items: center; gap: 8px; padding: 0 2px 2px; font-size: 15px; color: var(--muted); }
.status.mine { color: var(--ink); font-weight: 600; }
.status .msg { flex: 1; min-width: 0; }
.status .turnno { flex: none; font-size: 12px; font-weight: 700; color: var(--muted); background: var(--surface); border-radius: 8px; padding: 2px 7px; }
.status .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.thinking::after { content: ''; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

/* ---------- board ---------- */
.board-wrap { background: var(--paper); border-radius: 16px; box-shadow: 0 1px 0 var(--line), 0 3px 12px rgba(44, 48, 56, .08); }
.board { display: block; width: 100%; height: auto; aspect-ratio: 1 / 1; max-height: 62vh; touch-action: manipulation; }
.board .grid { stroke: rgba(44, 48, 56, .13); stroke-width: .02; }
.board .centre { fill: rgba(47, 125, 116, .09); }
.board .frame { fill: none; stroke: rgba(44, 48, 56, .35); stroke-width: .03; }
.board .spot { fill: rgba(47, 125, 116, .10); stroke: var(--accent); stroke-width: .045; stroke-dasharray: .12 .08; cursor: pointer; }
.board .hit { fill: transparent; cursor: pointer; }
.board .sel-ring { fill: none; stroke: var(--accent); stroke-width: .07; }
.board .preview { opacity: .9; }
.board .fresh { fill: rgba(47, 125, 116, .16); }
.board .loose { fill: var(--bad); }
.board .net-ok { fill: #2f7d74; }
.lane-body { fill: none; stroke: var(--lane); stroke-width: .3; stroke-linecap: butt; }
.lane-dash { fill: none; stroke: #f4f1ea; stroke-width: .035; stroke-dasharray: .09 .08; }
.track-ties { fill: none; stroke: #b08968; stroke-width: .26; stroke-dasharray: .045 .11; }
.track-rail { fill: none; stroke: var(--track); stroke-width: .075; }
.casing { fill: none; stroke: var(--paper); stroke-width: .46; }
.depot { fill: #f4efe2; stroke: var(--ink); stroke-width: .045; }
.depot-roof { fill: #c4453a; }

/* ---------- dice tray ---------- */
.tray { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 7px; margin-top: 10px; }
.die { position: relative; aspect-ratio: 1 / 1; min-height: 44px; border: 0; border-radius: 12px; background: var(--surface); box-shadow: 0 1px 0 var(--line), 0 2px 6px rgba(44, 48, 56, .08); cursor: pointer; padding: 5px; display: grid; place-items: center; transition: transform .15s, box-shadow .2s, opacity .2s; }
.die svg { width: 100%; height: 100%; display: block; }
.die.junction { background: #f3ecdc; }
.die.sel { box-shadow: 0 0 0 3px var(--accent); transform: translateY(-2px); }
.die.used { opacity: .28; cursor: default; }
.die.nofit { opacity: .5; }
.die.idle { cursor: default; }
.die.fresh { animation: roll .5s ease-out; }
.die.bonus { background: #fff; box-shadow: inset 0 0 0 1.5px #d9b44a, 0 2px 6px rgba(44, 48, 56, .08); color: #a17c12; font-weight: 800; display: flex; flex-direction: column; gap: 0; line-height: 1; }
.die.bonus .star { font-size: 22px; }
.die.bonus small { font-size: 11px; color: var(--muted); font-weight: 700; }
.die.bonus.sel { box-shadow: 0 0 0 3px var(--accent); }
.die .chk { position: absolute; right: 4px; top: 2px; font-size: 13px; color: var(--accent); font-weight: 900; }
@keyframes roll { 0% { transform: rotate(-12deg) scale(.8); opacity: 0; } 100% { transform: none; opacity: 1; } }

/* ---------- actions ---------- */
.actions-row { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; min-height: 56px; padding-top: 8px; }
.actions-row .grow { flex: 1 1 auto; max-width: 240px; }

/* ---------- drawer ---------- */
.drawer-wrap { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(44, 48, 56, .35); }
.drawer { position: relative; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; background: var(--surface); border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); animation: up .18s ease-out; box-shadow: 0 -10px 40px rgba(44, 48, 56, .2); }
@keyframes up { from { transform: translateY(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer h3 { font-size: 18px; margin-bottom: 8px; }
.drawer p { margin: 6px 0; }
.drawer .actions { display: flex; gap: 8px; margin-top: 14px; }
.drawer .actions .btn { flex: 1 1 0; white-space: nowrap; }
.drawer .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin: 12px 0 5px; }
.drawer .board { max-height: 46vh; background: var(--paper); border-radius: 12px; margin: 0 auto 8px; }
.bonus-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.bonus-grid button { border: 0; border-radius: 12px; background: var(--bg); padding: 8px 4px 6px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; min-height: 44px; }
.bonus-grid button svg { width: 60px; height: 60px; }
.bonus-grid button small { font-size: 12px; color: var(--muted); text-align: center; line-height: 1.2; }
.bonus-grid button:disabled { opacity: .3; cursor: not-allowed; }
.log { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; font-size: 13px; }
.log li { padding: 5px 2px; border-bottom: 1px solid var(--line); color: var(--muted); }
.log li:first-child { color: var(--ink); }
.setup-sheet .field { margin: 12px 0; }
.setup-sheet .label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 6px; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1 1 0; min-width: 0; min-height: 46px; border-radius: 12px; border: 0; background: var(--surface2); cursor: pointer; font-weight: 650; }
.seg button.on { background: var(--surface); box-shadow: inset 0 0 0 2px var(--accent); color: var(--accent); }

.table-wrap { overflow-x: auto; }
.scores { width: 100%; border-collapse: collapse; font-size: 14px; }
.scores th, .scores td { padding: 5px 4px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.scores th:first-child, .scores td:first-child { text-align: left; }
.scores thead th { color: var(--muted); font-size: 12px; font-weight: 600; }
.scores tr.tot td { font-weight: 900; font-size: 15px; border-bottom: 0; }
.scores td.me, .scores th.me { color: var(--accent); }

/* ---------- modals ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 40; background: rgba(44, 48, 56, .4); display: flex; align-items: center; justify-content: center; padding: 12px; }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 640px; max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(44, 48, 56, .3); }
.over-modal { max-width: 460px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; }
.modal-head h2 { font-size: 20px; }
.modal-body { padding: 0 18px 14px; overflow-y: auto; }
.modal-foot { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px 16px; }
.modal-foot .btn { flex: 1 1 110px; }
.rules h3 { font-size: 15px; margin: 16px 0 4px; }
.rules p, .rules li { font-size: 14px; }
.rules ol, .rules ul { padding-left: 20px; margin: 4px 0; }
.rules li { margin: 4px 0; }
.result-banner { font-size: 26px; font-weight: 850; margin: 0 0 8px; }
.result-banner.win { color: var(--accent); }

@media (min-width: 900px) {
  .app { max-width: 920px; }
  .game { display: grid; grid-template-columns: minmax(0, 1fr) 300px; grid-template-rows: auto auto auto auto 1fr; grid-template-areas: "chips chips" "status status" "board tray" "board actions" "board ."; column-gap: 20px; align-items: start; }
  .chips { grid-area: chips; justify-content: center; }
  .pchip { flex: 0 1 220px; }
  .status { grid-area: status; justify-content: center; font-size: 16px; }
  .status .msg { flex: 0 1 auto; }
  .board-wrap { grid-area: board; }
  .board { max-height: 76vh; margin: 0 auto; }
  .tray { grid-area: tray; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 0; }
  .actions-row { grid-area: actions; }
  .drawer-wrap { align-items: center; }
  .drawer { border-radius: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- online (a table with a friend: tables.js) ---------- */
/* a short notice (connection lost, the table was updated, the friend left) floats just under the status line,
   over the grid's top edge, so the board never moves */
.status-wrap { position: relative; }
.net-note { position: absolute; left: 50%; top: calc(100% + 2px); transform: translateX(-50%); z-index: 6; width: max-content; max-width: min(88vw, 360px);
  padding: 4px 12px; border-radius: 12px; background: var(--ink); color: var(--paper); font-size: 12.5px; font-weight: 700; line-height: 1.3; text-align: center;
  white-space: normal; box-shadow: 0 4px 14px rgba(44, 48, 56, .3); pointer-events: none; animation: net-fade .25s ease-out; }
@keyframes net-fade { from { opacity: 0; } to { opacity: 1; } }
.net-note[hidden] { display: none; }
/* the friend has finished this round (or is away): the chip says so */
.pchip.fin .nm { color: var(--ink); font-weight: 650; }
.pchip:disabled { cursor: default; }
/* a divider between the game rows (new game, online) and the help rows */
.menu #menu-help { border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; }
@media (min-width: 900px) {
  .status-wrap { grid-area: status; }
}
