* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0d0f1a;
  --panel: #171a2b;
  --border: #2e3350;
  --accent: #ffcc4d;
  --accent2: #6ee7ff;
  --text: #e8eaf6;
  --dim: #8b90b3;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  display: flex;
  justify-content: center;
  min-height: 100vh;
}

#app {
  width: 400px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0;
  position: relative;
}

/* ---------- Banner ---------- */
#banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  min-height: 84px;
}

#banner .label {
  display: block;
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--dim);
  margin-bottom: 4px;
}

#next-canvas { display: block; }

#last-word-panel { text-align: right; }

#last-word {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 2px;
}

/* ---------- Field ---------- */
#field-wrap {
  display: flex;
  justify-content: center;
}

#board-canvas {
  border: 2px solid var(--border);
  border-radius: 4px;
  background: #090b12;
  max-width: 100%;       /* scale down to fit narrow screens, keep aspect ratio */
  height: auto;
}

/* ---------- Touch controls (on-screen buttons) ---------- */
#touch-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#touch-controls.hidden { display: none; }

.tc-row { display: flex; gap: 8px; }

.tc-btn {
  flex: 1;
  min-height: 54px;
  background: var(--panel);
  color: var(--accent);
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
  touch-action: none;                       /* control taps never scroll/zoom the page */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.tc-btn:active {
  background: var(--accent);
  color: #1a1a1a;
  border-color: var(--accent);
}

.tc-wide {
  width: 100%;
  min-height: 48px;
  font-size: 15px;
  letter-spacing: 3px;
}

/* ---------- HUD ---------- */
#hud {
  display: flex;
  justify-content: space-between;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 16px;
  font-weight: 700;
}

#timer { color: var(--accent2); }
#score { color: var(--accent); }
#timer.low { color: #ff5a6e; }

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(9, 11, 18, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.overlay.hidden { display: none; }

.panel {
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 20px 20px;
  width: 340px;
  text-align: center;
}

.panel h1 {
  font-size: 22px;
  letter-spacing: 3px;
  color: var(--accent);
  margin-bottom: 6px;
}

.tagline {
  font-size: 12px;
  color: var(--dim);
  margin-bottom: 14px;
}

.config-row {
  margin-bottom: 10px;
  text-align: left;
}

.config-row label {
  display: block;
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--dim);
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* two shaded boxes side by side, each grouping a column of settings */
.config-cols {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.config-col {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  padding: 9px;
}

.config-col .config-row { margin-bottom: 8px; }
.config-col .config-row:last-child { margin-bottom: 0; }

.btn-group { display: flex; gap: 6px; }

.btn-group button {
  flex: 1;
  padding: 8px 0;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.btn-group button.selected {
  background: var(--accent);
  color: #1a1a1a;
  border-color: var(--accent);
  font-weight: 700;
}

#timer-input {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: "Consolas", monospace;
  font-size: 16px;
  text-align: center;
}

/* timer +/- 1 minute stepper */
.timer-stepper {
  display: flex;
  align-items: stretch;
  gap: 4px;
}

.timer-stepper #timer-input {
  flex: 1;
  min-width: 0;
  padding: 8px 2px;
  font-size: 15px;
}

.step-btn {
  flex: none;
  width: 26px;
  background: var(--bg);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.step-btn:active {
  background: var(--accent);
  color: #1a1a1a;
  border-color: var(--accent);
}

.controls-help {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 12px;
  font-size: 11px;
  color: var(--dim);
  margin: 12px 0;
  text-align: left;
}

.big-btn {
  width: 100%;
  padding: 12px 0;
  background: var(--accent);
  color: #1a1a1a;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 2px;
  cursor: pointer;
}

.big-btn:hover { filter: brightness(1.1); }

#start-btn { background: #22c55e; }   /* green "go" button */

.final-score {
  font-family: "Consolas", monospace;
  font-size: 18px;
  margin: 12px 0 4px;
  color: var(--accent2);
}

.penalty-note {
  font-size: 12px;
  color: #ff5a6e;
  margin-bottom: 12px;
}

.penalty-note.hidden { display: none; }

#word-log-final {
  max-height: 140px;
  overflow-y: auto;
  font-size: 13px;
  color: var(--dim);
  margin-bottom: 16px;
}

#word-log-final .w { color: var(--accent); font-weight: 700; }

/* ---------- Responsive / mobile ---------- */
@media (max-width: 420px) {
  #app {
    width: 100vw;
    padding: 6px 8px;
    gap: 6px;
    min-height: 100dvh;
  }
  #banner { min-height: 60px; padding: 6px 10px; }
  /* shrink the board so banner + HUD + controls all fit without page scroll */
  #board-canvas { max-height: calc(100dvh - 278px); width: auto; }
  #hud { padding: 8px 12px; font-size: 14px; }
  .tc-btn { min-height: 48px; font-size: 20px; }
  .panel { width: 92vw; max-width: 340px; padding: 22px 18px; }
}
