:root {
  --bg: #0d1b2a;
  --bg2: #1b263b;
  --panel: rgba(22, 35, 56, 0.82);
  --text: #edf6f9;
  --muted: #b9d6df;
  --accent: #ffb703;
  --accent2: #fb8500;
  --ok: #80ed99;
  --warn: #ff9f1c;
  --danger: #ff4d6d;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 15% 10%, #243b55 0%, var(--bg) 35%, #08111a 100%);
}

body {
  display: grid;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.app {
  width: min(960px, 100%);
  min-height: min(100vh - 24px, 820px);
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 14px;
  background: linear-gradient(145deg, rgba(10, 24, 43, 0.9), rgba(21, 35, 57, 0.8));
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

h1 {
  margin: 0;
  letter-spacing: 0.16em;
  font-size: clamp(1.3rem, 3vw, 1.9rem);
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
  background: linear-gradient(180deg, var(--accent), var(--accent2));
  color: #121212;
  font-weight: 700;
  cursor: pointer;
}

.btn.secondary {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.hidden {
  display: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn:focus-visible,
.tile:focus-visible,
.board:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid #ffcf5f;
  outline-offset: 2px;
}

.hud {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.stat {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 8px 10px;
  display: grid;
  gap: 2px;
}

.stat.timer-warning {
  border-color: rgba(255, 159, 28, 0.7);
}

.stat.timer-danger {
  border-color: rgba(255, 77, 109, 0.8);
  box-shadow: 0 0 0 2px rgba(255, 77, 109, 0.2);
}

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

.value {
  font-size: 1.2rem;
  font-weight: 700;
}

.board-wrap {
  display: grid;
  align-content: start;
  gap: 12px;
}

.status {
  margin: 0;
  color: var(--muted);
}

.board {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(56px, 1fr));
}

.tile {
  border: 0;
  border-radius: 14px;
  min-height: 68px;
  font-size: clamp(1.05rem, 2vw, 1.25rem);
  font-weight: 700;
  color: var(--text);
  background: linear-gradient(180deg, #2f4f6b, #1d314a);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 180ms ease, filter 120ms ease, box-shadow 180ms ease;
  will-change: transform;
}

.tile:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.tile:hover,
.tile:focus-visible {
  transform: translateY(-2px);
  filter: brightness(1.08);
}

.tile.prefix {
  background: linear-gradient(180deg, #6f1d1b, #432818);
}

.tile.correct {
  outline: 2px solid rgba(128, 237, 153, 0.5);
}

.tile.cursor {
  box-shadow: 0 0 0 3px rgba(255, 207, 95, 0.7), var(--shadow);
}

.tile.reversing {
  animation: reverseFlip 260ms ease;
}

.board.solved {
  animation: solvedGlow 650ms ease;
}

@keyframes reverseFlip {
  0% {
    transform: scale(1) rotateY(0deg);
  }
  50% {
    transform: scale(0.92) rotateY(90deg);
  }
  100% {
    transform: scale(1) rotateY(0deg);
  }
}

@keyframes solvedGlow {
  0% {
    filter: brightness(1);
  }
  45% {
    filter: brightness(1.3);
  }
  100% {
    filter: brightness(1);
  }
}

.controls {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto auto;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 10px;
}

input[type="range"] {
  width: 100%;
}

.dialog {
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 14px;
  background: #12263a;
  color: var(--text);
  max-width: 460px;
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.52);
}

.settings-grid {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.row {
  display: grid;
  gap: 6px;
}

.inline-control {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .tile,
  .board {
    transition: none;
    animation: none;
  }
}

@media (max-width: 900px) {
  .hud {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 680px) {
  .controls {
    grid-template-columns: 1fr;
  }

  .board {
    grid-template-columns: repeat(auto-fit, minmax(48px, 1fr));
  }

  .tile {
    min-height: 60px;
  }
}

\
.win-splash.hidden {
  display: none;
}
.win-splash {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 35%, rgba(255, 183, 3, 0.22), rgba(4, 10, 18, 0.88));
  backdrop-filter: blur(4px);
  z-index: 30;
}

.win-card {
  position: relative;
  min-width: min(88vw, 560px);
  text-align: center;
  padding: 28px 22px 24px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: linear-gradient(160deg, rgba(255, 196, 61, 0.92), rgba(251, 133, 0, 0.92));
  color: #111;
  box-shadow: 0 16px 46px rgba(0, 0, 0, 0.42);
  animation: winPop 420ms cubic-bezier(.2,.9,.2,1) forwards;
  overflow: hidden;
}

.win-kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.76rem;
  opacity: 0.8;
}

#winSplashTitle {
  margin: 8px 0 6px;
  font-size: clamp(2rem, 8vw, 3rem);
  letter-spacing: 0.05em;
}

.win-stats {
  margin: 0 0 14px;
  font-weight: 700;
}

.confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.confetti span {
  position: absolute;
  top: -14%;
  width: 12px;
  height: 20px;
  border-radius: 2px;
  opacity: 0;
  animation: confettiFall 1100ms ease-in forwards;
}

.confetti span:nth-child(odd) { background: #0d1b2a; }
.confetti span:nth-child(even) { background: #edf6f9; }
.confetti span:nth-child(1) { left: 8%; animation-delay: 20ms; }
.confetti span:nth-child(2) { left: 16%; animation-delay: 180ms; }
.confetti span:nth-child(3) { left: 25%; animation-delay: 80ms; }
.confetti span:nth-child(4) { left: 36%; animation-delay: 230ms; }
.confetti span:nth-child(5) { left: 45%; animation-delay: 140ms; }
.confetti span:nth-child(6) { left: 54%; animation-delay: 300ms; }
.confetti span:nth-child(7) { left: 63%; animation-delay: 110ms; }
.confetti span:nth-child(8) { left: 72%; animation-delay: 260ms; }
.confetti span:nth-child(9) { left: 80%; animation-delay: 60ms; }
.confetti span:nth-child(10) { left: 87%; animation-delay: 210ms; }
.confetti span:nth-child(11) { left: 93%; animation-delay: 160ms; }
.confetti span:nth-child(12) { left: 50%; animation-delay: 320ms; }

@keyframes winPop {
  0% { transform: scale(0.84) translateY(12px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

@keyframes confettiFall {
  0% { transform: translateY(-40px) rotate(0deg); opacity: 0; }
  10% { opacity: 1; }
  100% { transform: translateY(400px) rotate(560deg); opacity: 0; }
}

