/* Mongoose Inkboard. Tokens match the flagship's (bg / surface / text / accent), extended for this app's own elevation steps. */
:root {
  --bg: #12100d; --surface: #1c1812; --surface2: #262016; --surface3: #322a1d;
  --text: #eee4d3; --muted: #a89c86; --border: #3a3226; --border2: #4d4232;
  --accent: #6fe3c0; --accent-ink: #0b0f0c; --danger: #ff8a7a;
  --radius: 10px; --top: 52px; --rail: 54px; --panel: 272px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { display: flex; flex-direction: column; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
kbd { background: var(--surface3); border: 1px solid var(--border2); border-radius: 4px; padding: 0 5px; font-size: 12px; }
.muted { color: var(--muted); font-weight: 400; }
.noscript { padding: 2rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- top bar */
#top { min-height: var(--top); flex: none; display: flex; align-items: center; gap: 8px; padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
#top .spacer { flex: 1; }
.brand { display: flex; }
.brand canvas { width: 28px; height: 28px; image-rendering: pixelated; }
.logo { font-weight: 700; letter-spacing: 0.01em; font-size: 17px; }
.logo em { font-style: normal; color: var(--accent); }
#title { background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 5px 8px; width: 200px; min-width: 60px; }
#title:hover, #title:focus { border-color: var(--border2); background: var(--surface2); }
#savestate { font-size: 12px; white-space: nowrap; }
.tb { background: var(--surface2); border: 1px solid var(--border2); border-radius: 10px; padding: 6px 12px; line-height: 1.2; }
.tb:hover:not(:disabled) { background: var(--surface3); }
.tb:disabled { opacity: 0.4; cursor: default; }
.tb.icon { padding: 6px 9px; min-width: 34px; }
.tb.icon svg { width: 18px; height: 18px; display: block; }
.tb.small { padding: 2px 8px; font-size: 12px; }
.tb.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.tb.accent:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.tb.danger { color: var(--danger); }
.panel-toggle { display: none; }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 250px; background: var(--surface2); border: 1px solid var(--border2); border-radius: var(--radius); padding: 6px; z-index: 30; box-shadow: 0 12px 30px rgba(0,0,0,0.5); }
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; }
.menu button:hover { background: var(--surface3); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }

/* ---- layout */
#work { display: flex; flex: 1; min-height: 0; }
#tools { width: var(--rail); flex: none; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 0; background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; }
.tool { width: 40px; height: 40px; display: grid; place-items: center; place-content: center; padding: 0; background: none; border: 1px solid transparent; border-radius: 10px; }
.tool svg { width: 22px; height: 22px; }
.tool:hover { background: var(--surface2); }
.tool.on { background: var(--accent); color: var(--accent-ink); }
.tool-sep { width: 28px; border-top: 1px solid var(--border); margin: 4px 0; }
#stage { position: relative; flex: 1; min-width: 0; background: #0d0b09; overflow: hidden; }
#viewport { position: absolute; inset: 0; touch-action: none; cursor: crosshair; }
#viewport.pan { cursor: grab; }
#viewport.panning { cursor: grabbing; }
#viewport.select { cursor: default; }
#page { position: absolute; left: 0; top: 0; transform-origin: 0 0; box-shadow: 0 6px 40px rgba(0,0,0,0.6); background: #fff; }
#overlay { position: absolute; left: 0; top: 0; pointer-events: none; }
#text-editor { position: absolute; transform-origin: 0 0; background: rgba(255,255,255,0.4); border: 1px dashed var(--accent); border-radius: 2px; resize: none; overflow: hidden; padding: 0; margin: 0; line-height: 1.25; white-space: pre; outline: none; }
.hint { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); background: rgba(28,24,18,0.92); border: 1px solid var(--border2); border-radius: 16px; padding: 16px 22px; text-align: center; max-width: min(360px, 86%); pointer-events: none; }
.hint canvas { width: 64px; height: 64px; image-rendering: pixelated; }
.hint p { margin: 6px 0; }
#zoombar { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 4px; }

/* ---- side panel */
#panel { width: var(--panel); flex: none; background: var(--surface); border-left: 1px solid var(--border); overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.card h2 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card h2 .muted { text-transform: none; letter-spacing: 0; }
.row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.row > span { width: 78px; flex: none; color: var(--muted); }
.row input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }
.row output { width: 30px; text-align: right; font-variant-numeric: tabular-nums; }
input[type=text], input[type=number] { background: var(--surface); border: 1px solid var(--border2); border-radius: 6px; padding: 5px 8px; min-width: 0; }
select { background: var(--surface); border: 1px solid var(--border2); border-radius: 6px; padding: 5px 8px; min-width: 0; flex: 1; }
input[type=color] { width: 40px; height: 32px; padding: 0; border: 1px solid var(--border2); border-radius: 6px; background: none; cursor: pointer; }
#colour-hex { width: 90px; font-family: ui-monospace, Consolas, monospace; }
.swatches { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.swatch { width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--border2); padding: 0; }
.swatch.on { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.seg.wrap { margin-bottom: 10px; }
.seg button { background: var(--surface); border: 1px solid var(--border2); border-radius: 6px; padding: 5px 9px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btnrow { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.layers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column-reverse; gap: 4px; }
.layer { display: flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px 4px 3px 8px; }
.layer.on { border-color: var(--accent); }
.layer .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; background: none; border: 0; text-align: left; padding: 4px 0; }
.layer .lb { display: inline-grid; place-items: center; background: none; border: 0; padding: 3px 5px; border-radius: 6px; color: var(--muted); }
.layer .lb:hover { background: var(--surface3); color: var(--text); }
.layer .lb.active { color: var(--accent); }
.layer .rename { flex: 1; min-width: 0; }

/* ---- replay bar */
#replaybar { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 20; display: flex; align-items: center; gap: 8px; background: var(--surface2); border: 1px solid var(--border2); border-radius: 16px; padding: 8px 12px; box-shadow: 0 12px 30px rgba(0,0,0,0.5); max-width: calc(100% - 20px); }
#rp-scrub { width: min(280px, 30vw); accent-color: var(--accent); }

body.replaying #zoombar { display: none; }
body.replaying #toast-region { bottom: 130px; }

/* ---- dialogs */
dialog { background: var(--surface); color: var(--text); border: 1px solid var(--border2); border-radius: 16px; padding: 18px 20px; width: min(760px, 94vw); max-height: 88vh; overflow-y: auto; }
dialog::backdrop { background: rgba(0,0,0,0.6); }
#dlg-new { width: min(440px, 94vw); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.dlg-head h2, #new-title { margin: 0; font-size: 18px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin: 14px 0; }
.sheet { background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; }
.sheet.current { border-color: var(--accent); }
.sheet .thumb { aspect-ratio: 4 / 3; background: #fbf7ef center / contain no-repeat; border: 0; padding: 0; width: 100%; }
.sheet .info { padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.sheet .info b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet .info span { font-size: 12px; color: var(--muted); }
.sheet .acts { display: flex; gap: 6px; padding: 0 10px 10px; }
.empty { color: var(--muted); padding: 18px 4px; }
.fine { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
#new-form label { color: var(--muted); }
#new-form .row input[type=number] { width: 96px; margin-left: 6px; }

/* ---- toasts */
#toast-region { position: fixed; left: 50%; bottom: 74px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; z-index: 60; pointer-events: none; }
.toast { background: var(--surface3); border: 1px solid var(--border2); border-radius: 10px; padding: 8px 14px; box-shadow: 0 8px 24px rgba(0,0,0,0.5); max-width: 90vw; }

/* ---- small screens: tools along the bottom, panel as a sheet */
@media (max-width: 820px) {
  #top { flex-wrap: wrap; gap: 6px 6px; padding: 6px 10px; }
  #top .tb { padding: 6px 9px; }
  #title { flex: 1 1 100px; min-width: 0; width: auto; order: 1; }
  .logo, #savestate { display: none; }
  .panel-toggle { order: 2; }
  #top .spacer { flex: 0 0 100%; height: 0; order: 3; }
  #top > .tb, #top > .menu-wrap { order: 4; }
  #top > .panel-toggle { order: 2; }
  .panel-toggle { display: inline-block; }
  #work { flex-direction: column-reverse; }
  #tools { width: 100%; height: 56px; flex-direction: row; justify-content: flex-start; padding: 0 6px; border-right: 0; border-top: 1px solid var(--border); overflow-x: auto; overflow-y: hidden; gap: 2px; }
  .tool-sep { width: 0; height: 28px; border-top: 0; border-left: 1px solid var(--border); margin: 0 4px; }
  #panel { position: fixed; left: 0; right: 0; bottom: 56px; width: auto; max-height: 52vh; border: 1px solid var(--border2); border-radius: 16px 16px 0 0; z-index: 25; transform: translateY(110%); transition: transform 0.18s; box-shadow: 0 -10px 30px rgba(0,0,0,0.5); }
  body.panel-open #panel { transform: none; }
  #zoombar { bottom: 68px; }
  #replaybar { flex-wrap: wrap; justify-content: center; bottom: 66px; }
  #rp-scrub { width: 100%; order: 9; }
}
@media (max-width: 820px) and (prefers-reduced-motion: reduce) { #panel { transition: none; } }
