:root {
  color-scheme: dark;
  --bg: #0b1220;
  --panel: #131c2e;
  --text: #dbe4f0;
  --accent: #4a90d9;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid #22304a;
}

h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.credit {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 2px 10px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.diff-group {
  display: flex;
  border: 1px solid #2c3d5e;
  border-radius: 6px;
  overflow: hidden;
}

button {
  background: #1a2740;
  color: var(--text);
  border: 1px solid #2c3d5e;
  padding: 6px 14px;
  font: inherit;
  cursor: pointer;
}

.diff-group button { border: 0; border-right: 1px solid #2c3d5e; }
.diff-group button:last-child { border-right: 0; }
button:hover { background: #243556; }
.diff-group button.active { background: var(--accent); color: #fff; }
#new-game { border-radius: 6px; }
#custom-btn { border-radius: 6px; }
#custom-btn.active { background: var(--accent); color: #fff; }

.custom-wrap { position: relative; }

#custom-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 210px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid #2c3d5e;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
#custom-panel.hidden { display: none; }

#custom-panel label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.9rem;
}

#custom-panel input {
  width: 80px;
  background: #0e1727;
  color: var(--text);
  border: 1px solid #2c3d5e;
  border-radius: 6px;
  padding: 5px 8px;
  font: inherit;
}

#custom-info {
  font-size: 0.8rem;
  color: #8fa3c0;
  min-height: 1em;
}

#custom-play { border-radius: 6px; }
#custom-play:disabled { opacity: 0.45; cursor: default; }

.stat {
  min-width: 84px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  background: #0e1727;
  border: 1px solid #2c3d5e;
  border-radius: 6px;
  padding: 6px 10px;
}

main {
  position: relative;
  flex: 1;
  min-height: 0;
}

#board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#board:active { cursor: grabbing; }

#overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 8, 16, 0.6);
  transition: opacity 0.25s;
}
#overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

#overlay .modal {
  min-width: 300px;
  padding: 30px 44px;
  text-align: center;
  background: var(--panel);
  border: 1px solid #2c3d5e;
  border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.65);
}

#overlay-title {
  font-size: 2.1rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  margin-bottom: 6px;
}
#overlay.won #overlay-title { color: #7bdca8; }
#overlay.lost #overlay-title { color: #ff9a9a; }

#overlay-sub {
  color: #8fa3c0;
  margin-bottom: 20px;
}

#overlay-again {
  border-radius: 6px;
  padding: 9px 26px;
  font-size: 1rem;
}

.hint {
  margin: 0;
  padding: 8px;
  text-align: center;
  font-size: 0.8rem;
  color: #6b7d99;
  background: var(--panel);
  border-top: 1px solid #22304a;
}
