/* ============================================================
   Chess Puzzles – Global Styles
   Dark chess-themed design
   ============================================================ */

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-deep:    #0f0e17;
  --bg-mid:     #1a1a2e;
  --bg-card:    #16213e;
  --bg-panel:   #1f2d4a;
  --accent:     #c9a84c;
  --accent-lit: #e8c87a;
  --accent-dim: #7a5e25;
  --light-sq:   #f0d9b5;
  --dark-sq:    #b58863;
  --text-main:  #e8e8e8;
  --text-muted: #8899aa;
  --text-dim:   #556677;
  --danger:     #e05252;
  --success:    #52c078;
  --info:       #5295e0;
  --border:     #2a3a5a;
  --shadow:     rgba(0,0,0,0.5);
  --radius:     10px;
  --radius-sm:  6px;
  --font:       'Segoe UI', system-ui, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg-deep);
  color: var(--text-main);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-lit); text-decoration: underline; }

/* ── Index / Menu Page ────────────────────────────────────── */
.menu-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background:
    radial-gradient(ellipse at 20% 30%, rgba(100,70,20,0.18) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 70%, rgba(30,50,100,0.18) 0%, transparent 60%),
    var(--bg-deep);
}

.menu-header {
  text-align: center;
  margin-bottom: 3rem;
}

.menu-header h1 {
  font-size: 2.8rem;
  font-weight: 800;
  letter-spacing: -1px;
  color: var(--accent);
  text-shadow: 0 0 40px rgba(201,168,76,0.3);
}

.menu-header p {
  color: var(--text-muted);
  margin-top: 0.5rem;
  font-size: 1rem;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  width: 100%;
  max-width: 960px;
}

.menu-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
  text-decoration: none;
  color: var(--text-main);
}

.menu-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 8px 32px rgba(201,168,76,0.18);
  text-decoration: none;
  color: var(--text-main);
}

.menu-card.highscores-card {
  border-color: var(--accent-dim);
  background: var(--bg-panel);
  grid-column: 1 / -1;
}

.menu-card.highscores-card:hover {
  border-color: var(--accent-lit);
}

.card-icon {
  font-size: 3rem;
  line-height: 1;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.5));
}

.card-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
}

.card-subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.4;
}

.card-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-max { background: rgba(82,192,120,0.2); color: var(--success); border: 1px solid rgba(82,192,120,0.4); }
.badge-min { background: rgba(82,149,224,0.2); color: var(--info);    border: 1px solid rgba(82,149,224,0.4); }
.badge-hs  { background: rgba(201,168,76,0.2); color: var(--accent);  border: 1px solid rgba(201,168,76,0.4); }

.menu-footer {
  margin-top: 2.5rem;
  color: var(--text-dim);
  font-size: 0.8rem;
  text-align: center;
}

/* ── Game Layout ──────────────────────────────────────────── */
.game-container {
  display: grid;
  grid-template-columns: 270px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  overflow-y: auto;
}

.game-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--accent);
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.game-title .piece-symbol {
  font-size: 1.6rem;
  line-height: 1;
}

.game-mode-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  vertical-align: middle;
}

/* ── Control Groups ──────────────────────────────────────── */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.control-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

select {
  background: var(--bg-panel);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.75rem;
  font-size: 0.9rem;
  font-family: var(--font);
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

select:hover, select:focus {
  border-color: var(--accent);
}

/* ── Score Panel ─────────────────────────────────────────── */
.score-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.score-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.score-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.score-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 2rem;
  text-align: right;
}

/* ── Status Box ──────────────────────────────────────────── */
.status-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--text-main);
  min-height: 3.5rem;
  line-height: 1.5;
}

.status-box.status-win {
  border-left-color: var(--success);
  color: var(--success);
}

.status-box.status-error {
  border-left-color: var(--danger);
}

/* ── Buttons ─────────────────────────────────────────────── */
.button-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.btn {
  display: block;
  width: 100%;
  padding: 0.6rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  text-align: center;
  transition: filter 0.15s, transform 0.1s;
  text-decoration: none;
}

.btn:hover { filter: brightness(1.12); transform: translateY(-1px); }
.btn:active { transform: translateY(0); filter: brightness(0.95); }

.btn-primary   { background: var(--accent);   color: #1a1000; }
.btn-secondary { background: var(--bg-panel); color: var(--text-main); border: 1px solid var(--border); }
.btn-danger    { background: var(--danger);   color: #fff; }
.btn-link      { background: transparent; color: var(--accent); border: 1px solid var(--accent-dim); }

/* ── Nav Links ───────────────────────────────────────────── */
.nav-links {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.83rem;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
}

.nav-link:hover {
  background: var(--bg-panel);
  color: var(--accent);
  text-decoration: none;
}

/* ── Help Section ────────────────────────────────────────── */
.help-section {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  flex: 1;
}

.help-section h4 {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.5rem;
}

.help-section ul {
  padding-left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.help-section li {
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.4;
}

.help-section li strong {
  color: var(--text-muted);
}

/* ── Board Area ──────────────────────────────────────────── */
.board-area {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background:
    repeating-conic-gradient(rgba(255,255,255,0.012) 0% 25%, transparent 0% 50%) 0 0 / 60px 60px,
    var(--bg-mid);
  overflow: auto;
}

.board-wrapper {
  position: relative;
  display: inline-block;
}

canvas#board {
  display: block;
  border-radius: 4px;
  box-shadow: 0 8px 48px rgba(0,0,0,0.7), 0 2px 8px rgba(0,0,0,0.5);
  max-width: 100%;
  height: auto;
  cursor: pointer;
}

/* ── Toast Notifications ─────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 1000;
  pointer-events: none;
}

.toast {
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  max-width: 320px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: auto;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-info    { background: #1a3060; color: #b0d0ff; border-left: 3px solid var(--info); }
.toast-success { background: #0d3020; color: #80f0a0; border-left: 3px solid var(--success); }
.toast-record  { background: #3a2800; color: #ffe080; border-left: 3px solid var(--accent); }
.toast-warning { background: #3a1800; color: #ffb060; border-left: 3px solid #ff8c00; }

/* ── High Scores Page ────────────────────────────────────── */
.hs-page {
  min-height: 100vh;
  padding: 2rem 1rem;
  background: var(--bg-deep);
}

.hs-header {
  text-align: center;
  margin-bottom: 2rem;
}

.hs-header h1 {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--accent);
}

.hs-header p {
  color: var(--text-muted);
  margin-top: 0.4rem;
}

.hs-tabs {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 2rem;
}

.hs-tab {
  padding: 0.5rem 1.5rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  transition: all 0.18s;
}

.hs-tab.active {
  background: var(--accent);
  color: #1a1000;
  border-color: var(--accent);
}

.hs-content {
  max-width: 860px;
  margin: 0 auto;
}

.hs-panel { display: none; }
.hs-panel.active { display: block; }

.hs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.hs-table-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.hs-table-card h3 {
  padding: 0.8rem 1.2rem;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.hs-table {
  width: 100%;
  border-collapse: collapse;
}

.hs-table th {
  padding: 0.5rem 1rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.hs-table td {
  padding: 0.5rem 1rem;
  font-size: 0.88rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.hs-table tr:last-child td { border-bottom: none; }
.hs-table tr:hover td { background: rgba(255,255,255,0.03); }

.hs-table td.score-solved   { color: var(--success); font-weight: 700; }
.hs-table td.score-unsolved { color: var(--text-dim); }
.hs-table td.score-value    { color: var(--accent);  font-weight: 700; font-variant-numeric: tabular-nums; }
.hs-table td.score-none     { color: var(--text-dim); font-style: italic; }

.hs-nav {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 2rem;
}

.hs-footer {
  text-align: center;
  margin-top: 3rem;
  color: var(--text-dim);
  font-size: 0.78rem;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 800px) {
  .game-container {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .board-area {
    padding: 1rem;
  }

  .menu-header h1 { font-size: 2rem; }

  .hs-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .menu-header h1 { font-size: 1.6rem; }
  .menu-grid { grid-template-columns: 1fr 1fr; }
}
