:root {
  --letters: #000000;
  --keys: #FFFFFF;
  --page: #F6F5F0;
  --ink: #182B27;
  --green: #225C4F;
  --border: #D2D8D2;
  --gap: 4px;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: Roboto, "Segoe UI", system-ui, -apple-system, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: max(var(--gap), env(safe-area-inset-top)) max(var(--gap), env(safe-area-inset-right))
    max(var(--gap), env(safe-area-inset-bottom)) max(var(--gap), env(safe-area-inset-left));
}
button {
  font: inherit;
  color: var(--ink);
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: 12px;
  min-height: 48px;
  min-width: 48px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
button:disabled { opacity: 0.4; cursor: default; }
button:not(:disabled):active { filter: brightness(0.92); }
button:focus-visible, textarea:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--green); outline-offset: 2px; }
button svg, a.option svg { width: 24px; height: 24px; stroke: var(--green); stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; flex: none; }

/* Message line: grows to three lines, then scrolls. */
.top { display: flex; gap: var(--gap); align-items: stretch; }
.line { position: relative; flex: 1; display: flex; min-width: 0; }
#message {
  flex: 1;
  min-width: 0;
  resize: none;
  min-height: 56px;
  max-height: calc(3 * 1.3em + 16px);
  padding: 8px 52px 8px 12px;
  font: inherit;
  font-size: clamp(20px, 3.2vmin, 32px);
  line-height: 1.3;
  color: var(--ink);
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow-y: auto;
}
#message::placeholder { color: #555; }
.inline { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); border: 0; background: transparent; }
.icon { width: 48px; flex: none; display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.top .icon { min-height: 56px; }

/* Board: rows share the height; keys share each row; a shorter row is centred with spacers. */
#board { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 2px; }
#board .row { flex: 1; min-height: 0; display: flex; gap: 2px; }
#board .spacer { flex-basis: 0; }
.key {
  flex: 1 1 0;
  min-width: 0; min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: var(--keys);
  color: var(--letters);
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
  overflow: hidden;
}
.key span { display: inline-block; white-space: nowrap; }
.key.on { background: var(--letters); color: var(--keys); }   /* ⇧ capitals on, ~ waiting */
.empty { visibility: hidden; }

.controls { display: grid; grid-template-columns: 1fr 1fr 2fr 1fr 1fr 1fr; gap: var(--gap); }
.controls button { height: 52px; width: auto; min-width: 0; }
.controls .mark { font-size: 30px; font-weight: 700; line-height: 1; }

/* Dialogs */
dialog {
  border: 0; border-radius: 16px; padding: 0;
  width: min(600px, 94vw); max-height: 90dvh;
  color: var(--ink); background: #FFFFFF;
}
dialog::backdrop { background: rgb(0 0 0 / 0.55); }
#sheet { display: flex; flex-direction: column; max-height: 90dvh; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 12px 8px 4px 24px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 20px; }
.sheet-head button { border: 0; background: transparent; }
.sheet-body { overflow-y: auto; padding: 8px 16px; display: flex; flex-direction: column; gap: 8px; }
.sheet-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 8px 16px 16px; }
.sheet-body p { margin: 0; }
.sheet-body > * { flex-shrink: 0; }   /* the dialog scrolls instead of squashing its contents */
.text-button { padding: 8px 14px; }
.option { display: flex; align-items: center; gap: 12px; text-align: left; padding: 10px 14px; min-height: 64px; }
.option small { display: block; color: #444; font-size: 13px; margin-top: 2px; }
.option strong { font-size: 18px; }
a.option { color: var(--ink); text-decoration: none; background: #FFF; border: 1px solid var(--border); border-radius: 12px; }
.details { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 14px; padding: 10px 12px; background: #F4F6F4; border-radius: 10px; }
.details dt { font-weight: 600; }
.details dd { margin: 0; overflow-wrap: anywhere; }
.address { font-size: 14px; align-self: center; flex: 2; overflow-wrap: anywhere; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.phrase { display: flex; gap: 6px; align-items: stretch; }
.phrase .text { flex: 1; text-align: left; padding: 8px 12px; font-size: 18px; min-height: 56px; min-width: 0; overflow-wrap: anywhere; }
.phrase .text.plain { border: 1px solid var(--border); border-radius: 12px; display: flex; align-items: center; }
.choice { text-align: left; padding: 10px 14px; }
.choice[aria-pressed="true"] { outline: 3px solid var(--green); }
.big { font-size: clamp(32px, 8vmin, 72px); font-weight: 700; margin: 16px 8px; overflow-wrap: anywhere; }
.note { font-size: 14px; color: #444; }
.center { text-align: center; }
.error { color: #A3261A; font-size: 14px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
label.check { display: flex; align-items: center; gap: 10px; min-height: 48px; }
label.check input { width: 24px; height: 24px; flex: none; }
select, input[type="text"], textarea.edit {
  font: inherit; font-size: 18px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; color: var(--ink); background: #FFF; width: 100%;
}

/* Answer check */
.mark { font-size: 120px; font-weight: 700; text-align: center; line-height: 1.1; }
.checked { font-size: 24px; text-align: center; overflow-wrap: anywhere; }

/* Arrangement editor */
.editor-scroll { overflow-x: auto; padding: 2px; }
.editor-grid { display: grid; gap: 4px; width: max-content; }
.cell { width: 54px; height: 58px; min-width: 0; font-size: 26px; padding: 0; color: var(--letters); background: var(--keys); border-radius: 8px; touch-action: none; }
.cell.selected { outline: 3px solid var(--ink); }
.cell.fixed { opacity: 0.5; }
.palette { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; border: 1px dashed var(--border); border-radius: 10px; }
.ghost { position: fixed; z-index: 20; pointer-events: none; transform: translate(-50%, -50%); font-size: 32px; font-weight: 700;
  background: #FFF; border: 2px solid var(--green); border-radius: 8px; padding: 6px 12px; }

/* Colours */
.colour-row { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.colour-row input[type="color"] { width: 52px; height: 48px; padding: 2px; border: 1px solid var(--border); border-radius: 10px; background: #FFF; flex: none; }
.colour-row input[type="text"] { flex: 1; min-width: 0; }
.colour-row .text-button { flex: none; }
.preview { padding: 12px; border-radius: 12px; border: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.preview-keys { font-size: 32px; font-weight: 700; padding: 6px 12px; border-radius: 8px; white-space: pre; }
.chip { width: 48px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700; border-radius: 8px; border: 4px solid; }

#toast { position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%); background: #182B27; color: #FFF;
  padding: 12px 18px; border-radius: 10px; max-width: 90vw; font-size: 16px; z-index: 30; }
