:root {
  --bg: #1e293b;
  --panel: #0f172a;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --correct: #4ade80;
  --wrong: #f87171;
  --key: #334155;
  --key-hover: #475569;
  --board-blue: #1d4ed8;
  --piece-player: #f87171;
  --piece-computer: #fbbf24;
}

* { box-sizing: border-box; }

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

.game {
  width: 100%;
  max-width: 520px;
  margin: 2rem 1rem;
  padding: 1.5rem;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  text-align: center;
}

.home-btn {
  display: block;
  margin: 1.5rem auto 0;
  max-width: 220px;
  border-radius: 10px;
  overflow: hidden;
  opacity: 0.8;
  transition: opacity 0.15s, transform 0.12s;
}
.home-btn img { display: block; width: 100%; }
.home-btn:hover { opacity: 1; transform: scale(1.04); }

.speed-control {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.75rem;
}
.speed-label {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.speed-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.speed-hint {
  font-size: 0.68rem;
  color: var(--muted);
  white-space: nowrap;
}
.speed-slider {
  width: 130px;
  accent-color: var(--accent);
  cursor: pointer;
}

h1 {
  margin: 0 0 1rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--accent);
}

/* ---- Score bar ---- */
.score {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  margin-bottom: 1rem;
  padding: 0.6rem 1rem;
  background: var(--bg);
  border-radius: 12px;
}
.score-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 5rem;
  position: relative;
}
.score-label {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.name-btn {
  max-width: 7rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: inherit;
  font-weight: 600;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  border-bottom: 1px dashed var(--muted);
}
.name-btn:hover { color: var(--accent); border-bottom-color: var(--accent); }
.name-input {
  width: 7rem;
  font-family: inherit;
  font-size: 0.8rem;
  text-align: center;
  color: var(--text);
  background: var(--key);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0.1rem 0.3rem;
}
.name-input:focus { outline: none; }
.name-list {
  position: absolute;
  top: 1.6rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  min-width: 7rem;
  max-height: 9rem;
  overflow-y: auto;
  margin: 0;
  padding: 0.2rem;
  list-style: none;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--key-hover);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.name-list li {
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
}
.name-list li:hover { background: var(--key); color: var(--accent); }
.name-list li.name-add-hint { color: var(--muted); font-style: italic; }
.name-list li.name-add-hint:hover { color: var(--accent); }
.score-num {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1.1;
}
.score-side:first-child .score-num { color: var(--correct); }
.score-side:last-child  .score-num { color: var(--wrong); }
.score-vs {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
}

/* ---- Difficulty bar ---- */
.level-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.level-label {
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.level-btns {
  display: flex;
  gap: 0.35rem;
}
.level-btn {
  padding: 0.22rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--key);
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.level-btn:hover { background: var(--key-hover); color: var(--text); }
.level-btn.active {
  color: var(--accent);
  border-color: var(--accent);
}

/* ---- Status line ---- */
.status {
  font-size: 1.1rem;
  font-weight: 700;
  min-height: 1.6rem;
  margin: 0.25rem 0 0.5rem;
}
.status.win  { color: var(--correct); font-size: 1.5rem; text-shadow: 0 0 16px rgba(74, 222, 128, 0.5); }
.status.loss { color: var(--wrong); }
.status.draw { color: var(--accent); }

/* ---- Board wrap ---- */
.board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0.25rem 0 1rem;
}

/* ---- Drop buttons (checker row above board) ---- */
.drop-btns {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 448px;
  padding: 0 8px;
  margin-bottom: 3px;
}
.drop-btn {
  width: 72%;
  aspect-ratio: 1;
  justify-self: center;
  background: var(--piece-player);
  border: 2px solid #fca5a5;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  transition: background 0.12s, transform 0.12s, box-shadow 0.12s, opacity 0.2s;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.drop-btn:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.75);
  border-color: var(--piece-player);
  transform: scale(1.12);
  box-shadow: 0 0 10px rgba(248, 113, 113, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.drop-btn:disabled {
  opacity: 0;
  cursor: default;
  pointer-events: none;
}

/* ---- Board grid ---- */
.board {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  padding: 8px;
  background: var(--board-blue);
  border-radius: 12px;
  width: 100%;
  max-width: 448px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}

/* ---- Cells ---- */
.cell {
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--bg);
  transition: background 0.12s;
}
.cell.player   { background: var(--piece-player); }
.cell.computer { background: var(--piece-computer); }
.cell.preview  { background: rgba(248, 113, 113, 0.3); }
@keyframes win-flash {
  0%, 100% { filter: brightness(1);   box-shadow: none; }
  50%      { filter: brightness(1.6); box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.5), 0 0 18px rgba(255, 255, 255, 0.35); }
}
.cell.win {
  animation: win-flash var(--flash-duration, 1.65s) ease-in-out infinite;
}

/* ---- New Game button ---- */
.new-game {
  padding: 0.7rem 1.6rem;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  color: #06351a;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: filter 0.15s;
}
.new-game:hover { filter: brightness(1.1); }
