:root {
  --bg-1: #3a4a5c;
  --bg-2: #212d3a;
  --ink: #16241c;
  --cream: #f2f5f8;
  --accent: #ffb300;
  --accent-dark: #c98600;
  --red: #c62828;
  --panel: rgba(24, 34, 46, 0.92);

  --font-display: "Baloo 2", "Segoe UI", sans-serif;
  --font-body: "Poppins", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font-body);
  background: var(--bg-2);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.game-frame {
  position: relative;
  width: 100vw;
  height: calc(100vh - 48px);
  height: calc(100dvh - 48px);
  overflow: hidden;
}

html.ksz-fullscreen .game-frame {
  height: 100vh;
  height: 100dvh;
}

.play-area {
  position: relative;
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse at 50% 0%, var(--bg-1), var(--bg-2) 75%);
}

.hidden { display: none !important; }

/* ---------------- Screens ---------------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.start-content {
  max-width: 560px;
  text-align: center;
  color: var(--cream);
}

.brand-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.2rem, 8vw, 3.6rem);
  letter-spacing: 2px;
  color: var(--accent);
  text-shadow: 0 3px 0 rgba(0,0,0,0.35);
  margin: 0 0 18px;
}

.hint {
  font-size: 0.96rem;
  line-height: 1.6;
  color: rgba(242,245,248,0.88);
  margin: 0 0 26px;
}

.size-select {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 26px;
}

.size-btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 12px 18px;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.06);
  color: var(--cream);
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease, border-color 0.12s ease;
}

.size-btn:hover { filter: brightness(1.12); }
.size-btn:active { transform: translateY(2px); }

.size-btn.is-selected {
  border-color: var(--accent);
  background: rgba(255,179,0,0.18);
  color: var(--accent);
}

.btnrow {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn-primary, .btn-secondary {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1rem;
  padding: 14px 28px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.btn-primary {
  background: var(--accent);
  color: #2b1a00;
  box-shadow: 0 4px 0 var(--accent-dark);
}

.btn-secondary {
  background: transparent;
  color: var(--cream);
  border: 2px solid rgba(242,245,248,0.6);
}

.btn-primary:active, .btn-secondary:active {
  transform: translateY(2px);
}

.btn-primary:hover, .btn-secondary:hover {
  filter: brightness(1.08);
}

/* ---------------- Panels (leaderboard / win / lose) ---------------- */
.panel {
  background: var(--panel);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 20px;
  padding: 28px 32px;
  max-width: 480px;
  width: 100%;
  text-align: center;
  color: var(--cream);
  box-shadow: 0 12px 32px rgba(0,0,0,0.4);
}

.panel-title {
  font-family: var(--font-display);
  color: var(--accent);
  font-size: 1.7rem;
  margin: 0 0 18px;
}

.panel-title--lose { color: #ff6b6b; }

.win-time {
  font-size: 1.05rem;
  margin: 0 0 20px;
}

.size-tabs {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.size-tab {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 8px 14px;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,0.2);
  background: transparent;
  color: var(--cream);
  cursor: pointer;
}

.size-tab.is-selected {
  border-color: var(--accent);
  background: rgba(255,179,0,0.18);
  color: var(--accent);
}

.leaderboard-list {
  list-style: none;
  margin: 0 0 22px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 40vh;
  overflow-y: auto;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 2em 1fr auto auto;
  gap: 10px;
  align-items: center;
  background: rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.92rem;
}

.leaderboard-list li.is-me {
  background: rgba(255,179,0,0.16);
}

.lb-rank { color: var(--accent); font-weight: 700; text-align: left; }
.lb-name { text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 600; }
.lb-time { color: rgba(242,245,248,0.7); }

.lb-empty {
  font-size: 0.9rem;
  color: rgba(242,245,248,0.7);
  margin: 0 0 20px;
}

.highscore-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0 0 20px;
}

.highscore-form label {
  font-size: 0.9rem;
  text-align: left;
}

.highscore-form input {
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 10px 14px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  color: var(--cream);
}

.highscore-form input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---------------- Fullscreen button ---------------- */
.fullscreen-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 50;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.35);
  color: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.fullscreen-btn svg { width: 20px; height: 20px; }
.fullscreen-icon--exit { display: none; }
.fullscreen-btn.is-fullscreen .fullscreen-icon--enter { display: none; }
.fullscreen-btn.is-fullscreen .fullscreen-icon--exit { display: block; }

/* ---------------- HUD ---------------- */
.hud {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 60px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 40;
}

.hud-pill {
  background: rgba(0,0,0,0.3);
  border-radius: 999px;
  padding: 6px 16px;
  display: flex;
  gap: 8px;
  align-items: baseline;
  color: var(--cream);
}

.hud-label { font-size: 0.72rem; opacity: 0.75; }
.hud-value { font-family: var(--font-display); font-weight: 700; font-size: 1rem; }

.hud-controls { margin-left: auto; display: flex; gap: 8px; }

.hud-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.3);
  color: var(--cream);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.hud-icon-btn:active { transform: translateY(1px); }

.hud-icon-btn--flag.is-active {
  background: var(--accent);
}

/* ---------------- Board ---------------- */
#screen-game { align-items: stretch; padding: 0; }

.board-viewport {
  position: absolute;
  inset: 0;
  padding-top: 56px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
}

#board-canvas {
  margin: auto;
  touch-action: pan-x pan-y;
  image-rendering: pixelated;
}

@media (max-width: 640px) {
  .hint { font-size: 0.88rem; }
  .size-btn { padding: 10px 14px; font-size: 0.88rem; }
}
