/* ====== BASE ====== */

:root {
  font-family: 'Indie Flower', 'Segoe Print', 'Bradley Hand', cursive;
  color: white;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #4a3728;
}

button {
  font: inherit;
  cursor: pointer;
}

.screen {
  min-height: 100vh;
}

.screen[hidden] {
  display: none;
}

/* ====== CHALKBOARD SHELL ====== */

.chalkboard {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background:
    linear-gradient(to bottom,
      #c49a6c 0, #a67c52 18px,
      transparent 18px, transparent calc(100% - 18px),
      #8b6340 calc(100% - 18px), #7a5535 100%),
    linear-gradient(to right,
      #c49a6c 0, #a67c52 18px,
      transparent 18px, transparent calc(100% - 18px),
      #8b6340 calc(100% - 18px), #7a5535 100%);
  padding: 18px;
}

.chalkboard__surface {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  background: linear-gradient(to bottom, #2a4a3a, #1e3a2c, #162e22);
  border-radius: 3px;
  padding: 24px;
  overflow: hidden;
}

.chalk-tray {
  height: 10px;
  margin-top: -1px;
  background: #a67c52;
  border-radius: 0 0 2px 2px;
  opacity: 0.6;
}

/* ====== CHALK TEXT HELPERS ====== */

.chalk-heading {
  margin: 8px 0 4px;
  font-size: clamp(36px, 5vw, 56px);
  font-weight: 900;
  color: #ffe680;
  text-align: center;
}

.chalk-underline {
  width: 260px;
  height: 2px;
  margin: 0 auto 24px;
  background: white;
  opacity: 0.4;
  border-radius: 1px;
}

.chalk-label {
  margin: 0 0 10px;
  font-size: clamp(20px, 2.5vw, 28px);
  font-weight: 700;
  color: white;
}

.chalk-coming-soon {
  margin: 6px 0 0;
  font-size: 14px;
  opacity: 0.45;
}

.chalk-box {
  display: inline-block;
  padding: 8px 20px;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  font-size: clamp(17px, 2vw, 24px);
}

/* ====== CHALK BUTTON ====== */

.chalk-btn {
  min-width: 180px;
  padding: 12px 32px;
  border: 2.5px solid rgba(255, 255, 255, 0.85);
  border-radius: 26px;
  background: transparent;
  color: white;
  font-size: clamp(20px, 2.5vw, 28px);
  font-weight: 700;
  transition: background 0.15s;
}

.chalk-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
}

.chalk-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chalk-btn--sm {
  min-width: 0;
  padding: 6px 16px;
  font-size: clamp(14px, 1.6vw, 18px);
  border-width: 2px;
  border-radius: 15px;
}

/* ====== WELCOME SCREEN ====== */

.screen--welcome .chalkboard__surface {
  justify-content: center;
}

.spotlight {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 60% 50% at 50% 0%,
    rgba(255, 251, 230, 0.22) 0%,
    rgba(255, 245, 204, 0.10) 40%,
    transparent 70%);
  pointer-events: none;
}

.welcome-content {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 1;
}

.welcome-title {
  width: min(700px, 80vw);
}

.title-arc {
  width: 100%;
  height: auto;
  display: block;
}

.easter-egg {
  margin: 0;
  font-size: clamp(14px, 1.8vw, 20px);
  opacity: 0.50;
}

.welcome-menu {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 12px;
}

/* Chalk formulas background */
.chalk-formulas {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.chalk-formulas span {
  position: absolute;
  font-size: clamp(14px, 1.8vw, 22px);
  color: white;
  opacity: 0.45;
  white-space: nowrap;
}

/* Vignette for welcome screen */
.screen--welcome .chalkboard__surface::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center 30%,
    transparent 40%,
    rgba(0, 0, 0, 0.35) 100%);
  pointer-events: none;
}

.error-toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  margin: 0;
  padding: 10px 28px;
  border: 1.5px solid rgba(255, 120, 120, 0.6);
  border-radius: 10px;
  background: rgba(80, 20, 20, 0.9);
  color: #ffb0b0;
  font-size: clamp(14px, 1.6vw, 18px);
  text-align: center;
  max-width: calc(100vw - 32px);
}

.error-toast[hidden] {
  display: none;
}

/* ====== SETTINGS SCREEN ====== */

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px 60px;
  width: min(560px, 90vw);
  margin: 20px auto 30px;
}

.settings-group {
  min-width: 0;
}

.chalk-radio {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  font-size: clamp(18px, 2.2vw, 26px);
  cursor: pointer;
}

.chalk-radio input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
}

.chalk-radio input[type="radio"]:checked {
  background: white;
}

.color-swatches {
  display: flex;
  gap: 10px;
  margin-bottom: 4px;
}

.swatch {
  width: 38px;
  height: 38px;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
}

.swatch--green { background: #3a6b4f; }
.swatch--blue { background: #2a3a5c; }
.swatch--red { background: #5c2a2a; }
.swatch--purple { background: #3d2a5c; }

.swatch--active {
  border-color: #ffe680;
  border-width: 3px;
}

.swatch:hover {
  border-color: rgba(255, 255, 255, 0.95);
}

.swatch--active:hover {
  border-color: #ffe680;
}

.swatch:focus-visible {
  outline: 2px solid #ffe680;
  outline-offset: 2px;
}

/* Font previews in settings */
.font-preview--clean {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

.font-preview--retro {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.75em;
}

#settingsBackButton {
  margin-top: auto;
  align-self: center;
}

/* ====== LEADERBOARD SCREEN ====== */

.screen--leaderboard .chalkboard__surface {
  gap: 0;
}

.leaderboard-filters {
  display: flex;
  gap: 32px;
  justify-content: center;
  flex-wrap: wrap;
  width: min(720px, 90vw);
  margin: 0 auto 24px;
}

.leaderboard-filter-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.chalk-filter-label {
  font-size: clamp(16px, 2vw, 22px);
  opacity: 0.6;
  white-space: nowrap;
}

.chalk-pill-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chalk-pill {
  padding: 5px 14px;
  border: 1.5px solid rgba(255, 255, 255, 0.5);
  border-radius: 14px;
  background: transparent;
  color: white;
  font-size: clamp(14px, 1.6vw, 18px);
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.chalk-pill:hover {
  background: rgba(255, 255, 255, 0.08);
}

.chalk-pill--active {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.85);
}

.leaderboard-filter-summary {
  margin: 0 auto 14px;
  color: #ffe680;
  font-size: clamp(16px, 2vw, 22px);
  text-align: center;
}

.leaderboard-table-wrapper {
  width: min(680px, 90vw);
  margin: 0 auto 24px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: clamp(16px, 2vw, 22px);
}

.leaderboard-table th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 700;
  color: #ffe680;
  border-bottom: 1.5px solid rgba(255, 255, 255, 0.25);
  white-space: nowrap;
}

.leaderboard-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.leaderboard-table th:first-child,
.leaderboard-table td:first-child {
  text-align: center;
  width: 60px;
}

.leaderboard-table th:nth-child(3),
.leaderboard-table td:nth-child(3) {
  text-align: right;
}

.leaderboard-table th:nth-child(4),
.leaderboard-table td:nth-child(4) {
  text-align: center;
}

.leaderboard-empty {
  margin: 40px 0;
  text-align: center;
  font-size: clamp(18px, 2.2vw, 26px);
  opacity: 0.45;
}

#leaderboardBackButton {
  margin-top: auto;
  align-self: center;
}

/* ====== GAME SCREEN ====== */

.screen--game {
  position: relative;
  --game-board-background: linear-gradient(to bottom, #2a4a3a, #1e3a2c, #162e22);
  --game-overlay-scrim: rgba(10, 26, 16, 0.75);
}

.screen--game .chalkboard__surface {
  gap: 0;
  background: var(--game-board-background);
}

.screen--game.board-color-blue {
  --game-board-background: linear-gradient(to bottom, #2a3a5c, #1e2c4a, #162240);
  --game-overlay-scrim: rgba(12, 22, 45, 0.75);
}

.screen--game.board-color-red {
  --game-board-background: linear-gradient(to bottom, #5c2a2a, #4a1e1e, #3e1616);
  --game-overlay-scrim: rgba(45, 12, 12, 0.75);
}

.screen--game.board-color-purple {
  --game-board-background: linear-gradient(to bottom, #3d2a5c, #2e1e4a, #241640);
  --game-overlay-scrim: rgba(30, 12, 45, 0.75);
}

.game-topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  width: 100%;
  max-width: 780px;
  padding: 0 8px;
  flex-shrink: 0;
}

.topbar-label {
  display: block;
  font-size: clamp(13px, 1.5vw, 18px);
  opacity: 0.55;
  margin-bottom: 2px;
}

.topbar-score strong,
.topbar-time strong {
  font-size: clamp(24px, 3vw, 36px);
  font-weight: 900;
}

.topbar-score strong {
  color: #ffe680;
}

.topbar-time {
  text-align: center;
}

.topbar-skills {
  text-align: right;
}

.topbar-skills .skill-actions {
  display: flex;
  gap: 8px;
  margin-top: 2px;
}

.chalk-divider {
  width: 100%;
  max-width: 780px;
  height: 1.5px;
  margin: 10px 0;
  background: white;
  opacity: 0.25;
  flex-shrink: 0;
}

.board-panel {
  display: grid;
  place-items: center;
  flex: 1;
  width: 100%;
  min-height: 0;
  overflow: hidden;
}

.game-nav {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 10px;
  flex-shrink: 0;
}

.board {
  --size: 9;
  display: grid;
  grid-template-columns: repeat(var(--size), minmax(0, 1fr));
  gap: 2px;
  width: min(100%, max(280px, calc(100vh - 160px)));
  max-width: 780px;
  aspect-ratio: 1;
  border: 3px solid rgba(255, 255, 255, 0.45);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
}

.board.empty {
  border-color: transparent;
  background: transparent;
}

.cell {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: white;
  font-size: clamp(18px, 2.5vw, 30px);
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s;
}

.cell:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.10);
}

.cell.cleared {
  background: rgba(255, 255, 255, 0.03);
  color: transparent;
}

.cell.clearing {
  opacity: 0.25;
  pointer-events: none;
}

.cell.selected {
  background: rgba(255, 255, 255, 0.10);
}

.cell.corner {
  background: rgba(255, 255, 255, 0.18);
}

.cell.hint {
  background: rgba(255, 230, 128, 0.25);
  color: #ffe680;
  box-shadow: inset 0 0 0 2px rgba(255, 230, 128, 0.5);
}

.cell.hint.selected {
  background: rgba(255, 230, 128, 0.35);
  color: #ffe680;
}

.cell:disabled {
  cursor: default;
}

/* Board cell font variants */
.board.font-clean .cell {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

.board.font-retro .cell {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(14px, 2vw, 24px);
}

/* ====== GAME OVER OVERLAY ====== */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay[hidden] {
  display: none;
}

.overlay__scrim {
  position: absolute;
  inset: 0;
  background: var(--game-overlay-scrim, rgba(10, 26, 16, 0.75));
}

.overlay__popup {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 50px;
  border: 3px solid rgba(255, 255, 255, 0.65);
  border-radius: 10px;
  min-width: 360px;
  background: var(--game-board-background, linear-gradient(to bottom, #2a4a3a, #1e3a2c, #162e22));
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}

.overlay__popup::after {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  pointer-events: none;
}

.overlay__reason {
  margin: 0;
  font-size: clamp(34px, 5vw, 54px);
  font-weight: 900;
  color: #ffe680;
}

.overlay__underline {
  width: 240px;
  height: 2px;
  margin: 4px 0 20px;
  background: #ffe680;
  opacity: 0.45;
  border-radius: 1px;
}

.overlay__score-label {
  margin: 0;
  font-size: clamp(16px, 2vw, 22px);
  opacity: 0.55;
}

.overlay__score {
  margin: 4px 0 24px;
  font-size: clamp(40px, 5.5vw, 60px);
  font-weight: 900;
  color: #ffe680;
}

.overlay__submit-area {
  min-height: 58px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay__submit-status {
  margin: 0;
  min-width: 180px;
  padding: 10px 24px;
  border: 2.5px solid rgba(255, 230, 128, 0.75);
  border-radius: 26px;
  color: #ffe680;
  font-size: clamp(18px, 2.2vw, 24px);
  font-weight: 700;
  text-align: center;
}

.overlay__actions {
  display: flex;
  gap: 16px;
}

.overlay__actions .chalk-btn {
  min-width: 150px;
  font-size: clamp(18px, 2.2vw, 24px);
  padding: 10px 24px;
}

.overlay__popup--score-submit {
  gap: 0;
}

.score-submit-form {
  width: min(320px, 100%);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
}

.score-submit-form__label {
  font-size: clamp(18px, 2.2vw, 24px);
  opacity: 0.72;
  text-align: center;
}

.score-submit-form__input {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid rgba(255, 255, 255, 0.75);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: white;
  font: inherit;
  font-size: clamp(20px, 2.4vw, 28px);
  text-align: center;
  outline: none;
}

.score-submit-form__input::placeholder {
  color: rgba(255, 255, 255, 0.45);
}

.score-submit-form__input:focus {
  border-color: #ffe680;
  box-shadow: 0 0 0 2px rgba(255, 230, 128, 0.18);
}

.score-submit-form__error {
  min-height: 1.2em;
  margin: 0;
  color: #ffb4a8;
  font-size: clamp(15px, 1.8vw, 19px);
  line-height: 1.2;
  text-align: center;
}

.overlay__actions--submit {
  margin-top: 6px;
}

/* ====== RESPONSIVE ====== */

@media (max-width: 820px) {
  .game-topbar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .topbar-skills {
    width: 100%;
    text-align: left;
  }

  .topbar-skills .skill-actions {
    justify-content: flex-start;
  }

  .board {
    width: min(100%, calc(100vh - 180px));
  }
}

@media (max-width: 600px) {
  .settings-grid {
    grid-template-columns: 1fr;
    gap: 30px;
  }

  .leaderboard-filters {
    flex-direction: column;
    align-items: center;
    gap: 16px;
  }

  .leaderboard-filter-group {
    flex-direction: column;
    gap: 8px;
  }

  .chalk-pill-group {
    justify-content: center;
  }

  .leaderboard-table {
    font-size: 14px;
  }

  .leaderboard-table th,
  .leaderboard-table td {
    padding: 8px 6px;
  }

  .overlay__popup {
    min-width: 0;
    width: calc(100vw - 48px);
    padding: 30px 24px;
  }

  .overlay__reason {
    font-size: 34px;
  }

  .overlay__score {
    font-size: 40px;
  }

  .overlay__actions {
    flex-direction: column;
    width: 100%;
  }

  .overlay__actions .chalk-btn {
    width: 100%;
  }

  .welcome-menu .chalk-btn {
    min-width: 160px;
    font-size: 20px;
    padding: 10px 24px;
  }
}
