* { 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;
  position: relative;          /* anchor for the pause overlay */
}

#pause-overlay {
  position: absolute;
  inset: 0;
  background: rgba(9, 11, 18, 0.96);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  color: var(--accent);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 3px;
  z-index: 5;
}

#resume-game-btn,
#exit-game-btn {
  border: none;
  border-radius: 8px;
  padding: 12px 30px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #1a1a1a;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#resume-game-btn { background: #22c55e; }   /* green: continue playing */

#exit-game-btn {
  background: #ff5a6e;
  position: absolute;                        /* pinned to the bottom of the board */
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
}

#resume-game-btn:active,
#exit-game-btn:active { filter: brightness(1.15); }

#pause-overlay.hidden { display: none; }

/* Pre-game 3-2-1 countdown, centred over the board in the teal timer colour */
#countdown-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;                    /* purely visual; never intercepts taps */
  background: rgba(9, 11, 18, 0.45);
  border-radius: 4px;
}
#countdown-overlay.hidden { display: none; }
#countdown-num {
  font-size: 150px;
  font-weight: 800;
  line-height: 1;
  color: var(--accent2);                   /* same teal as #timer */
  text-shadow: 0 0 28px rgba(110, 231, 255, 0.65), 0 4px 10px rgba(0, 0, 0, 0.5);
}
#countdown-num.pop { animation: countdown-pop 0.7s ease-out; }
@keyframes countdown-pop {
  0%   { transform: scale(0.4);  opacity: 0; }
  30%  { transform: scale(1.15); opacity: 1; }
  45%  { transform: scale(1);    opacity: 1; }
  100% { transform: scale(1);    opacity: 1; }
}

#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;
  margin-top: 6px;   /* breathing room below the move/rotate row */
}

/* ---------- Select Game page ---------- */
.panel.select-panel {        /* .panel.select-panel outweighs the mobile .panel override */
  position: relative;
  min-height: 480px;
  padding: 26px 20px 112px;   /* bottom padding reserves the gear's corner */
}

#avatar-bubble {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
}

#signout-btn {
  position: absolute;
  top: 63px;                 /* tucked just under the 46px avatar bubble */
  right: 14px;
  background: none;
  border: none;
  color: var(--dim);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  padding: 2px 3px;
}
#signout-btn:hover { color: var(--accent2); text-decoration: underline; }

#welcome-msg {
  font-size: 19px;
  letter-spacing: 1px;
  color: var(--accent);
  margin: 44px 0 6px;
}

.choose-label {
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 14px;
}

.format-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.format-btn {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--bg);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.format-btn:hover { border-color: var(--accent2); }
.format-btn:active { border-color: var(--accent); background: rgba(255, 204, 77, 0.08); }

.fmt-icon { font-size: 42px; line-height: 1; }

/* disabled format tile with a Coming Soon badge */
.format-btn { position: relative; }

.format-btn.format-disabled {
  color: rgba(139, 144, 179, 0.5);
  border-color: rgba(46, 51, 80, 0.7);
  cursor: default;
}

.format-btn.format-disabled:hover,
.format-btn.format-disabled:active {
  border-color: rgba(46, 51, 80, 0.7);
  background: var(--bg);
}

.format-btn.format-disabled .fmt-icon {
  filter: grayscale(1);
  opacity: 0.35;
}

.coming-soon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-8deg);
  background: var(--accent);
  color: #1a1a1a;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 4px 10px;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  pointer-events: none;
}

.archives-row { font-size: 12px; color: var(--dim); margin-bottom: 12px; }
.archives-row a { color: var(--accent2); }

#settings-gear {
  position: absolute;
  right: 16px;
  bottom: 12px;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 44px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  -webkit-tap-highlight-color: transparent;
}

#settings-gear span {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--dim);
}

#settings-gear:active { color: var(--accent2); }

/* Admin person icon: mirrors the settings gear, bottom-left of the select panel */
#admin-gear {
  position: absolute;
  left: 16px;
  bottom: 12px;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  -webkit-tap-highlight-color: transparent;
}
#admin-gear span {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--dim);
}
#admin-gear:active { color: var(--accent2); }
#admin-gear.hidden { display: none; }   /* only admins (email allowlist) see this */

/* Administrator panel: sections and options */
.admin-section { text-align: left; margin-bottom: 16px; }
.admin-heading {
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 7px;
}
.admin-option {
  display: block;
  width: 100%;
  text-align: left;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.admin-option:hover { border-color: var(--accent2); }
.admin-option:active { background: rgba(255, 255, 255, 0.06); }
.admin-note { font-size: 11px; color: var(--dim); margin-top: 5px; }
.admin-note.hidden { display: none; }

/* Game Admin: card wrapping the recent-games table */
.admin-card {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
  text-align: left;
}
.admin-card-title {
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--accent);
  margin-bottom: 10px;
}
#recent-games-body { max-height: 300px; overflow-y: auto; font-size: 13px; }
#recent-games-body table { width: 100%; border-collapse: collapse; }
#recent-games-body th {
  text-align: left;
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--dim);
  padding: 4px 2px;
  border-bottom: 1px solid var(--border);
}
#recent-games-body td {
  padding: 4px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
#recent-games-body .rg-seed { font-family: "Consolas", monospace; color: var(--accent2); }

/* ---------- Splash / sign-in ---------- */
.splash-art {
  display: block;
  width: 100%;
  border-radius: 12px;
  margin-bottom: 14px;
}

.logo-cross {
  display: grid;
  grid-template-columns: repeat(5, 36px);
  grid-auto-rows: 36px;
  gap: 3px;
  justify-content: center;
  margin-bottom: 12px;
}

.lt {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.35);
  font-size: 19px;
  font-weight: 800;
  color: #1a1a1a;
}

.lt i {
  position: absolute;
  right: 3px;
  bottom: 1px;
  font-style: normal;
  font-size: 8px;
  font-weight: 600;
}

.c-y { background: #f4d35e; }   /* WORDS  */
.c-g { background: #90be6d; }   /* STICKY */
.c-o { background: #ee964b; }   /* shared S */

.google-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #ffffff;
  color: #1f1f1f;
  border: none;
  border-radius: 8px;
  padding: 11px 0;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.google-btn:hover { filter: brightness(0.95); }
.google-btn svg { width: 20px; height: 20px; }

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--dim);
  font-size: 11px;
  margin: 12px 0;
}

.divider::before,
.divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.splash-panel input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

.auth-error {
  color: #ff5a6e;
  font-size: 12px;
  margin-top: 8px;
  text-align: center;
}
.auth-error.hidden { display: none; }
.auth-error.info { color: #4ade80; }   /* positive confirmation (e.g. reset email sent) */

.auth-toggle {
  font-size: 12px;
  color: var(--dim);
  text-align: center;
  margin-top: 10px;
}
.auth-toggle a { color: var(--accent2); text-decoration: none; }
.auth-toggle a:hover { text-decoration: underline; }
.auth-forgot { margin-top: 4px; }
.auth-forgot.hidden { display: none; }

/* Sign-in loading state: the active button spins, both lock out */
#google-btn:disabled, #email-signin-btn:disabled { opacity: 0.7; cursor: default; }
.btn-loading { pointer-events: none; }
.btn-loading::before {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 8px;
  vertical-align: -2px;
  border: 2px solid currentColor;      /* matches each button's text colour */
  border-top-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }

.demo-note {
  font-size: 10px;
  color: var(--dim);
  margin-top: 10px;
}

/* ---------- 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; }

#pause-btn {
  background: var(--bg);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 24px;          /* doubled from the original 2px 10px / 12px font */
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

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

/* Stickee Help button in the banner, between Next Block and Last Word */
#auto-btn {
  background: var(--bg);
  color: #4ade80;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

#auto-btn:active { background: #4ade80; color: #1a1a1a; }

#auto-btn.reload {
  color: var(--accent);              /* gold: budget empty, press to refill */
  border-color: var(--accent);
}

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

/* ---------- 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); }

#save-settings-btn,
#restart-btn,
#email-signin-btn { background: #22c55e; }   /* green "go" buttons */

.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; }

.seed-note {
  font-family: "Consolas", monospace;
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--dim);
  margin-bottom: 8px;
}

#word-log-final {
  max-height: 270px;          /* ~15 rows at 18px each */
  overflow-y: auto;
  font-size: 13px;
  color: var(--dim);
  margin-bottom: 16px;
  text-align: left;
}

#word-log-final table {
  width: 100%;
  border-collapse: collapse;
  border: none;
}

#word-log-final td {
  border: none;
  padding: 1px 0;
  line-height: 16px;
  text-align: left;           /* both columns left justified */
}

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

/* words cleared in the same solve chain share a colour; the palette rotates
   so neighbouring groups always stand out from each other */
#word-log-final tr.g0 td.w { color: #4ade80; }   /* green  */
#word-log-final tr.g1 td.w { color: #c084fc; }   /* purple */
#word-log-final tr.g2 td.w { color: #fde047; }   /* yellow */

/* left bracket spanning words completed by the same block-solve */
#word-log-final td.bracket { width: 9px; padding: 0; }
#word-log-final td.br-top { border-left: 2px solid; border-top: 2px solid; }
#word-log-final td.br-mid { border-left: 2px solid; }
#word-log-final td.br-bot { border-left: 2px solid; border-bottom: 2px solid; }
#word-log-final tr.g0 td.bracket { border-color: #4ade80; }
#word-log-final tr.g1 td.bracket { border-color: #c084fc; }
#word-log-final tr.g2 td.bracket { border-color: #fde047; }

.assist-note {
  font-size: 10px;
  letter-spacing: 1px;
  color: #ffd700;
  margin-bottom: 6px;
}

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

#assist-mark { vertical-align: -3px; margin-left: 4px; }
#assist-mark.hidden { display: none; }

/* ---------- Leaderboard ---------- */
#leaderboard-body {
  max-height: 300px;
  overflow-y: auto;
  margin-bottom: 16px;
  font-size: 13px;
  text-align: left;
}

#leaderboard-body table { width: 100%; border-collapse: collapse; }

#leaderboard-body td {
  border: none;
  padding: 4px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

#leaderboard-body .lb-rank { width: 12%; color: var(--dim); }
#leaderboard-body .lb-score {
  width: 28%;
  font-family: "Consolas", monospace;
  font-weight: 700;
  color: var(--accent);
}
#leaderboard-body .lb-date { color: var(--dim); text-align: right; }

.lb-empty { color: var(--dim); font-size: 13px; line-height: 1.6; text-align: center; }

.lb-reset {
  background: #ff5a6e;   /* destructive action: red, distinct from BACK */
  margin-bottom: 8px;
}

/* ---------- How to Play tour ---------- */
.howto-panel { text-align: left; }

.howto-panel h1 { text-align: center; font-size: 18px; }

#howto-body {
  min-height: 240px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
  margin: 12px 0;
}

#howto-body ul { margin: 8px 0 8px 18px; padding: 0; }
#howto-body li { margin-bottom: 5px; }
#howto-body b { color: var(--accent); }

.howto-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.howto-nav button {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 20px;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
}

#howto-next { background: #22c55e; color: #1a1a1a; border-color: #22c55e; }

#howto-dots { color: var(--dim); font-size: 12px; letter-spacing: 3px; }

/* ---------- Display Size: Mobile (fill the screen) ---------- */
body.display-mobile #app {
  width: 100vw;
  max-width: 560px;
  min-height: 100dvh;
  padding: 6px 10px;
  gap: 6px;
}

body.display-mobile #board-canvas {
  width: 100%;                              /* upscale beyond native pixels... */
  height: auto;
  max-height: calc(100dvh - 320px);         /* ...but keep the controls on screen */
}

body.display-mobile .tc-btn { min-height: 58px; font-size: 24px; }
body.display-mobile .tc-wide { min-height: 52px; font-size: 16px; }
body.display-mobile #hud { font-size: 17px; }

/* ---------- 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; }
}
