/*
 * Boggle Buddy — sits on top of Bootstrap 5.
 *
 * The palette and the step/capture/footer shapes are carried over from
 * SetSolver so the two workshop apps read as siblings; Bootstrap supplies the
 * reset, the utility classes and the form controls underneath.
 */

:root {
  --bg: #0f1216;
  --surface: #191d23;
  --surface-2: #222831;
  --text: #eef1f5;
  --muted: #9aa4b2;
  --accent: #f59e0b;         /* amber — Boggle's wooden tray, vs SetSolver's blue */
  --accent-press: #d97706;
  --warn: #b45309;
  --ok: #22c55e;
  --border: #2c333d;
  --radius: 14px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
  /* An installed/standalone page owns the whole screen including the strip
     behind the notch. In a normal browser tab every inset resolves to 0. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Environment banner — teal local, amber staging, absent on production. */
.env-banner {
  text-align: center;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  padding: 4px;
}
.env-banner--local { background: #0f766e; color: #fff; }
.env-banner--staging { background: #b45309; color: #fff; }

.app-header {
  text-align: center;
  padding: 30px 16px 10px;
}

/* Two tones rather than two typefaces: "Boggle" carries the weight and
   "Buddy" recedes, which gives the lockup a shape without a webfont. */
.wordmark {
  margin: 0;
  font-size: 2.1rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--muted);
  line-height: 1.1;
}
.wordmark__accent { color: var(--text); }

.tagline {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  /* Wide tracking against the tight wordmark — the contrast is what makes the
     pair read as designed. */
  letter-spacing: 0.14em;
}

.app-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 16px 40px;
}

.step { animation: fade 0.25s ease; }

@keyframes fade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.step-title {
  font-size: 1.25rem;
  font-weight: 700;
  text-align: center;
  margin: 0 0 4px;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.hint code {
  color: var(--accent);
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 5px;
}

/* Capture */
.capture-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px 20px;
  margin: 24px 0 8px;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1.1rem;
  transition: border-color 0.15s, background 0.15s;
}
.capture-btn:active { background: var(--surface-2); border-color: var(--accent); }
.capture-btn__icon { font-size: 2.6rem; line-height: 1; color: var(--accent); }

.btn-manual {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
}
.btn-manual:hover { color: var(--text); }

/* Preview */
.preview-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border);
}
#preview {
  display: block;
  width: 100%;
  height: auto;
  max-height: 60vh;
  object-fit: contain;
}

/* Buttons — Bootstrap's .btn supplies the base; these are the two variants. */
.row-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}
.row-actions .btn {
  flex: 1;
  padding: 14px 16px;
  border-radius: var(--radius);
  font-weight: 600;
  border: none;
}
.btn-accent { background: var(--accent); color: #1a1206; }
.btn-accent:hover, .btn-accent:focus { background: var(--accent-press); color: #1a1206; }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-ghost:hover, .btn-ghost:focus { background: var(--border); color: var(--text); }
.btn:active { transform: scale(0.98); }

/* Spinner */
.spinner {
  width: 44px;
  height: 44px;
  margin: 40px auto 16px;
  border: 4px solid var(--surface-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Board grid — 4x4, square cells that stay square at any width. */
.board-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 16px auto;
  max-width: 380px;
}

.board-cell {
  aspect-ratio: 1;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  padding: 0;
  /* iOS zooms the page when a focused input's font-size is under 16px; these
     are well above that, so no viewport lock is needed. */
}
.board-cell:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.35);
}
.board-cell.is-flagged {
  border-color: var(--warn);
  box-shadow: 0 0 0 1px var(--warn) inset;
}
.board-cell.is-empty { background: var(--surface-2); }

.legend {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0;
}
.legend__swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  vertical-align: -1px;
  margin-right: 4px;
}
.legend__swatch--warn { border: 2px solid var(--warn); }

/* Results */
#results-summary {
  text-align: center;
  margin: 8px 0 20px;
}
.summary-badge {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 1.05rem;
}
.summary-badge.found {
  background: rgba(34, 197, 94, 0.15);
  color: var(--ok);
  border: 1px solid rgba(34, 197, 94, 0.4);
}
.summary-badge.none {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.4);
}
.summary-score {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.word-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}
.word-group__label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 8px;
}
.word-group__words {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.word-chip {
  background: var(--surface-2);
  border-radius: 7px;
  padding: 4px 9px;
  font-size: 0.95rem;
  text-transform: lowercase;
  font-variant-numeric: tabular-nums;
}
/* The long words are the ones worth playing — let them stand out. */
.word-chip--long { background: rgba(245, 158, 11, 0.16); color: #fcd34d; }

/* Full-width primary action (Review player words) */
.btn-wide {
  display: block;
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
  margin: 4px 0 16px;
}

/* ---- Player review ------------------------------------------------------ */

/* Segmented player-count control */
.seg {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 18px 0 4px;
}
.seg__btn {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.seg__btn.is-on {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1206;
}

.player-names {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 12px 0 4px;
}
.player-name,
.word-add .form-control {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 1rem;
}
.player-name:focus,
.word-add .form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.3);
  background: var(--surface);
  color: var(--text);
}

/* Mic */
.mic-wrap {
  text-align: center;
  margin: 8px 0 12px;
}
.btn-mic {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 12px 22px;
  font-weight: 600;
  font-size: 1rem;
}
.btn-mic .bi { color: var(--accent); }
.btn-mic.is-listening {
  background: var(--accent);
  color: #1a1206;
  border-color: var(--accent);
  animation: micpulse 1.2s ease-in-out infinite;
}
.btn-mic.is-listening .bi { color: #1a1206; }
@keyframes micpulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.5); }
  50%      { box-shadow: 0 0 0 10px rgba(245, 158, 11, 0); }
}
.mic-interim {
  min-height: 1.2em;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-style: italic;
}

/* Word-add row */
.word-add {
  display: flex;
  gap: 8px;
  margin: 4px 0 12px;
}
.word-add .form-control { flex: 1; }
.word-add .btn { padding: 12px 16px; border-radius: 10px; }

/* Collected-word chips (removable) */
.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}
.chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.95rem;
  cursor: pointer;
  text-transform: lowercase;
}
.chip__x { color: var(--muted); font-weight: 700; margin-left: 2px; }
.chip:active { background: var(--danger); border-color: var(--danger); }

/* Standings */
.pr-player {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
}
.pr-player__head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}
.pr-player__rank { color: var(--accent); font-weight: 700; font-size: 0.95rem; }
.pr-player__name { font-weight: 700; font-size: 1.05rem; flex: 1; }
.pr-player__pts {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ok);
}
.pr-player:first-child .pr-player__pts { font-size: 1.15rem; }

.word-chip__pts {
  color: var(--muted);
  font-size: 0.7rem;
  margin-left: 5px;
  vertical-align: super;
  font-variant-numeric: tabular-nums;
}
.word-chip--missed { opacity: 0.75; }

.pr-note {
  margin: 6px 0 0;
  font-size: 0.82rem;
  color: #d9b48c;
}
.pr-note.muted { color: var(--muted); }

.pr-section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--muted);
  margin: 20px 0 8px;
}
.pr-overlap {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.pr-overlap__word {
  font-weight: 600;
  text-transform: lowercase;
}
.pr-overlap__who {
  color: var(--muted);
  font-size: 0.8rem;
  text-align: right;
}

.pr-coverage {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 20px 0 6px;
}
.btn-reveal-missed {
  display: block;
  margin: 0 auto;
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
}
.btn-reveal-missed:hover { color: var(--text); }

/* Error banner */
.error-banner {
  margin-top: 16px;
  padding: 12px 14px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  border-radius: var(--radius);
  font-size: 0.9rem;
}

/* Footer */
.app-footer {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  text-align: center;
}
.app-footer__brand {
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: none;
  transition: color 0.15s;
}
.app-footer__brand strong { color: var(--text); font-weight: 600; }
.app-footer__brand:hover { color: var(--text); }
.app-footer__copy {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}
