/* Whiteboard. One screen: the header and its actions at the top, the board
   in the middle, the tools at the bottom where a thumb reaches. An
   app, so every control is at least 44px (R-G26b). */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* any class that sets display would otherwise beat the UA's [hidden] */
[hidden] { display: none !important; }

:root {
  --bg: #12151c;
  --bg2: #1a1f29;
  --line: #2a3240;
  --ink: #e9edf4;
  --dim: #9aa8bd;
  --accent: #4cb3e8;
  --accentInk: #06222f;
  --stage: #0d1016;
  --radius: 14px;
  --pad: 12px;
}

/* R-C40: the light look; "auto" follows the device */
:root[data-theme="light"] {
  --bg: #f4f6fa; --bg2: #ffffff; --line: #d8dfea;
  --ink: #17202c; --dim: #5b6779; --accentInk: #ffffff;
  --accent: #0075a6; --stage: #e3e8ef;
}

/* a one-screen app: the page itself never scrolls or bounces (R-C15) */
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px; line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

#app {
  height: 100%; display: flex; flex-direction: column;
  padding: 0 var(--pad) env(safe-area-inset-bottom);
  max-width: 1100px; margin: 0 auto;
}

/* ---------- header ---------- */
#hdr {
  display: flex; align-items: center; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 0 8px;
  border-bottom: 1px solid var(--line);
}
#hdr h1 { font-size: 19px; font-weight: 800; letter-spacing: -0.01em; white-space: nowrap; }
#hdrSpace, .grow { flex: 1; }

.pill {
  min-width: 44px; min-height: 44px;
  border-radius: 999px; border: 2px solid var(--line);
  background: var(--bg2); color: inherit; font: inherit; font-size: 18px;
  cursor: pointer;
}
.pill.danger { font-size: 14px; min-height: 44px; padding: 0 10px; border-color: #c0392b; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 14px;
  border-radius: 12px; border: 2px solid var(--line);
  background: var(--bg2); color: inherit; font: inherit; font-weight: 600;
  cursor: pointer; text-align: center;
}
.btn.primary { border-color: var(--accent); }
.pill:focus-visible, .btn:focus-visible, .tool:focus-visible, .swatch:focus-visible, textarea:focus-visible,
input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.actions { display: flex; align-items: center; gap: 8px; padding: 8px 0; }

/* ---------- the picture ---------- */
.stage {
  position: relative; flex: 1; min-height: 0;
  border-radius: 12px; overflow: hidden; background: var(--stage);
}
#board { display: block; touch-action: none; }

/* on the board: show everything (bottom left), and what to do with a selection (bottom right) */
.floatFit { position: absolute; left: 8px; bottom: 8px; z-index: 2; min-width: 44px; min-height: 44px; font-size: 20px; }
.selbar { position: absolute; right: 8px; bottom: 8px; z-index: 2; display: flex; gap: 6px; }
.btn.danger { border-color: #c0392b; }

/* ---------- tools ---------- */
.tools { padding: 8px 0 4px; display: flex; flex-direction: column; gap: 6px; }
.toolrow { display: flex; align-items: center; gap: 4px; }
.tool {
  min-width: 44px; min-height: 48px; flex: 1 1 0;
  border-radius: 12px; border: 2px solid var(--line);
  background: var(--bg2); color: inherit; font-size: 21px; cursor: pointer;
}
.tool[aria-pressed="true"] { border-color: var(--accent); }
.tool:disabled { opacity: 0.4; }
.swatch {
  width: 44px; height: 44px; min-width: 44px; flex: 0 0 auto;
  border-radius: 999px; border: 3px solid var(--line); cursor: pointer;
}
.swatch[aria-pressed="true"] { border-color: var(--ink); }
.toolrow .swatch[data-color="#16181d"] { background: #16181d; }
.toolrow .swatch[data-color="#e0312b"] { background: #e0312b; }
.toolrow .swatch[data-color="#1f63d6"] { background: #1f63d6; }
/* 🎨 wears the colour in use as its ring */
.styleBtn { box-shadow: inset 0 0 0 4px var(--pick, #16181d); }

#footer { padding: 2px 0 4px; font-size: 12px; color: var(--dim); }

/* undo and redo sit in the top bar beside Send; at 320 px all four keep one line */
.actions .tool { min-width: 44px; min-height: 44px; font-size: 19px; flex: 0 0 auto; }
.actions .btn { padding: 8px 10px; white-space: nowrap; }

/* ---------- sheets ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, 0.45);
}
.sheetCard {
  width: 100%; max-width: 520px; max-height: 92%; overflow-y: auto;
  background: var(--bg2); border-radius: 18px 18px 0 0;
  padding: 16px var(--pad) max(16px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
}
.sheetCard h2 { font-size: 18px; }
.sheetCard p { font-size: 15px; }
.hint { color: var(--dim); font-size: 13px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row .btn { flex: 1 1 0; }
.chk { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.chk input { width: 22px; height: 22px; }

.lfield { display: grid; grid-template-columns: 84px 1fr; align-items: center; gap: 4px 10px; }
.lfield span { color: var(--dim); font-size: 14px; }
.lfield input, #textIn {
  min-height: 48px; padding: 8px 12px; width: 100%;
  border-radius: 10px; border: 2px solid var(--line);
  background: var(--bg); color: var(--ink); font: inherit; font-size: 20px;
}
#textIn { resize: vertical; }

/* the style drawer */
.palette { display: grid; grid-template-columns: repeat(6, 44px); gap: 8px; justify-content: start; }
.palette .swatch { border-color: var(--line); }
.palette .swatch[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.anyColour { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.swatch.custom {
  position: relative; overflow: hidden; display: inline-block;
  background:
    radial-gradient(circle, var(--pick, #7a3fd1) 0 42%, transparent 45%),
    conic-gradient(#e0312b, #ffc928, #3cc463, #29b6d8, #1f63d6, #b23fd1, #e0312b);
}
.swatch.custom input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; border: 0; padding: 0; cursor: pointer; }
.sizes .btn { min-width: 64px; }
.sizeBtn[aria-pressed="true"], .shapes .btn[aria-pressed="true"] { border-color: var(--accent); }
.lw { display: block; width: 32px; margin: 0 auto; border-radius: 4px; background: currentColor; }

/* the boards list */
.skrow { display: flex; align-items: center; gap: 8px; }
.skopen {
  flex: 1; display: flex; align-items: center; gap: 10px; min-height: 64px; text-align: left;
  border: 2px solid var(--line); border-radius: 12px; background: var(--bg); color: inherit;
  font: inherit; padding: 6px; cursor: pointer;
}
.skopen img { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; background: #fff; }
.skopen span { display: flex; flex-direction: column; }
.skopen small { color: var(--dim); }
.skdel { flex: 0 0 auto; }
#boardList { display: flex; flex-direction: column; gap: 8px; }

/* ---------- toast ---------- */
.toastHost {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translateX(-50%); max-width: 90%;
  padding: 10px 14px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.toastHost.on { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .toastHost { transition: none; } }
