:root {
  --bg: #191715;
  --bg-2: #211d1c;
  --bg-3: #2a2523;
  --line: #3a3532;
  --text: #F1ECEC;
  --muted: #a49c98;
  --faint: #6f6763;
  --accent: #F5B84E;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --cols: 6;
  --rows: 6;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: var(--font-ui);
  background:
    radial-gradient(900px 560px at 50% -10%, #2b2622, transparent 70%),
    var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: auto;
  min-height: 100dvh;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
  border: none;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- topbar ---------- */

.topbar {
  width: 100%;
  max-width: 860px;
  padding: 14px 16px 4px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.back {
  font-family: var(--font-mono);
  font-size: .82rem;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 9px;
  border: 1px solid transparent;
  transition: color .15s, border-color .15s, background .15s;
}

.back:hover {
  color: var(--text);
  background: var(--bg-2);
  border-color: var(--line);
}

.topbar h1 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: .02em;
}

.select-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.nav-select {
  appearance: none;
  -webkit-appearance: none;
  font-family: var(--font-mono);
  font-size: .8rem;
  letter-spacing: .02em;
  color: var(--text);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23a49c98' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center,
    var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 32px 8px 12px;
  cursor: pointer;
  max-width: 190px;
  transition: border-color .15s, filter .15s;
}

.nav-select:hover {
  border-color: var(--faint);
  filter: brightness(1.08);
}

.nav-select:focus-visible {
  outline: 2px dashed var(--accent);
  outline-offset: 3px;
}

.nav-select option {
  background: var(--bg-2);
  color: var(--text);
}

.diff-label {
  font-family: var(--font-mono);
  font-size: .8rem;
  color: var(--muted);
  margin-right: 8px;
  white-space: nowrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- action buttons ---------- */

#newGame,
#playAgain,
.minor-btn {
  background: var(--accent);
  color: #1a1613;
  font-weight: 700;
  font-size: .92rem;
  padding: 10px 20px;
  border-radius: 12px;
  box-shadow: 0 6px 22px rgba(245, 184, 78, .35);
  transition: transform .1s, filter .15s;
}

.minor-btn {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--muted);
  background: var(--bg-2);
  box-shadow: none;
  font-family: var(--font-mono);
  font-size: .75rem;
}

.minor-btn:disabled {
  cursor: default;
  opacity: .38;
}

#playAgain {
  font-size: .98rem;
  padding: 11px 26px;
}

#newGame:hover,
#playAgain:hover,
.minor-btn:not(:disabled):hover {
  filter: brightness(1.08);
}

#newGame:active,
#playAgain:active {
  transform: scale(.96);
}

/* ---------- layout ---------- */

.layout {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
}

.hint {
  font-family: var(--font-mono);
  font-size: .76rem;
  letter-spacing: .02em;
  color: var(--faint);
  text-align: center;
  padding: 0 12px;
}

.hud {
  display: flex;
  gap: 20px;
  font-family: var(--font-mono);
  font-size: .82rem;
  color: var(--muted);
}

.hud b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* ---------- board ---------- */

.board-wrap {
  position: relative;
}

#board {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  gap: 6px;
  width: min(84vw, 400px);
  aspect-ratio: 1;
  background: #0c0a09;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .5), inset 0 0 0 1px rgba(255, 255, 255, .03);
  touch-action: none;
}

.block {
  border-radius: 10px;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  background: hsl(var(--h) 24% 38%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .14), 0 3px 10px rgba(0, 0, 0, .4);
  transition: filter .1s;
}

.block:hover {
  filter: brightness(1.12);
}

.block:active {
  cursor: grabbing;
  filter: brightness(1.22);
}

.block.hinted {
  filter: brightness(1.35);
  outline: 3px solid var(--accent);
  outline-offset: -3px;
  animation: hintPulse .7s ease-in-out infinite alternate;
}

@keyframes hintPulse {
  to { box-shadow: inset 0 0 0 2px #fff5, 0 0 22px rgba(245, 184, 78, .75); }
}

.block.red {
  background: hsl(12 45% 40%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .16), 0 4px 18px rgba(0, 0, 0, .5);
}

.exit {
  position: absolute;
  right: -20px;
  top: var(--exitTop, 50%);
  transform: translateY(-50%);
  width: 15px;
  height: calc(100% / var(--rows) - 12px);
  border: 1.5px solid var(--accent);
  border-left: none;
  border-radius: 0 7px 7px 0;
  opacity: .8;
}

/* ---------- win overlay ---------- */

.win-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 8, 7, .82);
  backdrop-filter: blur(4px);
  z-index: 50;
  padding: 16px;
}

.win-overlay.hidden {
  display: none;
}

.win-box {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 32px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
  max-width: 340px;
  animation: pop .25s ease;
}

@keyframes pop {
  from {
    transform: scale(.92);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .win-box {
    animation: none;
  }
}

.win-box h2 {
  font-size: 1.6rem;
  margin-bottom: 8px;
  color: var(--accent);
}

.win-box p {
  color: var(--muted);
  margin-bottom: 18px;
}

.stars {
  margin: -5px 0 18px;
  color: var(--accent);
  font-size: 1.8rem;
  letter-spacing: .14em;
  text-shadow: 0 0 16px rgba(245, 184, 78, .42);
}

/* ---------- mobile ---------- */

@media (max-width: 760px) {
  .topbar {
    padding: 10px 12px 4px;
  }

  .nav-select {
    max-width: 150px;
    font-size: .74rem;
    padding: 7px 28px 7px 10px;
  }
}
