:root {
  --bg: #0e0f1a;
  --panel: #171a2b;
  --panel-2: #1f2440;
  --text: #eef1ff;
  --muted: #a8b0d7;
  --accent: #ff506b;
  --danger: #ff2f53;
  --tile: #2b3157;
  --tile-selected: #ff506b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

body.high-contrast {
  --bg: #000;
  --panel: #101010;
  --panel-2: #181818;
  --text: #fff;
  --muted: #ddd;
  --accent: #00e5ff;
  --danger: #ff2d55;
  --tile: #222;
  --tile-selected: #00e5ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: radial-gradient(circle at top, #4c1526 0%, var(--bg) 45%);
  color: var(--text);
  min-height: 100vh;
}

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem;
}

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

h1 { margin: 0; }

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, auto));
  gap: 0.5rem;
}

.scoreboard > div,
.pill,
.controls button,
.board {
  background: var(--panel);
  border: 1px solid #5f2e3b;
  border-radius: 12px;
}

.scoreboard > div {
  padding: 0.45rem 0.6rem;
  display: flex;
  flex-direction: column;
}

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

.meta,
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.meta {
  margin-top: 0.75rem;
}

.controls {
  margin: 1rem auto 0;
  justify-content: center;
  width: min(100%, 680px);
}

.pill {
  padding: 0.45rem 0.7rem;
}


.controls button {
  color: var(--text);
  padding: 0.55rem 0.8rem;
  cursor: pointer;
}

.controls button:hover,
.controls button:focus-visible {
  outline: 2px solid var(--accent);
}

.board-wrap {
  margin-top: 1rem;
  display: flex;
  justify-content: center;
  position: relative;
}

.board {
  display: grid;
  grid-template-columns: repeat(6, minmax(42px, 72px));
  gap: 0.4rem;
  padding: 0.6rem;
  box-shadow: var(--shadow);
}

.cell {
  width: min(12vw, 72px);
  height: min(12vw, 72px);
  border-radius: 10px;
  border: 1px solid #6b3445;
  background: var(--tile);
  color: var(--text);
  font-size: clamp(1.15rem, 4.2vw, 1.8rem);
  display: grid;
  place-items: center;
  user-select: none;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, opacity 150ms ease;
}

body.reduced-motion .cell { transition: none; }


.cell.tile-red { background: linear-gradient(160deg, #ff6b7d, #db2e4f); }
.cell.tile-orange { background: linear-gradient(160deg, #ff9b4a, #f0641e); }
.cell.tile-yellow { background: linear-gradient(160deg, #fff3a1, #ffd447); }
.cell.tile-green { background: linear-gradient(160deg, #79e48a, #2fb85a); }
.cell.tile-blue { background: linear-gradient(160deg, #69c3ff, #2d84dd); }
.cell.tile-purple { background: linear-gradient(160deg, #c18bff, #8548db); }

.cell.blank {
  opacity: 0.32;
  background: repeating-linear-gradient(45deg, #3b1a24 0 6px, #31131c 6px 12px);
}

.cell:not(.blank):hover {
  transform: translateY(-1px);
}

.cell.legal {
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.92);
  color: rgba(255, 255, 255, 0.95);
  font-size: clamp(1.05rem, 3.2vw, 1.35rem);
  font-weight: 900;
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
}


.board.invalid {
  animation: shake 180ms ease;
}

.board.end-win {
  animation: endWinPulse 1300ms ease-in-out infinite;
}

.board.end-fail {
  animation: endFailPulse 1300ms ease-in-out infinite;
}

body.reduced-motion .board.invalid {
  animation: flash 150ms ease;
}

body.reduced-motion .board.end-win,
body.reduced-motion .board.end-fail {
  animation: none;
}

@keyframes shake {
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-3px); }
}

@keyframes flash {
  50% { filter: brightness(1.3); }
}

@keyframes endWinPulse {
  0%, 100% { box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3), 0 0 0 rgba(255, 98, 140, 0.0); }
  50% { box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3), 0 0 24px rgba(255, 98, 140, 0.65); filter: saturate(1.12); }
}

@keyframes endFailPulse {
  0%, 100% { box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3), 0 0 0 rgba(160, 50, 76, 0.0); }
  50% { box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3), 0 0 24px rgba(160, 50, 76, 0.65); filter: saturate(0.85); }
}

.completion-toast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  background: linear-gradient(180deg, #ff6a88, #ff3f63);
  color: #fff;
  padding: 0.95rem 1.35rem;
  border-radius: 14px;
  font-weight: 900;
  font-size: clamp(1.05rem, 2.2vw, 1.35rem);
  letter-spacing: 0.02em;
  box-shadow: 0 14px 30px rgba(255, 63, 99, 0.5);
  border: 1px solid rgba(255,255,255,0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
  z-index: 6;
  text-align: center;
  white-space: nowrap;
}

.completion-toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.completion-toast.fail {
  background: linear-gradient(180deg, #7f2a3d, #5b1d2b);
  box-shadow: 0 10px 24px rgba(127, 42, 61, 0.45);
}

body.reduced-motion .completion-toast {
  transition: none;
}

.message {
  min-height: 1.5em;
  margin-top: 0.7rem;
  color: var(--accent);
}

dialog {
  border: 1px solid #6b3445;
  border-radius: 14px;
  padding: 1rem;
  max-width: 540px;
  background: var(--panel-2);
  color: var(--text);
}

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

.help-scroll {
  max-height: min(56vh, 460px);
  overflow-y: auto;
  padding-right: 0.3rem;
  line-height: 1.65;
}

.help-scroll h3 {
  margin: 0.9rem 0 0.35rem;
}

.help-scroll ul {
  margin: 0.2rem 0 0.5rem 1rem;
  padding: 0;
}

.help-scroll li {
  margin-bottom: 0.35rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.dialog-actions button {
  color: var(--text);
  background: var(--panel);
  border: 1px solid #6b3445;
  border-radius: 10px;
  padding: 0.45rem 0.7rem;
  cursor: pointer;
}

@media (max-width: 520px) {

  .controls button { flex: 1 1 calc(50% - 0.5rem); }
}


.footer {
  text-align: center;
  color: var(--muted);
  margin: 1.25rem 0 0.5rem;
  font-size: 0.9rem;
}
