/* A friendly face, bundled rather than linked: a communication aid has to look
   the same on a tablet with no signal as it does on one with. Nunito is OFL,
   rounded without being childish, and its heavy weights stay legible at the
   small sizes a 10-column board forces on a label. */
@font-face {
  font-family: "Nunito";
  src: url("../fonts/nunito-latin.woff2") format("woff2");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}

/* Fredoka for anything a child looks at — button labels, headings. It is round
   and open, which is what makes it read as friendly rather than institutional,
   and its wide apertures hold up at the small sizes a ten-column board forces.
   Bundled, not linked: a board has to look the same with no signal. */
@font-face {
  font-family: "Fredoka";
  src: url("../fonts/fredoka-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Neutrals with a blue bias rather than pure grey — they sit under a board of
     saturated colour all day, and true grey next to it reads as dirty. */
  --bg: #eaf0fb;
  --bg-2: #ffffff;
  --bg-tint-a: rgba(99, 102, 241, .10);
  --bg-tint-b: rgba(236, 72, 153, .07);
  --bg-tint-c: rgba(34, 211, 238, .09);
  --panel: #ffffff;
  --panel-2: #eef2f9;
  --ink: #172233;
  --ink-soft: #5d6b80;
  --line: #d6dfec;
  --accent: #4f46e5;
  --accent-2: #7c6cf6;
  --accent-ink: #ffffff;
  --joy: #ff8a3d;
  --danger: #e03b45;
  --ok: #17a05a;
  --scan: #ff9500;
  --shadow: 0 1px 2px rgba(18, 30, 52, .06), 0 8px 24px rgba(18, 30, 52, .07);

  /* Fitzgerald Key colour coding (part of speech). Saturated enough to be fun,
     light enough that near-black text clears 4.5:1 on every one of them. */
  --c-pronoun:  #ffd45e;
  --c-verb:     #74dd9b;
  --c-descr:    #7cc6ef;
  --c-noun:     #ffa866;
  --c-social:   #fb9ac6;
  --c-question: #c39bf7;
  --c-misc:     #e6ebf5;
  --c-negate:   #ff8f8f;
  --c-folder:   #aebfdb;

  /* tunables written by JS */
  --gap: 10px;
  --radius: 26px;
  --rowh: 120px;
  --label-scale: 1;
  --grid-cols: 6;
}

/* Dark mode. "Match my device" (the default) follows the tablet's own setting;
   picking Light or Dark in Settings overrides it either way. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="contrast"]) {
    --bg: #0e1319;
    --panel: #18202a;
    --panel-2: #212b37;
    --ink: #eaf0f7;
    --ink-soft: #9aa8b8;
    --line: #2c3845;
    --accent: #5b90ff;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 22px rgba(0,0,0,.35);
    --c-pronoun:  #b39b2e;
    --c-verb:     #3f8f47;
    --c-descr:    #2f7fa8;
    --c-noun:     #b8752c;
    --c-social:   #a85280;
    --c-question: #7a4fa0;
    --c-misc:     #3a4553;
    --c-negate:   #a8434a;
    --c-folder:   #44525f;
  }
}

:root[data-theme="dark"] {
  --bg: #0d1219;
  --bg-2: #131b25;
  --panel: #18212c;
  --panel-2: #212c3a;
  --ink: #eaf0f8;
  --ink-soft: #9babbf;
  --line: #2c3948;
  --accent: #5b90ff;
  --accent-2: #86aeff;
  --joy: #ff9d5c;
  --shadow: 0 1px 2px rgba(0,0,0,.45), 0 10px 26px rgba(0,0,0,.38);
  --c-pronoun:  #a8882a;
  --c-verb:     #2f7f46;
  --c-descr:    #2a6f95;
  --c-noun:     #ad6a29;
  --c-social:   #9a4a74;
  --c-question: #6d47a0;
  --c-misc:     #323e4e;
  --c-negate:   #9c3d45;
  --c-folder:   #3c4a5c;
}

:root[data-theme="contrast"] {
  --bg: #000000;
  --panel: #000000;
  --panel-2: #111111;
  --ink: #ffffff;
  --ink-soft: #e0e0e0;
  --line: #ffffff;
  --accent: #ffff00;
  --accent-ink: #000000;
  --shadow: none;
  --c-pronoun: #000; --c-verb: #000; --c-descr: #000; --c-noun: #000;
  --c-social: #000; --c-question: #000; --c-misc: #000; --c-negate: #000;
  --c-folder: #000;
}
:root[data-theme="contrast"] .btn-cell { border-width: 3px; border-color: #fff; color: #fff; }
:root[data-theme="contrast"] .btn-cell .cell-label { color: #fff; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  /* Belt and braces for hosts where html's percentage height doesn't resolve
     (an embedding iframe, for example). The insets are zero everywhere except
     a phone with a notch, where they keep the board clear of the system bars. */
  min-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
}

body {
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(900px 620px at 8% -12%, var(--bg-tint-a), transparent 62%),
    radial-gradient(800px 560px at 102% 8%, var(--bg-tint-c), transparent 60%),
    radial-gradient(900px 620px at 50% 118%, var(--bg-tint-b), transparent 62%);
  background-attachment: fixed;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  user-select: none;
  touch-action: manipulation;
}

button { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- message */

#messagebar {
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 10px;
  background: color-mix(in srgb, var(--panel) 86%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

#message {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 84px;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--panel-2);
  border: 2px dashed var(--line);
  border-radius: 22px;
  padding: 8px 12px;
  cursor: pointer;
  scrollbar-width: thin;
}
#message:not(.empty) {
  border-style: solid;
  border-color: transparent;
  box-shadow: inset 0 0 0 2px var(--line);
}

#message.empty::after {
  content: attr(data-placeholder);
  color: var(--ink-soft);
  font-size: 1.15rem;
  padding-left: 8px;
}

@keyframes chip-pop {
  from { transform: scale(.55) translateY(6px); opacity: 0; }
  to   { transform: scale(1) translateY(0);     opacity: 1; }
}

.chip {
  animation: chip-pop .2s cubic-bezier(.34, 1.56, .64, 1);
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 62px;
  max-width: 132px;
  padding: 4px 8px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 10px;
  position: relative;
}
.chip .chip-img { font-size: 1.6rem; line-height: 1; height: 28px; display: flex; align-items: center; }
.chip .chip-img img { height: 28px; width: 28px; object-fit: contain; }
.chip .chip-text {
  font-size: calc(.85rem * var(--label-scale));
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 116px;
}
.chip.speaking { outline: 3px solid var(--accent); outline-offset: 2px; }

#message.text-only .chip { flex-direction: row; min-width: 0; }
#message.text-only .chip-img { display: none; }

.msg-actions { display: flex; gap: 8px; flex: 0 0 auto; align-items: stretch; }
#btn-speak { min-width: 104px; border-radius: 22px; }
#btn-speak .ico { font-size: 1.9rem; }
#btn-speak span:not(.ico) { font-size: calc(.82rem * var(--label-scale)); }

.tool {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 66px;
  min-height: 78px;
  padding: 6px 10px;
  border: none;
  border-radius: 18px;
  background: var(--panel-2);
  box-shadow: inset 0 0 0 2px var(--line), 0 2px 0 rgba(15, 25, 45, .06);
  cursor: pointer;
  font-family: "Fredoka", "Nunito", system-ui, sans-serif;
  font-size: calc(.74rem * var(--label-scale));
  font-weight: 500;
  line-height: 1.1;
  transition: transform .12s cubic-bezier(.34, 1.56, .64, 1), box-shadow .12s ease;
}
.tool:hover { transform: translateY(-1px); }
.tool .ico { font-size: 1.55rem; line-height: 1; }
.tool:active { transform: translateY(2px); }

/* Speak is the button the whole screen exists to reach, so it is the one thing
   allowed to be loud. */
.tool.primary {
  background: linear-gradient(145deg, var(--accent-2), var(--accent));
  color: var(--accent-ink);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, .22),
    0 5px 0 color-mix(in srgb, var(--accent) 70%, #000),
    0 12px 26px color-mix(in srgb, var(--accent) 45%, transparent);
}
.tool.primary:active {
  transform: translateY(4px);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .18), 0 1px 0 color-mix(in srgb, var(--accent) 70%, #000);
}
.tool.danger  { color: var(--danger); }
.tool.on      { background: var(--ok); border-color: var(--ok); color: #fff; }
.tool[disabled] { opacity: .4; cursor: default; }

/* ---------------------------------------------------------------- toolbar */

#toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  overflow-x: auto;
}
#toolbar .tool {
  min-height: 50px;
  min-width: 50px;
  padding: 5px 8px;
  background: transparent;
  box-shadow: none;
  color: var(--ink-soft);
  gap: 1px;
}
#toolbar .tool:hover { background: var(--panel-2); color: var(--ink); }
#toolbar .tool .ico { font-size: 1.2rem; }
#toolbar .tool span:not(.ico) { font-size: calc(.6rem * var(--label-scale)); opacity: .85; }

#boardtitle {
  flex: 1 1 auto;
  min-width: 0;
  font-family: "Fredoka", "Nunito", system-ui, sans-serif;
  font-weight: 600;
  font-size: calc(1.05rem * var(--label-scale));
  padding: 0 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#breadcrumb { font-weight: 500; color: var(--ink-soft); font-size: .8em; }

/* ------------------------------------------------------------ suggestions */

#suggestions {
  display: flex;
  gap: 6px;
  padding: 7px 10px;
  background: transparent;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  flex: 0 0 auto;
}
#suggestions:empty { display: none; }
.suggest-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.suggest-row:empty { display: none; }

.suggestion {
  flex: 0 0 auto;
  padding: 10px 18px;
  border-radius: 999px;
  border: none;
  background: var(--panel);
  box-shadow: inset 0 0 0 2px var(--line), 0 2px 6px rgba(15, 25, 45, .06);
  font-family: "Fredoka", "Nunito", system-ui, sans-serif;
  font-weight: 500;
  font-size: calc(1rem * var(--label-scale));
  cursor: pointer;
}

/* ------------------------------------------------------------------- grid */

#gridwrap { flex: 1 1 auto; min-height: 0; overflow: auto; padding: var(--gap); }

#grid {
  display: grid;
  /* --cell-min keeps buttons tappable on a phone: past that width the board
     scrolls sideways rather than shrinking, because squeezing the columns
     would move every word out from under the child's hand. */
  grid-template-columns: repeat(var(--grid-cols), minmax(var(--cell-min, 0px), 1fr));
  grid-auto-rows: var(--rowh);
  grid-auto-flow: row dense;
  gap: var(--gap);
}

/* A button you can feel: a light top edge, a darker bottom edge and a shadow
   underneath read as a physical key, and a physical key is what a child's hand
   is looking for. The press drops it onto the page rather than shrinking it —
   the same motion a real button makes. */
.btn-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 7px 6px 5px;
  border: none;
  border-radius: var(--radius);
  background: var(--c-misc);
  /* A single flat fill reads as a swatch. The highlight across the top is what
     makes it read as an object with a surface, which is what a hand reaches
     for. Kept to 14% so it never fights the colour coding. */
  background-image: linear-gradient(170deg, rgba(255, 255, 255, .42), rgba(255, 255, 255, 0) 52%,
                                    rgba(0, 0, 0, .05));
  color: #16202c;
  overflow: hidden;
  cursor: pointer;
  /* A white ring inside the edge is what makes a shape read as a sticker rather
     than a panel, and the flat coloured shadow underneath gives it a thickness
     a child's hand expects to be able to press. */
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, .55),
    inset 0 -5px 0 rgba(0, 0, 0, .09),
    0 5px 0 rgba(15, 25, 45, .10),
    0 10px 22px rgba(15, 25, 45, .12);
  transition: transform .13s cubic-bezier(.34, 1.56, .64, 1), box-shadow .13s ease;
}
.btn-cell:hover { transform: translateY(-2px); }
.btn-cell:active,
.btn-cell.pressed {
  transform: translateY(5px) scale(.985);
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, .4),
    inset 0 -2px 0 rgba(0, 0, 0, .10),
    0 0 0 rgba(15, 25, 45, .10),
    0 2px 6px rgba(15, 25, 45, .16);
}

.cell-img {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: min(3.9rem, calc(var(--rowh) * .46));
  filter: drop-shadow(0 2px 3px rgba(15, 25, 45, .16));
  line-height: 1;
}
.cell-img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.btn-cell[data-fit="cover"] .cell-img img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }

.cell-label {
  flex: 0 0 auto;
  font-family: "Fredoka", "Nunito", system-ui, sans-serif;
  font-weight: 600;
  letter-spacing: .005em;
  font-size: calc(clamp(.62rem, calc(var(--rowh) * .135), 1.35rem) * var(--label-scale));
  line-height: 1.1;
  text-align: center;
  width: 100%;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow-wrap: break-word;
  hyphens: auto;
}

.btn-cell[data-labelpos="above"] { flex-direction: column-reverse; }
.btn-cell[data-labelpos="none"] .cell-label { display: none; }
.btn-cell[data-labelpos="only"] .cell-img { display: none; }

/* folder affordance: a folded corner, not just colour (colour-blind safe) */
.btn-cell.is-folder::after {
  content: "›";
  position: absolute;
  top: 7px;
  right: 8px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, .55);
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1;
  opacity: .85;
}


.btn-cell.has-audio::before {
  content: "🔊";
  position: absolute;
  top: 3px; left: 5px;
  font-size: .7rem;
  opacity: .7;
}

.btn-cell.empty { background: transparent; border-style: dashed; box-shadow: none; cursor: default; opacity: .45; }
.btn-cell.hidden-cell { display: none; }
body.editing .btn-cell.hidden-cell { display: flex; opacity: .35; }
body.editing .btn-cell.empty { cursor: pointer; opacity: .8; }

/* The scanning highlight has to work on every kind of target: grid buttons,
   the Speak/Clear tools, and the word suggestions. */
.scan-on { outline: 6px solid var(--scan); outline-offset: -3px; z-index: 3; position: relative; }
.btn-cell.scan-on { box-shadow: 0 0 0 3px rgba(255, 149, 0, .35), var(--shadow); }
.tool.scan-on, .suggestion.scan-on { outline-offset: 1px; }

.btn-cell:focus-visible, .tool:focus-visible, .suggestion:focus-visible {
  outline: 4px solid var(--accent);
  outline-offset: 2px;
}

/* dwell progress ring */
.dwell-ring {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: conic-gradient(rgba(47,109,246,.45) var(--p, 0%), transparent 0);
}

/* edit-mode affordances */
body.editing .btn-cell { cursor: grab; }
body.editing .btn-cell::before { }
.btn-cell.drag-over { outline: 4px dashed var(--accent); outline-offset: -4px; }
.btn-cell.dragging { opacity: .35; }
#editbanner {
  display: none;
  gap: 8px;
  align-items: center;
  padding: 6px 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  flex: 0 0 auto;
  flex-wrap: wrap;
}
body.editing #editbanner { display: flex; }
#editbanner button {
  background: rgba(255,255,255,.18);
  border: 1px solid rgba(255,255,255,.5);
  color: inherit;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-weight: 700;
}

/* -------------------------------------------------------------- dedication */

/* The reason the whole thing exists. Given room to breathe rather than set as
   small print, because it is not a legal notice. */
.dedication {
  box-shadow: 0 4px 18px rgba(15, 25, 45, .06);
  padding: 20px 22px;
  margin-bottom: 20px;
  border-radius: 18px;
  border: 2px solid var(--line);
  background:
    radial-gradient(600px 200px at 0% 0%, rgba(46, 107, 255, .08), transparent 70%),
    var(--panel-2);
}
.dedication h3 {
  font-family: "Fredoka", "Nunito", system-ui, sans-serif;
  font-weight: 600;
  margin: 0 0 10px;
  font-size: 1.15rem;
  letter-spacing: .01em;
}
.dedication p { margin: 0 0 10px; max-width: 60ch; line-height: 1.6; }
.dedication p:last-child { margin-bottom: 0; }
.dedication .ask {
  font-weight: 800;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

/* ------------------------------------------------------------------- kiosk */

/* Locked: everything that leads out of the board goes away. The lock button
   stays, because a way out that only an adult can find is the point — a way out
   nobody can find is a child stuck in an app. */
body.kiosk #btn-edit,
body.kiosk #btn-settings,
body.kiosk #btn-history { display: none; }

body.kiosk #btn-lock { background: var(--ok); border-color: var(--ok); color: #fff; }
#btn-lock.holding {
  background: var(--scan);
  border-color: var(--scan);
  color: #16202c;
  transition: background 3s linear;
}

/* ----------------------------------------------------------------- dialog */

dialog {
  border: none;
  border-radius: 26px;
  padding: 0;
  background: var(--panel);
  color: var(--ink);
  max-width: min(960px, 96vw);
  width: 100%;
  max-height: 92vh;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
dialog::backdrop { background: rgba(8, 14, 22, .55); }
.dlg-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--panel); z-index: 2;
}
.dlg-head h2 { margin: 0; font-size: 1.15rem; flex: 1 1 auto; }
.dlg-body { padding: 16px; overflow: auto; max-height: calc(92vh - 130px); }
.dlg-foot {
  display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap;
  padding: 12px 16px; border-top: 1px solid var(--line);
  position: sticky; bottom: 0; background: var(--panel);
}

.btn {
  padding: 12px 18px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--panel-2);
  font-weight: 700;
  cursor: pointer;
}
.btn.primary {
  background: linear-gradient(145deg, var(--accent-2), var(--accent));
  border-color: transparent;
  color: var(--accent-ink);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 40%, transparent);
}
.btn.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn:active { transform: translateY(1px); }

.field { margin-bottom: 14px; }
.field > label { display: block; font-weight: 700; margin-bottom: 6px; font-size: .9rem; }
.field .hint { font-weight: 400; color: var(--ink-soft); font-size: .82rem; display: block; margin-top: 4px; }
.field input[type="text"], .field input[type="number"], .field input[type="password"],
.field select, .field textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  font: inherit;
}
.field input[type="range"] { width: 100%; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 200px; min-width: 0; }

.switchrow { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.switchrow:last-child { border-bottom: none; }
.switchrow .txt { flex: 1 1 auto; }
.switchrow .txt b { display: block; }
.switchrow .txt span { color: var(--ink-soft); font-size: .84rem; }
.switchrow input[type="checkbox"] { width: 26px; height: 26px; accent-color: var(--accent); flex: 0 0 auto; }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 8px 16px 0; }
.tabs button {
  padding: 9px 14px; border-radius: 10px 10px 0 0;
  border: 2px solid var(--line); border-bottom: none;
  background: var(--panel-2); cursor: pointer; font-weight: 700; white-space: nowrap;
}
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tabpanel[hidden] { display: none; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 46px; height: 46px; border-radius: 10px;
  border: 3px solid transparent; cursor: pointer;
}
.swatch[aria-pressed="true"] { border-color: var(--ink); }

.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; max-height: 260px; overflow: auto; }
.emoji-grid button { font-size: 1.7rem; padding: 6px; border-radius: 10px; border: 2px solid var(--line); background: var(--panel-2); cursor: pointer; }

.picto-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; max-height: 300px; overflow: auto; }
.picto-grid button { padding: 4px; border-radius: 10px; border: 2px solid var(--line); background: #fff; cursor: pointer; }
.picto-grid img { width: 100%; aspect-ratio: 1; object-fit: contain; }

.preview-cell {
  width: 140px; height: 140px; flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; border-radius: var(--radius); border: 2px solid rgba(0,0,0,.18);
  overflow: hidden; color: #16202c;
}
.preview-cell .cell-img { font-size: 3rem; }
.preview-cell .cell-label { font-size: 1rem; font-weight: 800; }

.list { display: flex; flex-direction: column; gap: 6px; }
.list-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 2px solid var(--line); border-radius: 12px;
  background: var(--panel-2);
}
.list-item .grow { flex: 1 1 auto; min-width: 0; }
.list-item .grow b { display: block; }
.list-item .grow span { color: var(--ink-soft); font-size: .84rem; }
.iconbtn {
  border: 2px solid var(--line); background: var(--panel); border-radius: 10px;
  width: 42px; height: 42px; cursor: pointer; font-size: 1.1rem; flex: 0 0 auto;
}

.keys { display: grid; gap: 6px; }
.keys .keyrow { display: flex; gap: 6px; justify-content: center; }
.key {
  flex: 1 1 0; min-width: 0; min-height: 58px;
  border-radius: 10px; border: 2px solid var(--line); background: var(--panel-2);
  font-size: calc(1.2rem * var(--label-scale)); font-weight: 700; cursor: pointer;
}
.key.wide { flex: 2 1 0; }
.key.xwide { flex: 5 1 0; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat { padding: 12px; border-radius: 12px; background: var(--panel-2); border: 2px solid var(--line); }
.stat b { display: block; font-size: 1.6rem; }
.stat span { color: var(--ink-soft); font-size: .84rem; }
.bar { height: 10px; border-radius: 6px; background: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: 12px 18px; border-radius: 999px; font-weight: 700;
  z-index: 99; box-shadow: var(--shadow); pointer-events: none;
  opacity: 0; transition: opacity .18s ease;
}
.toast.show { opacity: 1; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media print {
  #messagebar, #toolbar, #suggestions, #editbanner, .toast { display: none !important; }
  body { background: #fff; }
  #gridwrap { overflow: visible; }
  .btn-cell { box-shadow: none; break-inside: avoid; }
}

@media (max-width: 620px) {
  :root { --cell-min: 62px; }
  .tool { min-width: 54px; min-height: 62px; padding: 4px 6px; }
  #message { min-height: 62px; }
  .cell-label { -webkit-line-clamp: 3; }
}

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