:root {
  --bg: #1f2430;
  --surface: #2b3245;
  --surface-2: #39415a;
  --text: #f2f4f8;
  --text-dim: #b8bfce;
  --accent: #6aa9ff;
  --danger: #e05d5d;
  --tile-bg: #ffffff;
  --tile-text: #1a1d24;
  --radius: 14px;
}

/* touch-action isn't reliably honored from ancestors on iOS Safari — it must
   sit on the tapped element itself, so the double-tap-zoom kill goes on every
   element (nav-bar text was still zooming with it only on html/body).
   Pinch zoom still works. */
* {
  box-sizing: border-box;
  touch-action: manipulation;
}

/* CSS display rules must never defeat the hidden attribute. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  /* The document never scrolls — #board is the only scroll container. This
     is what actually disables Safari's pull-to-refresh; overscroll-behavior
     alone doesn't stop it when the page itself can rubber-band. */
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  overscroll-behavior: none;
}

/* ---------- Sentence strip ---------- */

#strip-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 56px 8px 8px; /* right gutter keeps the corner logo off the ✕ */
  background: var(--surface);
  min-height: 64px;
}

#strip-chips {
  flex: 1;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  min-height: 48px;
  align-items: center;
}

.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--tile-bg);
  color: var(--tile-text);
  border: none;
  border-radius: 10px;
  padding: 4px 10px;
  font-size: 1rem;
  flex-shrink: 0;
  min-height: 44px;
}

.chip img {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 6px;
}

.strip-controls { display: flex; gap: 6px; }

.strip-btn {
  min-width: 56px;
  min-height: 48px;
  border: none;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.05rem;
}

#strip-speak { background: var(--accent); color: #10131a; font-weight: 600; }

/* ---------- Nav (board picker) ---------- */

#nav-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 56px 6px 8px; /* right gutter keeps the corner logo clear */
  /* Tall enough to contain the fixed corner ⌗ (top 6px + 50px) even when
     the Boards button is hidden and only the title holds the row open. */
  min-height: 56px;
  box-sizing: border-box;
  background: var(--surface);
}

#nav-home {
  min-height: 44px;
  padding: 0 14px;
  border: none;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.05rem;
}

/* Stacks the small "Board" eyebrow above the board name. On the picker
   view the eyebrow is hidden and the lone title centers itself. */
#nav-board-group {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

#nav-title {
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Check screen (Yes / No / Not sure) ---------- */

#nav-label {
  color: var(--text-dim);
  font-size: 0.7rem;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#check-btn {
  margin-left: auto; /* right-aligned in the bar, before the ⌗ gutter */
  margin-right: 10px;
  min-height: 44px;
  padding: 0 14px;
  border: none;
  border-radius: 22px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 0.95rem;
}

#check-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 20;
  display: flex;
}

#check-close {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.2rem;
  z-index: 1;
}

.check-options {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(240px, 80vw), 1fr));
  gap: 12px;
  padding: 64px 12px 12px;
}

.check-opt {
  border: none;
  border-radius: var(--radius);
  color: var(--tile-text);
  font-size: clamp(1.6rem, 7vmin, 3.2rem);
  font-weight: 700;
  min-height: 0;
}

.check-yes { background: #ccff90; }
.check-notsure { background: #fff475; }
.check-no { background: #f28b82; }

.check-opt.chosen { outline: 6px solid var(--accent); outline-offset: -6px; }
.check-opt.dimmed { opacity: 0.35; }

/* ---------- Board ---------- */

#board {
  flex: 1;
  display: grid;
  gap: 10px;
  padding: 10px;
  min-height: 0;
  /* Sole scroll container (see html/body) — matters when the board picker
     has more boards than fit on screen. contain stops scroll chaining to
     the document, which would re-trigger pull-to-refresh. */
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  border: none;
  border-radius: var(--radius);
  background: var(--tile-bg);
  color: var(--tile-text);
  padding: 8px;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  min-height: 0;
  min-width: 0;
}

.tile img {
  flex: 1;
  width: 100%;
  min-height: 0;
  object-fit: cover;
  border-radius: calc(var(--radius) - 6px);
  pointer-events: none;
}

.tile .tile-label {
  padding-top: 6px;
  font-size: clamp(1rem, 3.5vmin, 1.6rem);
  font-weight: 600;
  text-align: center;
  overflow-wrap: anywhere;
  pointer-events: none;
}

.tile.text-only .tile-label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.2rem, 6vmin, 2.6rem);
}

/* Picker (board list) tiles are folders, not speak buttons — the kicker
   names the layer so a lone board can't pass for one giant button. */
.board-kicker {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: center;
  opacity: 0.6;
  padding-top: 4px;
  pointer-events: none;
}

#board.picker .tile.text-only .tile-label {
  font-size: clamp(1.1rem, 4.5vmin, 1.8rem);
}

.tile:active { filter: brightness(0.92); }

/* Hold-to-activate progress: a fill that rises for --hold-ms while pressed. */
.tile .hold-fill {
  position: absolute;
  inset: auto 0 0 0;
  height: 0%;
  background: rgba(106, 169, 255, 0.35);
  pointer-events: none;
}

.tile.holding .hold-fill {
  height: 100%;
  transition: height var(--hold-ms, 0ms) linear;
}

/* ---------- Edit mode ---------- */

#corner-logo {
  position: fixed;
  top: 6px;
  right: 6px;
  width: 50px;
  height: 50px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-dim);
  /* Deliberately prominent while field testing so testers can find edit
     mode; dial back toward 0.45 / 40px for release. */
  opacity: 0.72;
  font-size: 1.65rem;
}

#edit-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
}

#edit-toolbar button {
  min-height: 44px;
  padding: 0 16px;
  border: none;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
}

.edit-badge {
  background: var(--accent);
  color: #10131a;
  font-weight: 700;
  border-radius: 8px;
  padding: 4px 10px;
  margin-right: auto;
}

body.editing .tile.hidden-btn { opacity: 0.4; }

/* Dragging needs every move event — stop the browser claiming them for pan. */
body.editing .tile { touch-action: none; }

.tile.dragging {
  z-index: 10;
  opacity: 0.85;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  cursor: grabbing;
}

.tile.drop-target { outline: 4px dashed var(--accent); outline-offset: -4px; }

.tile-controls {
  display: flex;
  gap: 4px;
  padding-top: 4px;
}

.tile-controls .hide-toggle {
  flex: 1;
  min-height: 40px;
  border: none;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
}

.tile.add-tile {
  background: transparent;
  border: 2px dashed var(--text-dim);
  color: var(--text-dim);
  align-items: center;
  justify-content: center;
  font-size: 2rem;
}

/* ---------- Dialogs ---------- */

dialog {
  border: none;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  width: min(440px, 92vw);
  max-height: 90dvh;
  padding: 20px;
}

dialog::backdrop { background: rgba(0, 0, 0, 0.55); }

dialog h2 { margin: 0 0 12px; font-size: 1.2rem; }

dialog form { overflow-y: auto; }

dialog input[type="text"], dialog input[type="number"],
dialog select, #pin-input, #confirm-word {
  width: 100%;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--surface-2);
  background: var(--bg);
  color: var(--text);
  font-size: 1.1rem;
  padding: 6px 10px;
}

dialog input[type="number"] { width: 80px; }

#pin-input {
  font-size: 1.8rem;
  letter-spacing: 0.5em;
  text-align: center;
}

.field { display: block; margin: 12px 0; }
.field input { margin-top: 4px; }

fieldset.field { border: 1px solid var(--surface-2); border-radius: 8px; }

.row { display: block; margin: 12px 0; }
.row.indent { margin-left: 24px; display: flex; gap: 16px; }
.btn-col { display: flex; flex-direction: column; gap: 8px; }

.dlg-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
  margin-top: 16px;
}

.dlg-actions button, .btn-col button, .file-btn, #editor-remove-photo {
  min-height: 44px;
  padding: 0 16px;
  border: none;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button.primary { background: var(--accent); color: #10131a; font-weight: 600; }
button.danger { background: var(--danger); color: #fff; }
.link-btn {
  background: none !important;
  color: var(--accent);
  text-decoration: underline;
  margin-right: auto;
  padding: 0;
}

.dlg-hint { color: var(--text-dim); margin: 0 0 10px; }
.dlg-error { color: #ff9c9c; margin: 8px 0 0; }

.editor-photo-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }

.preview-tile {
  width: 140px;
  height: 140px;
  margin: 0 auto;
}

#editor-swatches { display: flex; gap: 8px; flex-wrap: wrap; padding: 8px; }

.swatch {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid transparent;
  padding: 0;
}

.swatch.selected { border-color: var(--text); }

.swatch.none {
  background: var(--tile-bg);
  color: var(--tile-text);
  font-size: 0.75rem;
}

.section-label {
  color: var(--text-dim);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 4px;
}

/* ---------- Library picker ---------- */

#library-list { display: flex; flex-direction: column; gap: 4px; }
#library-list .section-label { margin: 14px 0 4px; }

.library-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 6px 10px;
  border: none;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  text-align: left;
}

.library-item img, .library-dot {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: cover;
  flex: none;
}

.library-dot { background: var(--tile-bg); }

.library-text { display: flex; flex-direction: column; overflow: hidden; }
.library-label { font-weight: 600; }

.library-spoken {
  color: var(--text-dim);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.about-note {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-top: 16px;
}

.about-note.warning { color: var(--danger); }
.about-note a { color: var(--accent); }

hr { border: none; border-top: 1px solid var(--surface-2); margin: 14px 0; }
