/* ==========================================================================
   Судоку — премиальная тема: тёплая слоновая кость + латунь / полночь + золото
   ========================================================================== */
:root {
  --bg: #f4efe6;
  --surface: #fffdf8;
  --glass: rgba(255, 253, 248, 0.72);
  --text: #1d1a15;
  --muted: #6c6456;
  --line: #e0d8c8;
  --line-strong: #3d372d;
  --accent: #9a6b1f;
  --accent-ink: #7a5214;
  --accent-text: #fffaf0;
  --accent-soft: #f4e7cb;
  --peer: #f6f0e3;
  --same: #ecdcb4;
  --sel: #f0dfb4;
  --given: #1d1a15;
  --user: #2b5a8f;
  --error: #c8362f;
  --error-bg: #fbe1dc;
  --halo: rgba(154, 107, 31, 0.16);
  --wave: #f1d58a;
  --btn-from: #3a342b;
  --btn-to: #1d1a15;
  --btn-text: #f7eed9;
  --orb1: #ecce8f;
  --orb2: #bccce6;
  --shadow: 0 1px 2px rgba(60, 45, 20, 0.08), 0 12px 32px -8px rgba(60, 45, 20, 0.22), 0 36px 64px -24px rgba(60, 45, 20, 0.22);
  --shadow-sm: 0 1px 2px rgba(60, 45, 20, 0.08), 0 6px 16px -6px rgba(60, 45, 20, 0.18);
  --hl-unit: #f4ecdc;
  --hl-digit: #fbe9b8;
  --hl-source: #f5d27a;
  --hl-pattern: #cfdcf2;
  --hl-elim: #f5c9c0;
  --hl-target: #bfe5c8;
  --hl-ring: #1f8a4c;
  --serif: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
  --ease: cubic-bezier(0.22, 0.9, 0.3, 1);
  --spring: cubic-bezier(0.3, 1.5, 0.5, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0d12;
    --surface: #14171e;
    --glass: rgba(24, 28, 37, 0.72);
    --text: #efe9dc;
    --muted: #a29a89;
    --line: #2a2f3b;
    --line-strong: #8a7f68;
    --accent: #e2b862;
    --accent-ink: #e8c26f;
    --accent-text: #1b1406;
    --accent-soft: #2c2615;
    --peer: #1a1e27;
    --same: #35301f;
    --sel: #4a3f22;
    --given: #f1ebdd;
    --user: #8fb8ee;
    --error: #ff8077;
    --error-bg: #3d1f22;
    --halo: rgba(226, 184, 98, 0.12);
    --wave: #6b5620;
    --btn-from: #efca7c;
    --btn-to: #c99a3f;
    --btn-text: #1b1406;
    --orb1: #3a2f14;
    --orb2: #1b2c4d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 16px 40px -8px rgba(0, 0, 0, 0.6), 0 40px 80px -24px rgba(0, 0, 0, 0.6);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5), 0 8px 20px -8px rgba(0, 0, 0, 0.6);
    --hl-unit: #1b212d;
    --hl-digit: #3f3618;
    --hl-source: #66501a;
    --hl-pattern: #263f6e;
    --hl-elim: #5a2a2d;
    --hl-target: #1b5a37;
    --hl-ring: #4ed184;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0b0d12;
  --surface: #14171e;
  --glass: rgba(24, 28, 37, 0.72);
  --text: #efe9dc;
  --muted: #a29a89;
  --line: #2a2f3b;
  --line-strong: #8a7f68;
  --accent: #e2b862;
  --accent-ink: #e8c26f;
  --accent-text: #1b1406;
  --accent-soft: #2c2615;
  --peer: #1a1e27;
  --same: #35301f;
  --sel: #4a3f22;
  --given: #f1ebdd;
  --user: #8fb8ee;
  --error: #ff8077;
  --error-bg: #3d1f22;
  --halo: rgba(226, 184, 98, 0.12);
  --wave: #6b5620;
  --btn-from: #efca7c;
  --btn-to: #c99a3f;
  --btn-text: #1b1406;
  --orb1: #3a2f14;
  --orb2: #1b2c4d;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 16px 40px -8px rgba(0, 0, 0, 0.6), 0 40px 80px -24px rgba(0, 0, 0, 0.6);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5), 0 8px 20px -8px rgba(0, 0, 0, 0.6);
  --hl-unit: #1b212d;
  --hl-digit: #3f3618;
  --hl-source: #66501a;
  --hl-pattern: #263f6e;
  --hl-elim: #5a2a2d;
  --hl-target: #1b5a37;
  --hl-ring: #4ed184;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  overscroll-behavior: none;
  transition: background-color 0.5s var(--ease), color 0.4s var(--ease);
}

/* живой фон: два медленно дрейфующих светлых пятна */
body::before, body::after {
  content: "";
  position: fixed; z-index: -1; pointer-events: none;
  width: 70vmax; height: 70vmax; border-radius: 50%;
  filter: blur(80px); opacity: 0.55;
  will-change: transform;
}
body::before {
  top: -30vmax; left: -20vmax;
  background: radial-gradient(circle, var(--orb1), transparent 65%);
  animation: drift-a 26s ease-in-out infinite alternate;
}
body::after {
  bottom: -35vmax; right: -25vmax;
  background: radial-gradient(circle, var(--orb2), transparent 65%);
  animation: drift-b 32s ease-in-out infinite alternate;
}
@keyframes drift-a { to { transform: translate(18vmax, 14vmax) scale(1.15); } }
@keyframes drift-b { to { transform: translate(-16vmax, -12vmax) scale(1.1); } }

button { font: inherit; color: inherit; touch-action: manipulation; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  min-height: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; animation: rise 0.7s var(--ease) both; }
.top h1 {
  margin: 0; display: flex; align-items: center; gap: 10px;
  font-family: var(--serif); font-size: 26px; font-weight: 600; letter-spacing: 0.04em;
}
.top h1 span:last-child {
  background: linear-gradient(100deg, var(--text) 20%, var(--accent) 50%, var(--text) 80%);
  background-size: 220% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 7s ease-in-out infinite;
}
@keyframes shimmer { 0%, 100% { background-position: 100% 0; } 50% { background-position: 0 0; } }

.logo {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 2.5px;
  width: 30px; height: 30px; padding: 4px; border-radius: 9px;
  background: linear-gradient(145deg, var(--btn-from), var(--btn-to));
  box-shadow: var(--shadow-sm);
}
.logo i { border-radius: 2px; background: var(--btn-text); opacity: 0.35; animation: logo-pulse 3.6s ease-in-out infinite; }
.logo i:nth-child(5) { opacity: 1; animation: none; }
.logo i:nth-child(2) { animation-delay: 0.2s; } .logo i:nth-child(3) { animation-delay: 0.4s; }
.logo i:nth-child(4) { animation-delay: 0.6s; } .logo i:nth-child(6) { animation-delay: 0.8s; }
.logo i:nth-child(7) { animation-delay: 1s; }   .logo i:nth-child(8) { animation-delay: 1.2s; }
.logo i:nth-child(9) { animation-delay: 1.4s; }
@keyframes logo-pulse { 0%, 70%, 100% { opacity: 0.3; } 35% { opacity: 0.9; } }

.top-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 42px; min-width: 42px; padding: 0 11px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--glass); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-sm); cursor: pointer;
  transition: transform 0.25s var(--spring), border-color 0.2s, box-shadow 0.2s;
}
.icon-btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.icon-btn:active { transform: scale(0.94); }
#themeBtn svg { transition: transform 0.6s var(--ease); }
#themeBtn:hover svg { transform: rotate(180deg); }
.text-btn { font-size: 14px; }

.primary-btn {
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 42px; padding: 0 16px;
  border: 0; border-radius: 14px;
  background: linear-gradient(160deg, var(--btn-from), var(--btn-to));
  color: var(--btn-text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), var(--shadow-sm);
  font-weight: 650; letter-spacing: 0.01em; cursor: pointer; white-space: nowrap;
  transition: transform 0.25s var(--spring), box-shadow 0.25s;
}
.primary-btn::after {  /* блик */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.35) 50%, transparent 65%);
  transform: translateX(-120%);
}
.primary-btn:hover::after { transform: translateX(120%); transition: transform 0.7s var(--ease); }
.primary-btn:hover { transform: translateY(-1px); }
.primary-btn:active { transform: scale(0.96); }
.primary-btn svg { width: 18px; height: 18px; stroke-width: 2.5; transition: transform 0.4s var(--spring); }
.primary-btn:hover svg { transform: rotate(90deg); }

.ghost-btn {
  height: 42px; padding: 0 18px; border-radius: 14px;
  border: 1px solid var(--line); background: transparent; cursor: pointer;
  transition: transform 0.2s var(--spring), border-color 0.2s, background-color 0.2s;
}
.ghost-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.ghost-btn:active { transform: scale(0.96); }

/* ---------- layout ---------- */
.layout { display: flex; flex-direction: column; gap: 14px; align-items: center; flex: 1; }
.board-area, .controls { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }

.board-area { --size: max(260px, min(100vw - 28px, 100dvh - 405px, 560px)); animation: rise 0.8s 0.08s var(--ease) both; }
.controls { max-width: 560px; animation: rise 0.8s 0.18s var(--ease) both; }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.status {
  width: var(--size);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 14px; color: var(--muted);
}
.status b { color: var(--text); font-variant-numeric: tabular-nums; display: inline-block; }
.status b.bump { animation: bump 0.5s var(--spring); }
@keyframes bump { 40% { transform: scale(1.5); color: var(--error); } }
.pill {
  padding: 5px 14px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-ink);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  font-weight: 650; font-size: 13px; letter-spacing: 0.03em;
}
.timer { font-family: var(--serif); font-size: 17px; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); min-width: 60px; text-align: right; }

/* ---------- board ---------- */
.board-frame {
  position: relative;
  width: var(--size); height: var(--size);
  border: 2px solid var(--line-strong);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 0 0 6px var(--halo), var(--shadow);
  overflow: hidden;
}
/* мягкий стеклянный блик поверх поля */
.board-frame::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 3;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.16), transparent 38%);
}

#board {
  --cell: calc(var(--size) / 9);
  width: 100%; height: 100%;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  user-select: none; -webkit-user-select: none;
}

/* плавающая рамка выбора: скользит от клетки к клетке */
.cursor {
  position: absolute; z-index: 2; left: 0; top: 0;
  width: calc(100% / 9); height: calc(100% / 9);
  border: 2.5px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent), 0 0 18px color-mix(in srgb, var(--accent) 45%, transparent);
  pointer-events: none;
  transition: transform 0.26s var(--ease), opacity 0.2s;
  animation: cursor-glow 2.4s ease-in-out infinite;
}
.cursor.off { opacity: 0; animation: none; }
@keyframes cursor-glow { 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 12%, transparent), 0 0 26px color-mix(in srgb, var(--accent) 60%, transparent); } }

.cell {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  background: var(--surface);
  transition: background-color 0.22s var(--ease);
}
.cell.c-right { border-right: 2px solid var(--line-strong); }
.cell.c-bottom { border-bottom: 2px solid var(--line-strong); }
.cell.col-last { border-right: 0; }
.cell.row-last { border-bottom: 0; }
@media (hover: hover) { .cell:hover { background: var(--peer); } }

.cell.peer { background: var(--peer); }
.cell.same { background: var(--same); }
.cell.selected { background: var(--sel); }

.val {
  font-family: var(--serif);
  font-size: calc(var(--cell) * 0.6);
  line-height: 1;
  font-weight: 500;
  color: var(--user);
  will-change: transform;
}
.cell.given .val { color: var(--given); font-weight: 700; }
.cell.wrong .val { color: var(--error); }
.cell.wrong { background: var(--error-bg); }
.cell.wrong.selected { background: var(--error-bg); }

.notes {
  position: absolute; inset: 2px;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  pointer-events: none;
}
.notes i {
  display: flex; align-items: center; justify-content: center;
  font-style: normal;
  font-size: calc(var(--cell) * 0.27);
  line-height: 1;
  color: transparent;
  margin: 0.5px;
  border-radius: 4px;
  transition: background-color 0.2s, color 0.2s;
}
.notes i.on { color: var(--muted); animation: note-in 0.25s var(--spring); }
.notes i.on.hl { background: var(--accent); color: var(--accent-text); font-weight: 700; }
@keyframes note-in { from { transform: scale(0.3); opacity: 0; } }
.cell.has-value .notes { display: none; }

/* ---------- controls ---------- */
.toolbar { width: 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }

.tool {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  min-height: 60px; padding: 7px 4px;
  border: 1px solid var(--line); border-radius: 16px;
  background: var(--glass); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-sm); cursor: pointer;
  font-size: 12px; font-weight: 550; color: var(--text);
  transition: transform 0.25s var(--spring), border-color 0.2s, background-color 0.25s, color 0.25s, box-shadow 0.25s;
}
.tool svg { transition: transform 0.35s var(--spring); }
.tool:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-2px); }
.tool:hover:not(:disabled) svg { transform: scale(1.15) rotate(-6deg); }
.tool:active:not(:disabled) { transform: scale(0.95); }
.tool:disabled { opacity: 0.4; cursor: default; box-shadow: none; }
.tool[aria-pressed="true"] { background: linear-gradient(160deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #000)); color: var(--accent-text); border-color: var(--accent); }
.badge {
  position: absolute; top: 5px; right: 7px;
  font-style: normal; font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-ink);
}
.tool[aria-pressed="true"] .badge { background: var(--accent-text); color: var(--accent); }

#hintBtn:not(:disabled) svg { animation: bulb 4s ease-in-out infinite; transform-origin: 50% 90%; }
@keyframes bulb { 0%, 80%, 100% { transform: none; } 88% { transform: rotate(-12deg) scale(1.1); } 94% { transform: rotate(10deg) scale(1.1); } }

.auto-btn {
  position: relative; overflow: hidden;
  width: 100%; min-height: 50px; padding: 8px 14px;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  border: 1.5px dashed color-mix(in srgb, var(--accent) 60%, transparent); border-radius: 16px;
  background: var(--accent-soft); color: var(--accent-ink);
  font-weight: 650; font-size: 14px; text-align: left; cursor: pointer;
  transition: transform 0.25s var(--spring), background-color 0.25s, color 0.25s, border-color 0.25s;
}
.auto-btn svg { transition: transform 0.4s var(--spring); }
.auto-btn:hover:not(:disabled) { background: var(--accent); color: var(--accent-text); border-style: solid; transform: translateY(-1px); }
.auto-btn:hover:not(:disabled) svg { transform: scale(1.25) rotate(-10deg); }
.auto-btn:active:not(:disabled) { transform: scale(0.98); }
.auto-btn:disabled { opacity: 0.4; cursor: default; }

.numpad { width: 100%; display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; }
.num {
  position: relative; overflow: hidden;
  height: clamp(72px, 19vw, 92px);
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--glass); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-sm); cursor: pointer;
  font-family: var(--serif);
  font-size: clamp(30px, 9.5vw, 42px); font-weight: 500; color: var(--user);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 7px 0 0; line-height: 1;
  transition: transform 0.25s var(--spring), border-color 0.2s, background-color 0.2s, opacity 0.3s;
}
.num:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-3px); }
.num:active:not(:disabled) { transform: scale(0.92); }
.num:disabled { opacity: 0.25; cursor: default; box-shadow: none; transform: scale(0.96); }
.num small {
  position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%);
  min-width: 22px; padding: 2px 6px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: clamp(13px, 3.8vw, 16px); font-weight: 700; line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.num small:empty { display: none; }
.numpad.notes-mode .num { color: var(--muted); }

/* ---------- smart hints ---------- */
.cell.h-unit { background: var(--hl-unit); }
.cell.h-digit { background: var(--hl-digit); }
.cell.h-source { background: var(--hl-source); }
.cell.h-pattern { background: var(--hl-pattern); }
.cell.h-elim { background: var(--hl-elim); }
.cell.h-target { background: var(--hl-target); box-shadow: inset 0 0 0 3px var(--hl-ring); animation: target-pulse 1.6s ease-in-out infinite; }
.cell.h-bad { background: var(--error-bg); box-shadow: inset 0 0 0 3px var(--error); animation: bad-pulse 1.2s ease-in-out infinite; }
@keyframes target-pulse { 50% { box-shadow: inset 0 0 0 5px var(--hl-ring), inset 0 0 18px var(--hl-ring); } }
@keyframes bad-pulse { 50% { box-shadow: inset 0 0 0 5px var(--error), inset 0 0 18px var(--error); } }
.cell.ghost .val { color: var(--hl-ring); font-weight: 700; }
.marks { position: absolute; inset: 2px; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.marks:empty { display: none; }
.marks > span { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 2px; }
.marks i {
  font-style: normal; font-weight: 700; line-height: 1;
  font-size: calc(var(--cell) * 0.36); padding: 2px 3px; border-radius: 5px;
  background: var(--accent); color: var(--accent-text);
  animation: note-in 0.3s var(--spring) both;
}
.marks i.rm { background: var(--error); color: #fff; text-decoration: line-through; }
.marks .many i { font-size: calc(var(--cell) * 0.27); padding: 1px 2px; }

.hint-card {
  position: relative; overflow: hidden;
  width: 100%;
  background: var(--glass); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 16px 16px;
  box-shadow: var(--shadow);
  animation: card-in 0.5s var(--spring) both;
}
.hint-card::before {  /* золотая полоса сверху */
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 200% 100%; animation: sweep 3s linear infinite;
}
@keyframes sweep { to { background-position: -200% 0; } }
@keyframes card-in { from { opacity: 0; transform: translateY(18px) scale(0.97); } to { opacity: 1; transform: none; } }
.hint-card[hidden] { display: none; }
.hint-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.hint-title { font-family: var(--serif); font-weight: 700; font-size: 19px; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.hint-title .step {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-ink);
}
.hint-x {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; flex: none; padding: 0;
  border: 0; border-radius: 10px; background: transparent; cursor: pointer; color: var(--muted);
  transition: background-color 0.2s, color 0.2s, transform 0.3s var(--spring);
}
.hint-x:hover { background: var(--peer); color: var(--text); transform: rotate(90deg); }
.hint-text { margin: 0 0 10px; font-size: 15.5px; line-height: 1.5; }
.hint-text b { font-weight: 700; white-space: nowrap; }
.hint-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 12px; font-size: 12.5px; color: var(--muted); }
.hint-legend[hidden] { display: none; }
.hint-legend i {
  display: inline-block; width: 13px; height: 13px; margin-right: 5px; border-radius: 4px;
  vertical-align: -2px; border: 1px solid rgba(120, 130, 150, 0.45);
}
.lg-target { background: var(--hl-target); box-shadow: inset 0 0 0 2px var(--hl-ring); }
.lg-bad { background: var(--error-bg); box-shadow: inset 0 0 0 2px var(--error); }
.lg-pattern { background: var(--hl-pattern); }
.lg-elim { background: var(--hl-elim); }
.lg-source { background: var(--hl-source); }
.lg-digit { background: var(--hl-digit); }
.lg-unit { background: var(--hl-unit); }
.hint-actions { display: flex; gap: 8px; }
.hint-actions button { flex: 1; height: 46px; justify-content: center; font-size: 15px; }
.hint-actions button[hidden] { display: none; }

/* while a hint is open the input controls give way to the explanation */
.controls.hinting .toolbar,
.controls.hinting .auto-btn,
.controls.hinting .numpad { display: none; }

/* ---------- overlays ---------- */
.busy {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  font-family: var(--serif); font-size: 17px; letter-spacing: 0.03em;
  animation: fade 0.25s both;
}
.busy[hidden] { display: none; }
.loader { display: grid; grid-template-columns: repeat(3, 14px); gap: 5px; }
.loader i { height: 14px; border-radius: 4px; background: var(--accent); animation: load 1.2s ease-in-out infinite; }
.loader i:nth-child(1) { animation-delay: 0s; }   .loader i:nth-child(2) { animation-delay: 0.1s; } .loader i:nth-child(3) { animation-delay: 0.2s; }
.loader i:nth-child(4) { animation-delay: 0.1s; } .loader i:nth-child(5) { animation-delay: 0.2s; } .loader i:nth-child(6) { animation-delay: 0.3s; }
.loader i:nth-child(7) { animation-delay: 0.2s; } .loader i:nth-child(8) { animation-delay: 0.3s; } .loader i:nth-child(9) { animation-delay: 0.4s; }
@keyframes load { 0%, 60%, 100% { transform: scale(0.45); opacity: 0.25; } 30% { transform: scale(1); opacity: 1; } }
@keyframes fade { from { opacity: 0; } }

.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom));
  transform: translate(-50%, 24px) scale(0.95);
  max-width: calc(100vw - 32px);
  padding: 11px 18px; border-radius: 14px;
  background: var(--text); color: var(--bg);
  box-shadow: var(--shadow);
  font-size: 14px; font-weight: 550; opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.4s var(--spring); z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

dialog {
  width: min(92vw, 430px);
  border: 1px solid var(--line); border-radius: 24px; padding: 24px;
  background: var(--surface); color: var(--text);
  box-shadow: 0 0 0 6px var(--halo), 0 30px 80px rgba(0, 0, 0, 0.4);
}
dialog[open] { animation: dialog-in 0.5s var(--spring); }
dialog[open]::backdrop { animation: fade 0.35s both; }
dialog::backdrop { background: rgba(10, 8, 4, 0.5); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(24px) scale(0.92); } }
dialog h2 { margin: 0 0 6px; font-family: var(--serif); font-size: 24px; font-weight: 600; letter-spacing: 0.02em; }
.muted { color: var(--muted); margin: 0 0 14px; font-size: 14px; line-height: 1.45; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.level-list { display: flex; flex-direction: column; gap: 8px; }
.level-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  padding: 12px 16px; border: 1px solid var(--line); border-radius: 16px;
  background: var(--surface); cursor: pointer; text-align: left;
  transition: transform 0.25s var(--spring), border-color 0.2s, background-color 0.2s, box-shadow 0.2s;
  animation: rise 0.5s var(--ease) both;
}
.level-btn:nth-child(1) { animation-delay: 0.05s; } .level-btn:nth-child(2) { animation-delay: 0.1s; }
.level-btn:nth-child(3) { animation-delay: 0.15s; } .level-btn:nth-child(4) { animation-delay: 0.2s; }
.level-btn:nth-child(5) { animation-delay: 0.25s; }
.level-btn:hover { border-color: var(--accent); background: var(--accent-soft); transform: translateX(4px); box-shadow: var(--shadow-sm); }
.level-btn:active { transform: scale(0.98); }
.level-btn.current { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.level-btn b { font-family: var(--serif); font-size: 17px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.level-btn span { font-size: 13px; color: var(--muted); line-height: 1.35; }
.level-btn b .stars { color: var(--accent); }
.stars { letter-spacing: 2px; font-size: 12px; font-family: system-ui, sans-serif; }

.win-mark {
  width: 64px; height: 64px; margin: 0 auto 10px; display: block;
  stroke: var(--accent); stroke-width: 2.4;
}
.win-mark circle { stroke-dasharray: 160; stroke-dashoffset: 160; animation: draw 0.9s 0.1s var(--ease) forwards; }
.win-mark path { stroke-dasharray: 40; stroke-dashoffset: 40; animation: draw 0.5s 0.8s var(--ease) forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
#winDialog h2, #winDialog .muted { text-align: center; }

.confetti { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 100; pointer-events: none; }

/* ---------- wide screens: board on the left, controls on the right ---------- */
@media (min-width: 860px) and (orientation: landscape) {
  .layout { flex-direction: row; justify-content: center; align-items: flex-start; gap: 40px; padding-top: 6px; }
  .board-area { width: auto; --size: max(300px, min(100dvh - 150px, 100vw - 460px, 680px)); }
  .controls { width: 420px; padding-top: 40px; }
  .num { height: 76px; }
}

/* short landscape phones */
@media (max-height: 520px) and (orientation: landscape) {
  .top h1 { display: none; }
  .layout { flex-direction: row; justify-content: center; align-items: flex-start; gap: 16px; }
  .board-area { width: auto; --size: max(220px, min(100dvh - 90px, 100vw - 360px)); }
  .controls { width: 330px; }
  .tool { min-height: 46px; }
  .num { height: 52px; font-size: 26px; padding-top: 4px; }
  .num small { font-size: 11px; bottom: 3px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
  body::before, body::after { animation: none; }
}
