:root {
  color-scheme: light;
  --ink: #202d29;
  --muted: #7c8983;
  --paper: #f5f6f2;
  --card: #fff;
  --line: #e8ece7;
  --green: #317b63;
  --green-dark: #286b55;
  --mint: #e9f4ee;
  --coral: #e78372;
  --red: #cf5d56;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 9% 4%, rgba(226, 239, 229, .7), transparent 27rem),
    var(--paper);
  color: var(--ink);
}

button { color: inherit; font: inherit; }

.app-shell { width: min(1120px, calc(100% - 64px)); margin: 0 auto; }
.topbar { height: 84px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(49, 73, 60, .09); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font: 800 23px "Avenir Next", "Segoe UI", sans-serif; letter-spacing: -1.3px; }
.brand-period { color: var(--coral); }
.brand-mark { display: grid; grid-template-columns: repeat(2, 8px); grid-template-rows: repeat(2, 8px); gap: 3px; transform: rotate(-8deg); }
.brand-mark span { border-radius: 2px; background: var(--green); }
.brand-mark span:nth-child(2), .brand-mark span:nth-child(3) { opacity: .46; }
.topbar-note { display: flex; gap: 8px; align-items: center; color: #7f8b84; font-size: 13px; }
.language-switch { display: flex; gap: 2px; padding: 3px; border: 1px solid #e2e8e2; border-radius: 8px; background: rgba(255,255,255,.72); }
.language-switch button { min-width: 31px; padding: 4px 6px; border: 0; border-radius: 5px; background: transparent; color: #87928b; font-size: 10px; font-weight: 700; cursor: pointer; }
.language-switch button[aria-pressed="true"] { background: var(--green); color: #fff; }
.language-switch button:focus-visible { outline: 2px solid #7ab38a; outline-offset: 2px; }
.sparkle { color: #d9a765; font-size: 18px; }
.icon-button { width: 34px; height: 34px; border: 1px solid #e2e8e2; border-radius: 50%; background: transparent; color: #7f8b84; font-weight: 700; cursor: pointer; transition: .2s ease; }
.icon-button:hover { color: var(--green); border-color: var(--green); background: #fff; }

.intro { padding: 46px 0 30px; }
.eyebrow { margin: 0 0 10px; color: var(--green); font-size: 10px; font-weight: 700; letter-spacing: 1.65px; }
h1, h2, p { margin-top: 0; }
h1, h2 { font-family: "Avenir Next", "Segoe UI", sans-serif; }
h1 { margin-bottom: 10px; font-size: clamp(30px, 4vw, 42px); line-height: 1.18; letter-spacing: -1.8px; font-weight: 700; }
.intro-copy { margin: 0; color: var(--muted); font-size: 15px; }
.mobile-break { display: none; }

.game-layout { display: grid; grid-template-columns: minmax(0, 620px) minmax(260px, 1fr); align-items: start; gap: 38px; }
.board-card { padding: 24px 29px 20px; border: 1px solid rgba(42, 70, 54, .07); border-radius: 18px; background: var(--card); box-shadow: 0 14px 42px rgba(43, 63, 49, .055); }
.board-topline { display: flex; justify-content: space-between; align-items: center; margin-bottom: 19px; }
.game-label, .stats, .stat { display: flex; align-items: center; }
.game-label { gap: 8px; color: #77837d; font-size: 12px; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: #83bd94; box-shadow: 0 0 0 3px #eef7ef; }
.stats { gap: 14px; font-size: 12px; color: #748078; }
.stat { gap: 5px; min-width: 35px; }
.stat-icon { font-size: 17px; }
.clock-icon { color: #6f9d7d; }
.error-icon { color: #e19b76; font-size: 12px; }
.stat-divider { height: 15px; border-left: 1px solid #e8ece7; }
.board-wrap { width: min(100%, 510px); margin: 0 auto; padding: 6px; border-radius: 8px; background: #305c4b; }
.sudoku-board { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); border: 1px solid #305c4b; background: #fff; }
.cell {
  position: relative;
  display: flex;
  min-width: 0;
  aspect-ratio: 1;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-right: 1px solid #dfe6e1;
  border-bottom: 1px solid #dfe6e1;
  background: #fff;
  color: #357c63;
  font-size: clamp(15px, 2.35vw, 24px);
  font-weight: 500;
  cursor: pointer;
  transition: background-color .12s ease, color .12s ease;
  -webkit-tap-highlight-color: transparent;
}
.cell:nth-child(9n) { border-right: 0; }
.cell:nth-child(n+73) { border-bottom: 0; }
.cell:nth-child(3n) { border-right: 2px solid #a9c0b1; }
.cell:nth-child(9n) { border-right: 0; }
.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid #a9c0b1; }
.cell.given { color: #293b33; font-weight: 700; }
.cell.related { background: #f1f7f2; }
.cell.same-number { background: #e1f0e6; color: #286b55; font-weight: 700; }
.cell.selected { z-index: 1; background: #d9eee0; box-shadow: inset 0 0 0 2px #5eaa7e; }
.cell.error { background: #fff0ed; color: var(--red); }
.cell.error.selected { box-shadow: inset 0 0 0 2px #df8378; }
.cell:focus-visible { z-index: 2; outline: 2px solid #317b63; outline-offset: -2px; }
.notes-grid { display: grid; width: 100%; height: 100%; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); align-items: center; justify-items: center; color: #82928a; font-size: clamp(6px, 1.1vw, 10px); line-height: 1; }
.number-pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 7px; width: min(100%, 510px); margin: 17px auto 0; }
.number-pad button { aspect-ratio: 1.25; padding: 0; border: 1px solid #e2ece4; border-radius: 7px; background: #f6faf6; color: #34785f; font: 600 18px "Avenir Next", "Segoe UI", sans-serif; cursor: pointer; transition: .16s ease; }
.number-pad button:hover { border-color: #9dc4a8; background: #eaf4ec; transform: translateY(-1px); }
.number-pad button:disabled { opacity: .36; cursor: default; transform: none; }
.board-actions { display: flex; justify-content: center; gap: clamp(15px, 5vw, 42px); margin-top: 17px; }
.text-action { display: inline-flex; gap: 6px; align-items: center; padding: 5px 2px; border: 0; background: transparent; color: #77847d; font-size: 12px; cursor: pointer; transition: color .15s ease; }
.text-action > span[aria-hidden="true"] { font-size: 16px; }
.text-action:hover, .text-action[aria-pressed="true"] { color: var(--green); }

.side-panel { padding-top: 7px; }
.panel-section { padding: 2px 0 0; }
.section-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 19px; }
.section-heading .eyebrow { margin-bottom: 5px; }
.section-heading h2 { margin: 0; font-size: 20px; line-height: 1.25; letter-spacing: -.6px; }
.heading-sparkle { color: #e2b772; font-size: 19px; }
.difficulty-list { display: grid; gap: 8px; }
.difficulty-option { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 65px; padding: 10px 13px; border: 1px solid #e9ece7; border-radius: 10px; background: rgba(255,255,255,.8); text-align: left; cursor: pointer; transition: .18s ease; }
.difficulty-option:hover { border-color: #b6d2bc; transform: translateY(-1px); }
.difficulty-option.active { border-color: #79ae89; background: #eff7f0; box-shadow: 0 0 0 2px rgba(93, 158, 111, .08); }
.difficulty-emoji { display: grid; width: 34px; height: 34px; flex: 0 0 auto; place-items: center; border-radius: 9px; background: #f5f7f0; font-size: 16px; }
.difficulty-copy { display: grid; flex: 1; gap: 3px; }
.difficulty-copy strong { font-size: 12px; font-weight: 700; }
.difficulty-copy small { color: #8b958f; font-size: 10px; }
.option-indicator { width: 14px; height: 14px; border: 1.5px solid #d5ddd6; border-radius: 50%; }
.active .option-indicator { border: 4px solid var(--green); background: #fff; }
.new-game-button { display: flex; min-height: 45px; justify-content: center; align-items: center; gap: 8px; width: 100%; margin-top: 15px; border: 0; border-radius: 8px; background: var(--green); color: white; font-size: 13px; font-weight: 600; cursor: pointer; transition: background .18s ease, transform .18s ease; }
.new-game-button:hover { background: var(--green-dark); transform: translateY(-1px); }
.new-game-button > span:first-child { font-size: 19px; line-height: 1; }
.tip-card { display: flex; gap: 12px; margin-top: 23px; padding: 15px; border: 1px solid #eee6d9; border-radius: 10px; background: #fbf8f1; }
.tip-icon { color: #d6a35e; font-size: 18px; }
.tip-card strong { font-size: 11px; }
.tip-card p { margin: 5px 0 0; color: #85867c; font-size: 10px; line-height: 1.6; }
.keyboard-hint { margin: 18px 0 0; color: #9aa29c; font-size: 10px; line-height: 1.6; }
kbd { display: inline-grid; min-width: 17px; height: 18px; place-items: center; margin: 0 2px; padding: 0 4px; border: 1px solid #e2e7e2; border-radius: 4px; background: #fff; color: #67746c; font: 10px "Avenir Next", "Segoe UI", sans-serif; }
.page-footer { display: grid; grid-template-columns: 1fr auto; gap: 10px 20px; align-items: center; padding: 28px 0 22px; color: #99a29c; font-size: 10px; }
.footer-author { display: flex; align-items: center; gap: 4px; }
.footer-author a { color: #6d7e73; font-weight: 600; text-decoration-color: #b7c5bb; text-underline-offset: 2px; }
.footer-author a:hover { color: var(--green); }
.footer-tagline { text-align: right; }
.footer-details { display: grid; grid-column: 1 / -1; grid-template-columns: max-content 1fr; gap: 18px; align-items: baseline; padding-top: 12px; border-top: 1px solid rgba(49, 73, 60, .09); }
.ai-credit { color: #8d9991; white-space: nowrap; }
.privacy-note { max-width: 820px; margin: 0; color: #87938b; line-height: 1.6; }
.heart { color: var(--coral); }
.toast { position: fixed; z-index: 5; bottom: 22px; left: 50%; max-width: calc(100% - 32px); padding: 11px 18px; border: 1px solid rgba(255,255,255,.1); border-radius: 9px; background: #253b31; color: #fff; box-shadow: 0 8px 24px #1c312b30; font-size: 13px; opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: .2s ease; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.help-dialog { width: min(420px, calc(100% - 32px)); padding: 30px; border: 0; border-radius: 16px; color: var(--ink); box-shadow: 0 20px 70px #1b302a35; }
.help-dialog::backdrop { background: #1b302a70; backdrop-filter: blur(3px); }
.help-dialog h2 { margin: 0 0 12px; font-size: 24px; letter-spacing: -.7px; }
.help-dialog p:not(.eyebrow), .help-dialog li { color: #748078; font-size: 13px; line-height: 1.65; }
.help-dialog ul { padding-left: 19px; }
.help-dialog li { margin: 7px 0; }
.help-dialog .new-game-button { margin-top: 22px; }
.dialog-close { position: absolute; top: 13px; right: 15px; width: 30px; height: 30px; border: 0; border-radius: 50%; background: #f1f5f1; color: #718078; font-size: 21px; cursor: pointer; }

@media (min-width: 1200px) {
  .game-layout { grid-template-columns: 620px 1fr; gap: 48px; }
}

@media (max-width: 760px) {
  .app-shell { width: min(540px, calc(100% - 32px)); }
  .topbar { height: 66px; }
  .topbar-note { font-size: 11px; }
  .intro { padding: 32px 0 22px; }
  h1 { font-size: 32px; }
  .game-layout { grid-template-columns: 1fr; gap: 27px; }
  .board-card { padding: 17px 15px 15px; }
  .board-wrap { padding: 4px; }
  .cell { font-size: clamp(14px, 4.6vw, 22px); }
  .number-pad { gap: 5px; margin-top: 13px; }
  .number-pad button { font-size: 16px; }
  .side-panel { padding: 0 3px; }
  .section-heading { margin-bottom: 13px; }
  .difficulty-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .difficulty-option { min-height: 62px; gap: 8px; padding: 8px; }
  .difficulty-emoji { width: 30px; height: 30px; font-size: 14px; }
  .difficulty-copy small { font-size: 9px; }
  .page-footer { gap: 10px; padding-top: 23px; font-size: 9px; }
  .footer-details { grid-template-columns: 1fr; gap: 6px; }
}

@media (max-width: 560px) {
  .topbar-note { display: none; }
}

@media (max-width: 380px) {
  .app-shell { width: calc(100% - 24px); }
  .board-card { padding-inline: 10px; }
  .difficulty-copy strong { font-size: 11px; }
  .difficulty-copy small { font-size: 8px; }
}

html[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e3ece5;
  --muted: #a5b3a9;
  --paper: #18231d;
  --card: #202d26;
  --line: #34463b;
  --green: #65b986;
  --green-dark: #4d9d6d;
  --mint: #263b2e;
}

html[data-theme="dark"] body {
  background:
    radial-gradient(ellipse at 9% 4%, rgba(49, 88, 62, .28), transparent 27rem),
    var(--paper);
}

html[data-theme="dark"] .topbar { border-bottom-color: #33443a; }
html[data-theme="dark"] .topbar-note,
html[data-theme="dark"] .game-label,
html[data-theme="dark"] .stats,
html[data-theme="dark"] .stat,
html[data-theme="dark"] .text-action { color: #a6b4aa; }
html[data-theme="dark"] .language-switch { border-color: #405147; background: #202d26; }
html[data-theme="dark"] .language-switch button { color: #a6b4aa; }
html[data-theme="dark"] .language-switch button[aria-pressed="true"] { color: #102117; }
html[data-theme="dark"] .icon-button { border-color: #405147; color: #b7c6ba; }
html[data-theme="dark"] .icon-button:hover { border-color: #76bd8f; background: #26372d; color: #9bd8ae; }
html[data-theme="dark"] .board-card { border-color: #33463a; background: var(--card); box-shadow: 0 14px 42px rgba(0, 0, 0, .2); }
html[data-theme="dark"] .stat-divider { border-left-color: #3a4b40; }
html[data-theme="dark"] .board-wrap { background: #73947c; }
html[data-theme="dark"] .sudoku-board { border-color: #73947c; background: #233129; }
html[data-theme="dark"] .cell {
  border-right-color: #3b4b41;
  border-bottom-color: #3b4b41;
  background: #24332b;
  color: #a4dfb4;
}
html[data-theme="dark"] .cell:nth-child(3n) { border-right-color: #78917f; }
html[data-theme="dark"] .cell:nth-child(n+19):nth-child(-n+27),
html[data-theme="dark"] .cell:nth-child(n+46):nth-child(-n+54) { border-bottom-color: #78917f; }
html[data-theme="dark"] .cell.given { color: #e0e9e2; }
html[data-theme="dark"] .cell.related { background: #2b3c32; }
html[data-theme="dark"] .cell.same-number { background: #385744; color: #c3f0cc; }
html[data-theme="dark"] .cell.selected { background: #345641; box-shadow: inset 0 0 0 2px #7ec896; }
html[data-theme="dark"] .cell.error { background: #4b302e; color: #ffaaa0; }
html[data-theme="dark"] .cell.error.selected { box-shadow: inset 0 0 0 2px #e58d83; }
html[data-theme="dark"] .cell:focus-visible { outline-color: #88d39c; }
html[data-theme="dark"] .notes-grid { color: #afc1b4; }
html[data-theme="dark"] .number-pad button { border-color: #3b5142; background: #293b30; color: #b5e7c1; }
html[data-theme="dark"] .number-pad button:hover { border-color: #73b78a; background: #314a38; }
html[data-theme="dark"] .text-action:hover,
html[data-theme="dark"] .text-action[aria-pressed="true"] { color: #93d7a7; }
html[data-theme="dark"] .difficulty-option { border-color: #35483b; background: #222f28; }
html[data-theme="dark"] .difficulty-option:hover { border-color: #70967a; }
html[data-theme="dark"] .difficulty-option.active { border-color: #6eb383; background: #293d30; }
html[data-theme="dark"] .difficulty-emoji { background: #304035; }
html[data-theme="dark"] .difficulty-copy small { color: #a3b1a7; }
html[data-theme="dark"] .option-indicator { border-color: #64776a; }
html[data-theme="dark"] .active .option-indicator { border-color: #70bc88; background: #203027; }
html[data-theme="dark"] .new-game-button { color: #102117; }
html[data-theme="dark"] .tip-card { border-color: #514a35; background: #302f27; }
html[data-theme="dark"] .tip-card p { color: #c1bca8; }
html[data-theme="dark"] .keyboard-hint { color: #a3b0a7; }
html[data-theme="dark"] kbd { border-color: #405147; background: #243129; color: #c1cdc4; }
html[data-theme="dark"] .page-footer { color: #a1afa5; }
html[data-theme="dark"] .footer-author a { color: #c0d2c4; text-decoration-color: #738779; }
html[data-theme="dark"] .footer-author a:hover { color: #98d5a9; }
html[data-theme="dark"] .footer-details { border-top-color: #33443a; }
html[data-theme="dark"] .ai-credit,
html[data-theme="dark"] .privacy-note { color: #aab8ae; }
html[data-theme="dark"] .help-dialog { background: #202d26; color: var(--ink); }
html[data-theme="dark"] .help-dialog p:not(.eyebrow),
html[data-theme="dark"] .help-dialog li { color: #b0bdb3; }
html[data-theme="dark"] .dialog-close { background: #304036; color: #d1ded4; }
