:root {
  --bg:       #0f172a;
  --surface:  #1e293b;
  --border:   #334155;
  --board-l:  #f0d9b5;
  --board-d:  #b58863;
  --select:   #60a5fa;
  --legal-dot:#22c55e;
  --legal-cap:#fb923c;
  --text:     #f1f5f9;
  --muted:    #94a3b8;
  --success:  #4ade80;
  --fail:     #f87171;
  --tile-bg:  #334155;
}

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

body {
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 20px 16px;
}

.app {
  max-width: 900px;
  margin: 0 auto;
}

/* ── Header ── */

header {
  margin-bottom: 28px;
  text-align: center;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

h1 {
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

h1 a {
  color: inherit;
  text-decoration: none;
}

@keyframes title-flash {
  0%, 100% { color: #fff; }
  50%       { color: var(--success); }
}
h1 a.flashing {
  animation: title-flash 1.2s ease-in-out infinite;
}

.subtitle {
  font-size: 0.85rem;
  color: var(--muted);
  font-style: italic;
  margin-top: 4px;
}

/* ── Layout ── */

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

@media (min-width: 700px) {
  main {
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
  }
}

/* ── Board wrap ── */

#board-wrap {
  flex-shrink: 0;
}

#board {
  display: grid;
  grid-template-columns: repeat(var(--size), var(--cell));
  grid-template-rows: repeat(var(--size), var(--cell));
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.55);
  border-radius: 4px;
  overflow: hidden;
}

/* ── Squares ── */

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: filter 0.12s;
}
.square.light { background: var(--board-l); }
.square.dark  { background: var(--board-d); }

.square.has-piece { cursor: pointer; }
.square.has-piece:hover { filter: brightness(1.08); }

.square.selected {
  box-shadow: inset 0 0 0 3px var(--select);
  filter: brightness(1.05);
}

.square.legal::after {
  content: "";
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(34, 197, 94, 0.6);
  pointer-events: none;
}
.square.legal.has-letter::after {
  width: 86%;
  height: 86%;
  background: transparent;
  border: 3px solid rgba(251, 146, 60, 0.85);
  border-radius: 50%;
}

/* ── Coords ── */

.coord {
  position: absolute;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}
.coord-rank { top: 3px; left: 4px; }
.coord-file { bottom: 3px; right: 4px; }
.square.light .coord { color: var(--board-d); }
.square.dark  .coord { color: var(--board-l); }

/* ── Pieces & letters ── */

.piece {
  font-size: clamp(28px, calc(var(--cell) * 0.72), 52px);
  color: #1e293b;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
  line-height: 1;
  pointer-events: none;
}

.letter {
  font-family: "Outfit", system-ui, sans-serif;
  font-weight: 700;
  font-size: clamp(18px, calc(var(--cell) * 0.44), 30px);
  color: #1d4ed8;
  pointer-events: none;
}

/* ── Info panel ── */

#info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.5rem;
  width: calc(var(--size) * var(--cell));
  height: auto;
}

/* ── Move progress ── */

.meta-row {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  gap: 0.75rem;
}

#streak-display, #total-label, #time-display {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  white-space: nowrap;
}

#streak-count.bump {
  display: inline-block;
  animation: streak-bump 0.4s ease-out;
}

@keyframes streak-bump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.5); }
  100% { transform: scale(1); }
}

/* ── Captured letters ── */

.captured-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.captured-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#captured {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  height: 2rem;
  overflow: visible;
}

@keyframes popin {
  0%   { transform: scale(0.4); opacity: 0; }
  70%  { transform: scale(1.18); opacity: 1; }
  100% { transform: scale(1); }
}

#captured span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  background: var(--tile-bg);
  border: 2px solid var(--border);
  border-radius: 0.5rem;
  font-family: "Outfit", system-ui, sans- serif;
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text);
}
#captured span.new {
  animation: popin 0.25s ease forwards;
}
#captured span.empty {
  border-style: dashed;
  opacity: 0.3;
}
#captured span.solved {
  color: var(--success);
}
#captured span.failed {
  color: var(--fail);
}

/* ── Hints ── */

.hints-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.hints-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

#hints {
  display: flex;
  gap: 0.3rem;
  align-items: center;
}

#hints span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  background: var(--tile-bg);
  border: 1.5px solid var(--border);
  border-radius: 0.25rem;
  font-family: "Outfit", system-ui, sans-serif;
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--text);
}

#hints span.empty {
  border-style: dashed;
  opacity: 0.3;
}

#hint-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  font-family: inherit;
  font-size: 0.65rem;
  background: var(--tile-bg);
  color: #3b82f6;
  border: 1.5px solid var(--border);
  border-radius: 0.25rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s;
}
#hint-btn:hover:not(:disabled) { color: #6366f1; }
#hint-btn:disabled { opacity: 0.3; cursor: default; }

@keyframes hint-nudge {
  0%, 100% { box-shadow: none; border-color: var(--border); color: #3b82f6; }
  50%      { box-shadow: 0 0 5px 2px rgba(251, 146, 60, 0.9); border-color: #fb923c; color: #fb923c; }
}
#hint-btn.nudge {
  animation-name: hint-nudge;
  animation-duration: 0.25s;
  animation-timing-function: ease-in-out;
  animation-iteration-count: 3;
}

.hint-history-row {
  font-size: 0.75rem;
  font-style: italic;
  color: var(--muted);
  text-align: center;
}

/* ── See attempts link ── */

#see-attempts {
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
#see-attempts:hover:not(.disabled) { color: var(--text); }
#see-attempts.disabled { opacity: 0.3; cursor: default; text-decoration: none; }

/* ── Attempts modal ── */

#attempts-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 100;
}
#attempts-modal[hidden] { display: none; }

.modal-box {
  position: fixed;
  left: 50%;
  top: 10%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: calc(var(--size) * var(--cell));
  max-height: 70vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
}

.modal-title {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

#modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
#modal-close:hover { color: var(--text); }

.modal-stats {
  display: flex;
  justify-content: space-around;
  width: 100%;
}

.modal-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.modal-stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
}

.score-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: mi5-spin 0.8s linear infinite;
  vertical-align: middle;
  opacity: 0.5;
}

@keyframes mi5-spin {
  to { transform: rotate(360deg); }
}

.modal-stat-label {
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

#modal-share {
  padding: 0.625rem 1.75rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  align-self: center;
  transition: filter 0.15s, transform 0.15s;
}
#modal-share:hover { filter: brightness(1.12); transform: scale(1.02); }
#modal-share:active { transform: scale(0.97); }

.signin-cta {
  display: block;
  width: 100%;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  color: var(--select);
  background: rgba(96, 165, 250, 0.1);
  border: 1px solid var(--select);
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
}
.signin-cta:hover { background: rgba(96, 165, 250, 0.18); }
.signin-cta[hidden] { display: none; }

.next-game {
  font-size: 0.8rem;
  color: var(--text-muted, #888);
  text-align: center;
}
.next-game span {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.attempts-toggle {
  background: none;
  border: none;
  color: var(--text-muted, #888);
  font-size: 0.72rem;
  cursor: pointer;
  padding: 0.25rem 0;
  letter-spacing: 0.02em;
}
.attempts-toggle:hover { text-decoration: underline; }

#attempts-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: center;
}

.history-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  height: 2rem;
  overflow: visible;
}

.history-row span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  background: var(--tile-bg);
  border: 2px solid var(--border);
  border-radius: 0.5rem;
  font-family: "Outfit", system-ui, sans-serif;
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text);
}

.history-row span.solved { color: var(--success); }
.history-row span.failed { color: var(--fail); }
.history-row span.empty  { border-style: dashed; opacity: 0.3; }

.history-row span.sq-correct { background: var(--success); border-color: var(--success); }
.history-row span.sq-wrong   { background: var(--fail);    border-color: var(--fail); }
.history-row span.sq-empty   { background: transparent;    border-style: dashed; opacity: 0.3; }

/* ── Result ── */

#result {
  display: flex;
  align-items: center;
  min-height: 1.75rem;
  font-weight: 600;
  font-size: 0.875rem;
  line-height: 1.4;
}
#result.success { color: var(--success); }
#result.fail    { color: var(--fail); }

/* ── Button ── */

#reset {
  padding: 0.625rem 1.75rem;
  width: 6.875rem;
  text-align: center;
  justify-content: center;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  align-self: center;
  transition: filter 0.15s, transform 0.15s;
}
#reset:hover:not(:disabled)  { filter: brightness(1.12); transform: scale(1.02); }
#reset:active:not(:disabled) { transform: scale(0.97); }
#reset:disabled { opacity: 0.35; cursor: not-allowed; }

@keyframes btn-pulse {
  0%, 100% { filter: brightness(1);    transform: scale(1); }
  50%       { filter: brightness(1.25); transform: scale(1.06); }
}
#reset.blinking { animation: btn-pulse 1s ease-in-out infinite; }

.games-link {
  font-size: 0.75rem;
  color: var(--muted);
}
.games-link:hover { color: var(--text); }

/* ── Confetti ── */

@keyframes confetti-fall {
  0%   { transform: translateY(var(--start)) translateX(0) rotate(0); opacity: 1; }
  100% { transform: translateY(110vh) translateX(var(--drift)) rotate(var(--spin)); opacity: 1; }
}
#confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 150;
  overflow: hidden;
}
.confetti-piece {
  position: absolute;
  top: 0;
  border-radius: 2px;
  animation: confetti-fall var(--fall) linear var(--delay) both;
}

/* ── Toast ── */

@keyframes toast-in-out {
  0%   { opacity: 0; transform: translateX(-50%) translateY(12px) scale(0.95); }
  12%  { opacity: 1; transform: translateX(-50%) translateY(0)    scale(1); }
  75%  { opacity: 1; transform: translateX(-50%) translateY(0)    scale(1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-8px) scale(0.97); }
}

#toast {
  position: fixed;
  top: 25%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg);
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.01em;
  padding: 12px 28px;
  border-radius: 1rem;
  border: 1px solid var(--border);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  opacity: 0;
  max-width: 80vw;
  text-align: center;
  white-space: normal;
  z-index: 200;
}
#toast.show {
  animation: toast-in-out 2.8s ease forwards;
}

/* ── Pre-start letter mask ── */

#board.pre-start { pointer-events: none; }
#board.pre-start .square.has-letter { cursor: default; }
#board.pre-start .square.has-letter .letter { opacity: 0; }
#board.pre-start .square.has-letter::after {
  content: "?";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: auto;
  height: auto;
  background: none;
  border: none;
  border-radius: 0;
  font-family: "Outfit", system-ui, sans-serif;
  font-weight: 700;
  font-size: clamp(18px, calc(var(--cell) * 0.44), 30px);
  color: #1d4ed8;
  pointer-events: none;
}

/* ── Timer ── */

.stat-data {
  font-size: 12px;
  font-weight: 900;
  color: var(--muted);
  letter-spacing: 0.05em;
  font-variant-numeric: tabular-nums;
}

/* ── Tutorial ── */

#tutorial-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.25rem 1.75rem;
  text-align: center;
  width: 80vw;
  max-width: 24rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: 0 0.5rem 2rem rgba(0, 0, 0, 0.5);
}

#tutorial-card h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

#tutorial-card p {
  font-size: 0.8125rem;
  color: var(--muted);
  line-height: 1.5;
}

.tutorial-play-link {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.625rem 1.5rem;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: 999px;
  text-decoration: none;
  transition: filter 0.15s, transform 0.15s;
}
.tutorial-play-link:hover { filter: brightness(1.12); transform: scale(1.02); }

.tutorial-action-btn {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.625rem 1.5rem;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: filter 0.15s, transform 0.15s;
}
.tutorial-action-btn:hover { filter: brightness(1.12); transform: scale(1.02); }


/* ── Hamburger menu ── */

#back-btn {
  position: fixed;
  top: 1.25rem;
  left: 1.25rem;
  width: 1.75rem;
  height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  z-index: 10;
  padding: 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
}
#back-btn:hover { color: var(--text); }
#back-btn[hidden] { display: none; }

#menu-btn {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  width: 1.75rem;
  height: 1.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  z-index: 10;
  padding: 0;
}
#menu-btn[hidden] { display: none; }
#menu-btn:disabled { opacity: 0.3; cursor: default; }
#menu-btn span {
  display: block;
  width: 11px;
  height: 1.5px;
  background: var(--muted);
  border-radius: 1px;
  transition: background 0.15s;
}
#menu-btn:hover span { background: var(--text); }

#menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
#menu-overlay.open { opacity: 1; pointer-events: all; }

#menu-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 200px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 201;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}
#menu-drawer.open { transform: translateX(0); }
@media (min-width: 640px) { #menu-drawer { width: 300px; } }

.menu-drawer-header {
  display: flex;
  justify-content: flex-end;
  padding: 1rem 1rem 0;
}

#menu-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
#menu-close:hover { color: var(--text); }

.menu-items {
  display: flex;
  flex-direction: column;
  padding: 0.75rem 1.5rem;
}

.menu-item {
  color: var(--text);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}
.menu-item:hover { color: var(--select); }

#menu-auth {
  padding: 0.75rem 0;
  border-top: 1px solid var(--border);
  margin-top: auto;
}
#google-btn-wrap { padding: 0.5rem 0; }
#google-btn-wrap[hidden] { display: none; }
#sign-out-btn {
  background: none;
  border: none;
  border-bottom: none;
  cursor: pointer;
  text-align: left;
  padding: 0.75rem 0;
  font-family: inherit;
  color: var(--fail);
  font-size: 0.875rem;
  font-weight: 600;
  width: 100%;
}
#sign-out-btn:hover { opacity: 0.8; }
