/* Clockmakers: a warm workshop palette, fixed in light and dark OS modes.
   One accent (brass) marks "your move": free spaces, selections, Place. */
:root {
  color-scheme: light;
  --bg: #f2ece1;
  --card: #fdfaf3;
  --ink: #2a2018;
  --muted: #7a6a55;
  --soft: rgba(42, 32, 24, .07);
  --line: rgba(42, 32, 24, .14);
  --accent: #a1600b;
  --accent-soft: rgba(161, 96, 11, .16);
  --brass: #d79a2b;
  --cogc: #2f8f8a;
  --spring: #6b4fc0;
  --gold: #e0a93a;
  --bad: #b5402f;
  --plate: #e7dcc6;
  --plate-2: #dccfb3;
  --radius: 14px;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #d79a2b;
  --tut-accent-ink: #2a2018;
  --tut-bubble: #fdfaf3;
  --tut-ink: #2a2018;
  --tut-muted: #7a6a55;
  --tut-dim: rgba(42, 32, 24, .55);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  touch-action: manipulation;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------- top bar */
.topbar {
  display: flex; align-items: center; gap: 4px;
  max-width: 1040px; margin: 0 auto; height: 50px;
  padding: 0 max(6px, env(safe-area-inset-right)) 0 max(6px, env(safe-area-inset-left));
}
.back, .icon-btn {
  flex: none; width: 44px; height: 44px; display: grid; place-items: center;
  border: 0; border-radius: 12px; background: transparent; color: var(--ink);
  text-decoration: none; font-size: 22px; line-height: 1; cursor: pointer;
}
.back:hover, .icon-btn:hover { background: var(--soft); }
.brand {
  flex: 1; margin: 0; text-align: center; font-size: 18px; font-weight: 750;
  letter-spacing: .06em; font-variant: small-caps;
}
.back:focus-visible, .icon-btn:focus-visible, .btn:focus-visible, .pchip:focus-visible,
.tile:focus-visible, .seg button:focus-visible, .menu button:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}

/* ------------------------------------------------------------- buttons */
.btn {
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 0;
  background: var(--soft); cursor: pointer; font-weight: 650; line-height: 1.1;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .08s, background .15s, opacity .15s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); }
.btn[disabled] { opacity: .4; cursor: not-allowed; transform: none; }
.btn.icon { min-width: 44px; padding: 0 10px; }
.btn .ico { font-size: 19px; line-height: 1; }

/* ------------------------------------------------------------- layout */
.app {
  max-width: 1040px; margin: 0 auto;
  padding: 0 max(12px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr);
}
.side { display: grid; gap: 8px; align-content: start; min-width: 0; }
.board-area { position: relative; min-width: 0; display: grid; gap: 6px; }
@media (min-width: 920px) {
  .app { grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; padding-top: 6px; }
  .board-area { grid-column: 1; grid-row: 1; }
  .side { grid-column: 2; grid-row: 1; gap: 14px; }
}

/* ------------------------------------------------------------- score chips */
.scores { display: flex; gap: 5px; flex-wrap: nowrap; min-width: 0; }
.pchip {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 11px 0 5px; border: 0; border-radius: 22px;
  background: transparent; cursor: pointer; min-width: 0; flex: 0 1 auto;
  transition: background .2s, box-shadow .2s;
}
.pchip:hover { background: var(--soft); }
.pchip.turn { background: var(--card); box-shadow: 0 0 0 2px color-mix(in srgb, var(--pc) 45%, transparent), 0 1px 4px rgba(42, 32, 24, .08); }
.pchip.won .pts::after { content: " \2605"; color: var(--gold); }
.av {
  display: inline-grid; place-items: center; flex: none; width: 27px; height: 27px; border-radius: 50%;
  background: var(--pc, #888); color: #fff; font-size: 13px; font-weight: 800;
}
.pchip .nm { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pchip .pts { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }
.pchip .first-key { flex: none; width: 15px; height: 15px; color: var(--accent); }
.pchip .wk { display: inline-flex; gap: 2px; }
.pchip .wk i { width: 6px; height: 6px; border-radius: 50%; background: var(--pc); opacity: .85; }
.pchip .wk i.used { opacity: .22; }
.pchip.bump { animation: bump 1s ease-out 1 both; }
.pchip .delta {
  position: absolute; right: 2px; top: -5px; font-size: 12px; font-weight: 800; color: var(--pc);
  animation: rise 1.4s ease-out 1 both; pointer-events: none;
}
@keyframes bump { 0% { transform: none; } 30% { transform: scale(1.07); } 100% { transform: none; } }
@keyframes rise { 0% { opacity: 0; transform: translateY(6px); } 20% { opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; transform: translateY(-9px); } }
@media (max-width: 599px) {
  .scores[data-n="4"] .nm, .scores[data-n="3"] .rival .nm { display: none; }
  .scores[data-n="4"] .wk, .scores[data-n="3"] .wk { display: none; }
}

/* ------------------------------------------------------------- status */
.status-row { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.status { display: flex; align-items: center; gap: 8px; min-height: 24px; font-size: 15.5px; font-weight: 650; padding: 0 2px; }
.status .dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--pc); }
.status.mine .dot { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.status.err .msg { color: var(--bad); }
.status.thinking .msg { color: var(--muted); }
.status .msg { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-row .net { color: var(--muted); justify-content: flex-start; padding: 0 3px; font-size: 13px; }

/* ------------------------------------------------------------- the board */
.board-box { width: 100%; display: flex; justify-content: center; }
.board {
  width: 100%; max-width: min(100%, 460px); height: auto; display: block;
  touch-action: manipulation;
}
.wedge { fill: var(--wc, transparent); stroke: rgba(253, 250, 243, .55); stroke-width: 1.2; }
/* The rim must never be filled: the tinted wedges below it are the board's colour. */
.rim { fill: none; stroke: rgba(42, 32, 24, .12); stroke-width: 1.5; }
.teeth { fill: var(--plate-2); }
.hub { fill: #efe3c9; stroke: rgba(42, 32, 24, .2); stroke-width: 1.5; }
.hub-round { font-size: 15px; font-weight: 800; fill: var(--ink); text-anchor: middle; }
.hub-of { font-size: 8.5px; font-weight: 700; fill: var(--muted); text-anchor: middle; letter-spacing: .06em; }
.turn-arrow { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linecap: round; opacity: .55; }
.turn-arrow-head { fill: var(--accent); opacity: .55; }

.sp-face { fill: var(--card); stroke: rgba(42, 32, 24, .22); stroke-width: 1.4; transition: fill .2s, stroke .2s; }
.space.cog .sp-face { fill: #f6edda; }
.space .sp-hit { fill: transparent; cursor: default; }
.space.legal .sp-hit { cursor: pointer; }
.space.legal .sp-face { stroke: var(--accent); stroke-width: 2.2; }
.space.legal .sp-glow { fill: var(--accent); opacity: .07; }
.space.dim { opacity: .72; }
.space.sel .sp-face { stroke: var(--accent); stroke-width: 3.4; }
.space.sel .sp-glow { fill: var(--accent); opacity: .16; }
.space.fresh .sp-face { animation: freshring 1.4s ease-out 1 both; }
@keyframes freshring { 0% { stroke: var(--gold); stroke-width: 5; } 100% { stroke-width: 1.4; } }
.sp-label { font-size: 8px; font-weight: 700; fill: var(--muted); text-anchor: middle; letter-spacing: .02em; }
.sp-num { font-size: 12.5px; font-weight: 800; fill: var(--ink); text-anchor: middle; }
.sp-cost { font-size: 10px; font-weight: 700; fill: var(--muted); text-anchor: middle; }
.arrow { stroke: var(--muted); stroke-width: 1.3; fill: none; opacity: .7; }
.worker { stroke: #fff; stroke-width: 2; }
.worker-ini { font-size: 10px; font-weight: 800; fill: #fff; text-anchor: middle; }

/* the mainspring turns one wedge at the end of each round */
.inner-ring, .cog-spin {
  transform-box: view-box;
  transition: transform .8s cubic-bezier(.34, .1, .2, 1);
}
.inner-ring { transform: rotate(var(--rot, 0deg)); transform-origin: 180px 180px; }
.cog-spin { transform: rotate(calc(-1 * var(--rot, 0deg))); }
.board.no-anim .inner-ring, .board.no-anim .cog-spin { transition: none; }

/* ------------------------------------------------------------- action bar */
.actionbar {
  position: sticky; bottom: calc(6px + env(safe-area-inset-bottom)); z-index: 5;
  width: fit-content; max-width: 100%; margin: 0 auto; min-height: 52px;
  display: flex; gap: 6px; align-items: center; padding: 5px;
  background: var(--card); border-radius: 18px;
  box-shadow: 0 4px 18px rgba(42, 32, 24, .16);
  animation: barin .18s ease-out;
}
.actionbar:empty { visibility: hidden; animation: none; }
.actionbar .what { font-size: 13px; line-height: 1.25; padding: 0 6px; max-width: 200px; }
.actionbar .what b { font-size: 13.5px; }
@keyframes barin { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------- favours + supply */
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.tile {
  display: flex; flex-direction: column; gap: 1px; min-height: 58px; padding: 6px 7px;
  border: 0; border-radius: 12px; background: var(--card); box-shadow: inset 0 0 0 1.5px var(--line);
  text-align: left; cursor: default; min-width: 0;
}
.tile .tname { font-size: 12.5px; font-weight: 750; }
.tile .ttext { font-size: 11px; line-height: 1.25; color: var(--muted); }
.tiles.picking .tile { cursor: pointer; box-shadow: inset 0 0 0 2px var(--accent-soft); }
.tiles.picking .tile:hover { background: #fffdf7; }
.tile.selected { box-shadow: inset 0 0 0 2.5px var(--accent); background: #fffdf7; }
.tile.empty { opacity: .4; }

.supply {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  padding: 6px 8px; border-radius: 14px; background: var(--card); box-shadow: inset 0 0 0 1.5px var(--line);
}
.supply .sup { display: inline-flex; align-items: center; gap: 3px; font-size: 15px; font-weight: 750; font-variant-numeric: tabular-nums; }
.supply .sup + .sup { margin-left: 4px; }
.supply .sup svg { width: 19px; height: 19px; display: block; }
.supply .sup.wide { margin-left: auto; }
.supply .sup small { font-size: 11px; font-weight: 650; color: var(--muted); }
.supply .fav-chip { font-size: 11px; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 8px; padding: 2px 6px; }

/* ------------------------------------------------------------- overlays */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(42, 30, 16, .42); padding: 14px; overflow-y: auto;
}
.modal {
  width: 100%; max-width: 420px; max-height: calc(100vh - 28px); max-height: calc(100dvh - 28px); overflow-y: auto;
  background: var(--card); border-radius: 20px; padding: 18px;
  box-shadow: 0 12px 40px rgba(30, 20, 8, .28);
  animation: pop .18s ease-out;
}
.modal.wide { max-width: 600px; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h2 { margin: 0 0 12px; font-size: 20px; text-align: center; }
.modal-head { display: flex; align-items: center; gap: 8px; margin: -6px -6px 8px 0; }
.modal-head h2 { flex: 1; margin: 0; text-align: left; display: flex; align-items: center; gap: 8px; }
.modal-head h2 .pts { margin-left: auto; font-size: 22px; }
.modal .lede { margin: -4px 0 14px; text-align: center; color: var(--muted); font-size: 14px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.modal-actions .btn { flex: 1 1 auto; }

/* menu */
.menu-overlay { background: rgba(42, 30, 16, .12); place-items: start end; padding: 50px 10px 0; }
.menu {
  min-width: 212px; background: var(--card); border-radius: 16px; padding: 6px;
  box-shadow: 0 10px 30px rgba(30, 20, 8, .22); animation: pop .15s ease-out; display: grid;
}
.menu button {
  min-height: 48px; padding: 0 14px; border: 0; background: transparent; text-align: left;
  border-radius: 10px; cursor: pointer; font-size: 15px; font-weight: 550;
}
.menu button:hover { background: var(--soft); }
@media (min-width: 1060px) { .menu-overlay { padding-right: calc((100vw - 1040px) / 2 + 8px); } }

/* setup */
.field { margin: 14px 0; }
.field-label { font-weight: 650; margin-bottom: 6px; font-size: 14px; }
.field-hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--soft); }
.seg button { flex: 1; min-height: 44px; border: 0; border-radius: 10px; background: transparent; cursor: pointer; font-weight: 650; }
.seg button[aria-checked="true"] { background: var(--accent); color: #fff; }

/* info + viewer */
.info-round { margin: 0 0 12px; color: var(--muted); font-size: 13.5px; }
.info-scores { display: grid; gap: 12px; }
.info-player { display: grid; gap: 5px; }
.info-head { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.info-head .info-sub { font-weight: 400; font-size: 12.5px; color: var(--muted); }
.info-head .total { margin-left: auto; font-size: 18px; }
.sub-title { margin: 20px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.holding { display: flex; flex-wrap: wrap; gap: 5px; }
.holding .reg {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px 3px 5px; border-radius: 999px;
  background: var(--soft); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.holding .reg svg { width: 16px; height: 16px; display: block; }
.holding .reg.fav { background: var(--accent-soft); }
.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; font-size: 13px; max-height: 38vh; overflow-y: auto; }
.log li { display: flex; gap: 7px; align-items: flex-start; }
.log li .av { width: 18px; height: 18px; font-size: 10px; margin-top: 1px; }
.log li.round-line { color: var(--muted); font-style: italic; }
.viewer-body { display: grid; gap: 10px; }

/* help */
.help-body h3 { margin: 16px 0 4px; font-size: 15px; }
.help-body h3:first-child { margin-top: 0; }
.help-body p, .help-body li { font-size: 14px; }
.help-body ul, .help-body ol { padding-left: 20px; margin: 4px 0; }

/* game over */
.go-table { display: grid; gap: 4px; }
.go-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; }
.go-row.win { background: var(--accent-soft); }
.go-row .place { width: 26px; color: var(--muted); font-size: 13px; font-weight: 700; }
.go-name { display: flex; flex-direction: column; font-weight: 700; min-width: 0; }
.go-name small { font-weight: 400; color: var(--muted); font-size: 12px; }
.go-row .total { margin-left: auto; font-size: 22px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Online play (online.js) */
body.is-online #btn-new { display: none; }
.menu #menu-online { border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; margin-top: 4px; }
#over-leave { display: flex; width: 100%; margin-top: 8px; }
