:root {
  --bg: #111214; --panel: #1e1f22; --panel2: #2b2d31; --text: #dbdee1; --muted: #949ba4;
  --accent: #5865f2; --ok: #23a55a; --bad: #f23f43; --line: #3f4147;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; overflow: hidden; }
button { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
button:hover { border-color: var(--muted); }
button:disabled { opacity: .4; cursor: default; }
button.small { padding: 3px 8px; font-size: 12px; }
button.link { background: none; border: none; color: var(--muted); padding: 0; text-decoration: underline; }
input, select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
.muted { color: var(--muted); }
.small-text { font-size: 12px; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: grid; place-items: center; z-index: 50; }
.overlay[hidden] { display: none; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; width: min(380px, 92vw); display: grid; gap: 12px; }
.card h1 { margin: 0; font-size: 22px; }
.card label { display: grid; gap: 4px; }
.card label.row { display: flex; gap: 8px; align-items: center; }
.card button[type=submit] { background: var(--accent); border-color: var(--accent); padding: 10px; font-weight: 600; }

#top { position: fixed; top: 0; left: 0; right: 0; height: 48px; display: flex; align-items: center; gap: 16px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--line); z-index: 10; }
.tabs { display: flex; gap: 4px; }
.tab { white-space: nowrap; }
.tab.on { background: var(--accent); border-color: var(--accent); }
#charges { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.bar { width: 80px; height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
#charge-fill { height: 100%; width: 0; background: var(--ok); transition: width .2s; }
.boost { display: flex; align-items: center; gap: 6px; margin-left: auto; color: #ffd635; font-size: 12px; font-weight: 600; white-space: nowrap; cursor: help; }
.boost[hidden] { display: none; }
.boost + #charges { margin-left: 0; }
.boost-bar { width: 56px; height: 6px; }
#boost-fill { height: 100%; width: 0; background: #ffd635; transition: width .4s; }
#charge-text { font-variant-numeric: tabular-nums; min-width: 7.5em; }
.me { color: var(--muted); white-space: nowrap; }

#stage { position: fixed; top: 48px; left: 0; right: 260px; bottom: 64px; overflow: hidden; background: #0b0c0e; cursor: crosshair; touch-action: none; }
#cv { position: absolute; left: 0; top: 0; transform-origin: 0 0; image-rendering: pixelated; image-rendering: crisp-edges; box-shadow: 0 0 0 1px var(--line); }
#cursor { position: absolute; pointer-events: none; border: 1px solid #fff; box-shadow: 0 0 0 1px #000; display: none; }
#cursor.sel { border-style: dashed; border-color: #ffd635; }
#coords { position: absolute; left: 8px; bottom: 8px; color: var(--muted); font-size: 12px; background: rgba(0,0,0,.5); padding: 2px 6px; border-radius: 4px; }

#side { position: fixed; top: 48px; right: 0; width: 260px; bottom: 64px; background: var(--panel); border-left: 1px solid var(--line); padding: 12px; overflow-y: auto; display: grid; align-content: start; gap: 16px; }
#side h3 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
#side h4 { margin: 10px 0 4px; font-size: 12px; color: var(--muted); }
#side ol, #side ul { margin: 0; padding-left: 18px; }
#board li { margin: 2px 0; }
#board li b { float: right; font-variant-numeric: tabular-nums; }
#board li.mine { color: #ffd635; }
#reports li { margin: 6px 0; }
#reports .acts { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.modrow { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
section[hidden] { display: none; }

#palette { position: fixed; left: 0; right: 0; bottom: 0; height: 64px; background: var(--panel); border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: center; gap: 4px; flex-wrap: wrap; padding: 6px; }
.sw { width: 26px; height: 22px; border-radius: 4px; border: 2px solid transparent; cursor: pointer; padding: 0; }
.sw.custom.empty { background: repeating-linear-gradient(45deg, var(--panel2) 0 4px, var(--bg) 4px 8px); border: 2px dashed var(--line); }
.sw-sep { width: 1px; height: 22px; background: var(--line); margin: 0 6px; }
.picker { position: fixed; left: 50%; bottom: 40px; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.hex-box { position: fixed; z-index: 40; background: var(--panel); border: 1px solid var(--accent); border-radius: 8px; padding: 6px; }
.hex-box[hidden] { display: none; }
.hex-box input { width: 120px; font-family: ui-monospace, monospace; }
.sw.on { border-color: #fff; box-shadow: 0 0 0 2px #000 inset; transform: translateY(-2px); }

.share-card { width: min(560px, 94vw); }
.share-areas { display: flex; gap: 6px; flex-wrap: wrap; }
.share-areas button.on { background: var(--accent); border-color: var(--accent); }
.share-preview { background: #0b0c0e; border: 1px solid var(--line); border-radius: 8px; display: grid; place-items: center; min-height: 160px; max-height: 50vh; overflow: hidden; }
.share-preview img { max-width: 100%; max-height: 50vh; image-rendering: pixelated; }
#share-acts button.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }

.hint { position: absolute; left: 50%; bottom: 44px; transform: translateX(-50%); z-index: 5; display: flex; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--accent); border-radius: 8px; padding: 8px 12px; box-shadow: 0 4px 16px rgba(0,0,0,.4); max-width: calc(100% - 32px); }
.hint[hidden] { display: none; }
.hint button { white-space: nowrap; }

#toast { position: fixed; left: 50%; top: 60px; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 8px 14px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 60; }
#toast.show { opacity: 1; }

@media (max-width: 720px) {
  #stage { right: 0; bottom: 96px; }
  #side { display: none; }
  #palette { height: 96px; }
  .bar { width: 60px; }
  #charge-text { min-width: 0; }
  .boost-label { display: none; }   /* narrow screens: just the bar; tapping it explains */
  .me { display: none; }
  /* phone header: everything on one 48 px row */
  #top { gap: 6px; padding: 0 8px; }
  #top button { padding: 5px 8px; font-size: 13px; }
  .tab { max-width: 92px; overflow: hidden; text-overflow: ellipsis; }
  #charges .bar { display: none; }
  .boost-bar { width: 28px; }
  /* palette: 16 colours + 8 custom slots in two rows */
  #palette { gap: 3px; padding: 4px; }
  .sw { width: 22px; height: 22px; }
  .sw-sep { margin: 0 2px; }
}
#coords:empty { display: none; }

#map { position: absolute; inset: 0; }
#map[hidden], #ov[hidden], #cv[hidden] { display: none; }
#ov { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#board li[data-act] { cursor: pointer; }
#board li[data-act]:hover { text-decoration: underline; }

.shop-btn { background: #3ba55d; border-color: #3ba55d; font-weight: 600; white-space: nowrap; }
.shop-card { width: min(520px, 94vw); max-height: 86vh; overflow: auto; }
.coins-balance { font-size: 15px; padding: 8px 10px; background: var(--panel2); border-radius: 8px; }
.coins-balance b { color: #ffd635; }
.shop-sec { margin: 6px 0 0; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.price.coin { background: #b8860b; border-color: #b8860b; }
.shop-head { display: flex; justify-content: space-between; align-items: center; }
.item { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 10px 0; border-top: 1px solid var(--line); }
.item b { display: block; }
.item .price { min-width: 84px; }
.gold { color: #ffd635; text-shadow: 0 0 6px rgba(255,214,53,.5); }
.price.vote { display: inline-block; text-align: center; padding: 6px 12px; border-radius: 6px; background: #3ba55d; color: #fff; text-decoration: none; font-weight: 600; }
.check-opts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.check-opts button { height: 64px; border-radius: 10px; border: 2px solid var(--line); }
.check-opts button:hover { border-color: #fff; }
#tplc { position: absolute; left: 0; top: 0; transform-origin: 0 0; image-rendering: pixelated; pointer-events: none; }
#tplc[hidden] { display: none; }
.tpl-list { list-style: none; padding: 0 !important; margin: 8px 0 0 !important; display: grid; gap: 8px; }
.tpl-list li { background: var(--panel2); border-radius: 8px; padding: 6px 8px; }
.tpl-name { font-weight: 600; font-size: 13px; }
.tpl-list .acts { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
