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

:root {
  --bg: #0d0f1a;
  --surface: #161928;
  --border: #2a2f4a;
  --accent: #7c6bff;
  --p1: #e05b5b;
  --p2: #4caf78;
  --hole: #1a1a2e;
  --text: #d8daf0;
  --muted: #6b72a0;
  --radius: 12px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

#app {
  max-width: 880px;
  width: 100%;
  padding: 24px 16px;
}

/* ── Header ───────────────────────────────────────────────── */
header {
  text-align: center;
  margin-bottom: 20px;
}

h1 {
  font-size: 2.4rem;
  letter-spacing: .04em;
  color: #fff;
}

.subtitle {
  color: var(--muted);
  margin-top: 4px;
}

/* ── Controls ─────────────────────────────────────────────── */
#controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  margin-bottom: 20px;
}

#controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: .82rem;
  color: var(--muted);
}

select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 10px; font-size: .9rem; cursor: pointer;
}

#newGameBtn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 24px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}

#newGameBtn:hover {
  opacity: .85;
}

/* ── Game Area ────────────────────────────────────────────── */
#gameArea {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

#board {
  flex-shrink: 0;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
}

/* ── Sidebar ──────────────────────────────────────────────── */
#sidebar {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#status {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 1rem;
  line-height: 1.6;
  min-height: 60px;
}

#tileInfo {
  display: flex;
  gap: 12px;
}

.tile-box {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.tile-box .label {
  font-size: .75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.tile-box .val {
  font-size: 2rem;
  font-weight: 700;
}

#p1Tile .val {
  color: var(--p1);
}

#p2Tile .val {
  color: var(--p2);
}

#scoreBox {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

#scoreBox h3 {
  margin-bottom: 8px;
  font-size: .95rem;
}

#scoreDetail {
  font-size: .85rem;
  line-height: 1.8;
  color: var(--muted);
}

/* ── Modal Overlay ────────────────────────────────────────── */
#overlay,
#rulesOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#modal,
#rulesModal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 90%;
}

#modal {
  padding: 40px;
  max-width: 380px;
  text-align: center;
}

#modalTitle {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 12px;
}

#modalBody {
  color: var(--muted);
  margin-bottom: 28px;
  line-height: 1.6;
}

#modalBtn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px 32px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

#modalBtn:hover {
  opacity: .85;
}

/* ── Rules Modal ──────────────────────────────────────────── */
#rulesModal {
  position: relative;
  padding: 32px;
  max-width: 540px;
  text-align: left;
  max-height: 85vh;
  overflow-y: auto;
}
#rulesModal::-webkit-scrollbar { width: 8px; }
#rulesModal::-webkit-scrollbar-track { background: var(--bg); border-radius: 4px; }
#rulesModal::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
#rulesModal::-webkit-scrollbar-thumb:hover { background: var(--muted); }
#rulesClose {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.2rem;
  cursor: pointer;
}

#rulesClose:hover {
  color: var(--text);
}

#rulesModal h2 {
  font-size: 1.6rem;
  margin-bottom: 16px;
  text-align: center;
}

#rulesModal h3 {
  font-size: 1.1rem;
  color: var(--accent);
  margin: 20px 0 10px;
}

#rulesModal p,
#rulesModal li {
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 8px;
}

#rulesModal ul,
#rulesModal ol {
  padding-left: 24px;
  color: var(--text);
}

#rulesBtn {
  margin-top: 10px;
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 16px;
  font-size: .9rem;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: background .15s;
}

#rulesBtn:hover {
  background: var(--border);
}