/* Say - styles. High-contrast, large-target, theme-aware. */

:root {
  --bg: #0b0b0c;
  --surface: #17171a;
  --surface-2: #202026;
  --text: #f2f2f4;
  --muted: #a6a6ad;
  --line: #33333b;
  --accent: #ffd23f;      /* scan highlight - vivid, high contrast on dark */
  --accent-ink: #1a1500;
  --primary: #4da3ff;
  --danger: #ff6b6b;
  --ok: #6ee7a8;
  --radius: 16px;
  --tap: 15px;            /* base tap padding, scales with --scale */
  --scale: 1.15;          /* text-size multiplier, set by JS */
}

:root.light {
  --bg: #f4f4f6;
  --surface: #ffffff;
  --surface-2: #ececef;
  --text: #16161a;
  --muted: #5a5a63;
  --line: #d7d7dd;
  --accent: #ffb300;
  --accent-ink: #201700;
  --primary: #0b62c4;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;   /* scan glows/outlines never cause a sideways scroll */
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.skip {
  position: absolute;
  left: -999px;
}
.skip:focus {
  left: 12px;
  top: 12px;
  z-index: 10;
  background: var(--primary);
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  font-weight: 800;
  color: var(--accent);
  font-size: 1.4rem;
  letter-spacing: -2px;
}
.brand h1 { font-size: 1.35rem; margin: 0; font-weight: 700; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.chip {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  min-height: 44px;
}
.chip:hover { border-color: var(--muted); }
.chip.primary { background: var(--primary); color: #fff; border-color: transparent; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.chip strong { font-weight: 800; }

/* Utterance bar */
.utterance {
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.utterance-text {
  margin: 0;
  min-height: calc(1.4em * var(--scale));
  font-size: calc(1.5rem * var(--scale));
  line-height: 1.35;
  font-weight: 600;
  word-break: break-word;
}
.utterance-text:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  font-weight: 400;
}

/* Board */
.board {
  flex: 1;
  padding: 12px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  outline: none;
}
.row {
  display: grid;
  gap: 8px;
}

.key {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  min-width: 0;                        /* let 1fr columns shrink instead of overflowing */
  min-height: calc(56px * var(--scale));
  padding: calc(var(--tap) * 0.7) 10px;
  background: var(--surface-2);
  color: var(--text);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: calc(1.15rem * var(--scale));
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: transform .05s ease;
}
.key:hover { border-color: var(--muted); }
.key:active { transform: scale(.98); }

.key.action { background: var(--surface); }
.key.speak { background: var(--ok); color: #05270f; border-color: transparent; font-weight: 800; }
.key.danger { color: var(--danger); }
.key.wide { grid-column: 1 / -1; }
.key.pred { background: var(--surface); color: var(--primary); font-weight: 700; font-style: normal; }
.key.pred.empty { color: var(--muted); font-weight: 500; cursor: default; }
.key.phrase { min-height: calc(72px * var(--scale)); font-size: calc(1.2rem * var(--scale)); }
/* Single-letter keys: tight horizontal padding so a full 10-key row fits a phone */
.key.char { padding-left: 4px; padding-right: 4px; }

/* Scanning highlight - deliberately loud so it is unmissable */
body.scanning .key { cursor: default; }
.key.scan-row-active {
  border-color: var(--accent);
}
.key.scan-active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent);
  transform: scale(1.03);
  z-index: 1;
}
.row.scan-row-active {
  outline: 3px dashed var(--accent);
  outline-offset: 4px;
  border-radius: var(--radius);
}

.switch-hint {
  margin: 0;
  padding: 10px 16px 4px;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
}

.footer {
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.footer p { margin: 0; }
.linkish {
  background: none;
  border: none;
  color: var(--primary);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  padding: 6px;
}

/* Dialogs / sheets */
.sheet {
  border: none;
  border-radius: 20px;
  padding: 0;
  width: min(560px, 94vw);
  max-height: 90dvh;
  background: var(--surface);
  color: var(--text);
}
.sheet::backdrop { background: rgba(0,0,0,.55); }
.sheet-inner { padding: 20px; display: flex; flex-direction: column; gap: 16px; overflow: auto; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-head h2 { margin: 0; font-size: 1.3rem; }
.sheet-buttons { display: flex; gap: 10px; justify-content: flex-end; }

.field { display: flex; flex-direction: column; gap: 8px; font-size: 1.05rem; }
.field.checkbox { flex-direction: row; align-items: center; gap: 12px; }
.field select, .field input[type="range"], textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}
.field input[type="range"] { padding: 0; accent-color: var(--primary); height: 40px; }
.field input[type="checkbox"] { width: 26px; height: 26px; accent-color: var(--primary); }
.btn-wide {
  font: inherit; font-size: 1.05rem;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; cursor: pointer; min-height: 50px;
}
textarea { width: 100%; resize: vertical; line-height: 1.5; }
.muted { color: var(--muted); margin: 0; }
.sheet p { line-height: 1.5; }

@media (prefers-reduced-motion: reduce) {
  .key, .key.scan-active { transition: none; transform: none; }
}

/* Wider screens: give the keyboard more breathing room */
@media (min-width: 720px) {
  .board { max-width: 900px; margin: 0 auto; width: 100%; }
}
