:root {
  --bg: #fff6e5;
  --bg-dots: #ffe9c2;
  --surface: #ffffff;
  --text: #3b2d6b;
  --muted: #7a6f99;
  --line: #e6dcf7;
  --line-strong: #7b61ff;
  --accent: #ff6f59;
  --accent-text: #ffffff;
  --accent-2: #4cb6ff;
  --peer: #fff3d9;
  --same: #ffe38a;
  --selected: #ffd23f;
  --entered: #2f6fe0;
  --bad: #e5484d;
  --bad-soft: #ffe1e1;
  --good: #2fbf71;
  --shadow: 0 4px 0 #e9dcc4;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1830;
    --bg-dots: #241f40;
    --surface: #2a2449;
    --text: #f4efff;
    --muted: #b6acd8;
    --line: #40386b;
    --line-strong: #a796ff;
    --accent: #ff8f73;
    --accent-text: #1b1830;
    --accent-2: #6cc4ff;
    --peer: #352d5c;
    --same: #6a5520;
    --selected: #8a6d12;
    --entered: #8cc0ff;
    --bad: #ff7a7f;
    --bad-soft: #4a2335;
    --good: #4fdc90;
    --shadow: 0 4px 0 #120f22;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--text);
  background-color: var(--bg);
  background-image: radial-gradient(var(--bg-dots) 2px, transparent 2px);
  background-size: 22px 22px;
  font: 600 17px/1.45 "Baloo 2", "Comic Sans MS", system-ui, sans-serif;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.top { text-align: center; padding: 22px 16px 4px; }
.top h1 { margin: 0; font-size: clamp(2rem, 7vw, 2.8rem); font-weight: 800; line-height: 1.1; color: var(--line-strong); }
.logo { display: inline-block; animation: wiggle 3s ease-in-out infinite; }
.tag { margin: 4px 0 0; color: var(--muted); font-size: 1.05rem; }

.layout {
  display: grid;
  gap: 28px;
  max-width: 980px;
  margin: 0 auto;
  padding: 12px 16px;
  justify-items: center;
}
@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(0, 500px) minmax(0, 340px); align-items: start; justify-content: center; }
}

.game { width: 100%; max-width: 500px; }

.levels {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 18px;
  padding: 4px;
}
.levels button { border: 0; background: none; padding: 6px 2px; border-radius: 14px; font-size: 0.98rem; white-space: nowrap; }
.levels button[aria-checked="true"] { background: var(--line-strong); color: #fff; }

.bar { display: flex; justify-content: space-between; align-items: center; margin: 10px 0; gap: 8px; }
.toggles { display: flex; gap: 6px; }
.toggles button {
  border: 2px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 2px 12px;
  font-size: 0.95rem;
}
.toggles button[aria-pressed="true"] { border-color: var(--accent-2); background: color-mix(in srgb, var(--accent-2) 18%, var(--surface)); }
.timer { font-variant-numeric: tabular-nums; font-size: 1.05rem; color: var(--muted); }

.board {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
  width: 100%;
  aspect-ratio: 1;
  background: var(--surface);
  border: 4px solid var(--line-strong);
  border-radius: 20px;
  overflow: hidden;
  user-select: none;
  box-shadow: 0 6px 0 color-mix(in srgb, var(--line-strong) 35%, transparent);
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-right: 2px solid var(--line);
  border-bottom: 2px solid var(--line);
  background: var(--surface);
  color: var(--entered);
  font-size: clamp(1.7rem, 8.5vw, 2.5rem);
  font-weight: 700;
  line-height: 1;
  padding: 0;
  min-width: 0;
  min-height: 0;
  transition: background-color 0.15s;
}
.cell:nth-child(6n) { border-right: 0; }
.cell:nth-child(n + 31) { border-bottom: 0; }
.cell.edge-r { border-right: 4px solid var(--line-strong); }
.cell.edge-b { border-bottom: 4px solid var(--line-strong); }
.cell:focus-visible { outline: 4px solid var(--accent-2); outline-offset: -4px; }

.cell.given { color: var(--text); font-weight: 800; }
.cell.peer { background: var(--peer); }
.cell.same { background: var(--same); }
.cell.selected { background: var(--selected); }
.cell.conflict, .cell.wrong { color: var(--bad); }
.cell.wrong { background: var(--bad-soft); animation: shake 0.35s; }
.cell.pop { animation: pop 0.6s ease; background: color-mix(in srgb, var(--good) 28%, var(--surface)); }
.pictures .cell { font-size: clamp(1.6rem, 8vw, 2.4rem); }

.notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  width: 100%;
  height: 100%;
  padding: 3px;
  font-size: clamp(0.65rem, 2.8vw, 0.95rem);
  color: var(--muted);
}
.notes span { display: flex; align-items: center; justify-content: center; }

.pad { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-top: 18px; }
.pad button {
  border: 2px solid var(--line);
  background: var(--surface);
  border-radius: 16px;
  font-size: 1.9rem;
  font-weight: 800;
  padding: 6px 0;
  color: var(--entered);
  box-shadow: var(--shadow);
  transition: transform 0.08s;
}
.pad button:active { transform: translateY(3px); box-shadow: none; }
.pad button.used { opacity: 0.3; }
.pictures .pad button { font-size: 1.8rem; }

.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.tools button, .dialog-actions button {
  border: 2px solid var(--line);
  background: var(--surface);
  border-radius: 16px;
  padding: 8px 4px;
  font-size: 1rem;
  box-shadow: var(--shadow);
}
.tools button:active, .dialog-actions button:active { transform: translateY(3px); box-shadow: none; }
.tools button[aria-pressed="true"] { border-color: var(--accent-2); background: color-mix(in srgb, var(--accent-2) 18%, var(--surface)); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.status { min-height: 1.6em; margin: 12px 0 0; text-align: center; color: var(--line-strong); font-size: 1.15rem; }

.rules { width: 100%; max-width: 500px; background: var(--surface); border: 2px solid var(--line); border-radius: 22px; padding: 6px 22px 18px; }
.rules h2 { font-size: 1.25rem; margin: 14px 0 4px; color: var(--accent); }
.rules ol, .rules ul { padding-left: 1.3em; margin: 0; font-weight: 500; }
.rules li { margin: 4px 0; }
.rules p { margin: 0; font-weight: 500; }

.foot { text-align: center; color: var(--muted); font-size: 0.95rem; padding: 8px 16px 32px; font-weight: 500; }

dialog {
  border: 3px solid var(--line-strong);
  border-radius: 26px;
  background: var(--surface);
  color: var(--text);
  padding: 20px 24px;
  text-align: center;
  width: min(360px, calc(100vw - 32px));
}
dialog[open] { animation: pop 0.4s ease; }
dialog::backdrop { background: rgb(30 20 60 / 0.45); }
dialog h2 { margin: 0; font-size: 2rem; color: var(--line-strong); }
.win-emoji { font-size: 3.2rem; line-height: 1; }
.stars { font-size: 2.2rem; margin: 4px 0; letter-spacing: 4px; }
.stars .off { filter: grayscale(1); opacity: 0.3; }
#winText { margin: 0; font-weight: 500; }
.dialog-actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }
.dialog-actions button { padding: 8px 16px; }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 10; }
.confetti i {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 14px;
  border-radius: 3px;
  animation: fall linear forwards;
}

@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }
@keyframes pop { 0% { transform: scale(0.85); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@keyframes wiggle { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(-12deg); } 95% { transform: rotate(12deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .confetti { display: none; }
}
