:root {
  color-scheme: dark;
  --bg: #060b10;
  --bg-deep: #03070a;
  --panel: rgba(11, 21, 29, 0.88);
  --panel-soft: rgba(15, 28, 37, 0.72);
  --line: rgba(170, 217, 236, 0.14);
  --line-strong: rgba(170, 217, 236, 0.36);
  --text: #edf7f4;
  --muted: #849ba3;
  --green: #71f6c7;
  --blue: #70cfff;
  --amber: #ffd17c;
  --danger: #ff8292;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 14% 12%, rgba(64, 176, 145, 0.10), transparent 30rem),
    radial-gradient(circle at 82% 78%, rgba(63, 144, 188, 0.11), transparent 34rem),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, a { font: inherit; }
button { color: inherit; }
a { color: inherit; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }

.skip-link {
  position: fixed;
  z-index: 200;
  top: 12px;
  left: 12px;
  padding: 10px 14px;
  transform: translateY(-150%);
  border-radius: 7px;
  background: var(--green);
  color: #04100c;
  font: 700 0.78rem var(--mono);
  text-decoration: none;
}
.skip-link:focus { transform: translateY(0); }

.ambient { position: fixed; inset: 0; overflow: hidden; pointer-events: none; }
.ambient::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.18;
  background-image:
    linear-gradient(rgba(113, 246, 199, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(113, 246, 199, 0.07) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: linear-gradient(to bottom, #000, transparent 80%);
}
.ambient i { position: absolute; border-radius: 50%; filter: blur(90px); opacity: 0.08; }
.ambient i:nth-child(1) { width: 34rem; height: 34rem; left: -15rem; top: -15rem; background: var(--green); }
.ambient i:nth-child(2) { width: 29rem; height: 29rem; right: -13rem; top: 18%; background: var(--blue); }
.ambient i:nth-child(3) { width: 24rem; height: 24rem; left: 38%; bottom: -17rem; background: var(--green); }

.game-header {
  position: relative;
  z-index: 10;
  min-height: 72px;
  display: grid;
  grid-template-columns: minmax(200px, 1fr) auto minmax(100px, 1fr);
  align-items: center;
  gap: 24px;
  padding: 10px clamp(15px, 3vw, 38px);
  border-bottom: 1px solid var(--line);
  background: rgba(4, 9, 13, 0.75);
  backdrop-filter: blur(18px) saturate(135%);
}
.brand { display: inline-flex; align-items: center; gap: 12px; width: max-content; text-decoration: none; }
.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 39px;
  height: 39px;
  border: 1px solid rgba(113, 246, 199, 0.55);
  color: var(--green);
  font: 700 0.72rem var(--mono);
  letter-spacing: 0.05em;
}
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; width: 7px; height: 7px; border-color: var(--green); }
.brand-mark::before { left: -3px; top: -3px; border-left: 1px solid; border-top: 1px solid; }
.brand-mark::after { right: -3px; bottom: -3px; border-right: 1px solid; border-bottom: 1px solid; }
.brand-copy { display: flex; flex-direction: column; line-height: 1.12; }
.brand-copy strong { font-size: 1rem; letter-spacing: -0.02em; }
.brand-copy small { margin-top: 5px; color: var(--muted); font: 500 0.58rem var(--mono); letter-spacing: 0.13em; }
.header-stats { display: flex; align-items: center; gap: clamp(22px, 4vw, 54px); }
.header-stats > span { min-width: 58px; display: flex; flex-direction: column; align-items: center; }
.header-stats small { color: var(--muted); font: 600 0.57rem var(--mono); letter-spacing: 0.12em; text-transform: uppercase; }
.header-stats strong { margin-top: 4px; font: 600 0.92rem var(--mono); color: #fff; }
.back-link { justify-self: end; display: inline-flex; align-items: center; gap: 8px; color: #bcd0d5; font: 600 0.72rem var(--mono); text-decoration: none; }
.back-link:hover { color: var(--green); }

.game-shell {
  position: relative;
  z-index: 1;
  width: min(1160px, calc(100% - 32px));
  min-height: calc(100dvh - 72px);
  margin: 0 auto;
  padding: clamp(28px, 4vw, 52px) 0 40px;
  display: grid;
  grid-template-columns: minmax(0, 720px) 250px;
  justify-content: center;
  align-items: start;
  gap: clamp(24px, 4vw, 54px);
}
.board-column { min-width: 0; }
.board-toolbar { display: flex; justify-content: space-between; align-items: end; gap: 22px; margin-bottom: 18px; }
.eyebrow { margin: 0; color: var(--green); font: 600 0.62rem/1.2 var(--mono); letter-spacing: 0.15em; text-transform: uppercase; }
.board-toolbar h1 { margin: 7px 0 0; font-size: clamp(1.7rem, 3vw, 2.45rem); line-height: 1; letter-spacing: -0.045em; }
.difficulty-switch { display: inline-flex; padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: rgba(5, 13, 18, 0.66); }
.difficulty-switch button { min-width: 68px; padding: 9px 11px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; font: 650 0.68rem var(--mono); }
.difficulty-switch button:hover { color: #fff; }
.difficulty-switch button.active { background: rgba(113, 246, 199, 0.12); color: var(--green); box-shadow: inset 0 0 0 1px rgba(113, 246, 199, 0.21); }

.board-wrap {
  position: relative;
  width: min(100%, 660px);
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid rgba(170, 217, 236, 0.30);
  border-radius: 18px;
  background: rgba(5, 13, 18, 0.86);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.30), 0 0 0 1px rgba(255, 255, 255, 0.018) inset;
}
.board { display: grid; grid-template-columns: repeat(9, 1fr); width: 100%; height: 100%; }
.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-right: 1px solid rgba(170, 217, 236, 0.13);
  border-bottom: 1px solid rgba(170, 217, 236, 0.13);
  background: rgba(9, 20, 27, 0.66);
  color: var(--blue);
  cursor: pointer;
  font: 650 clamp(1.05rem, 3vw, 1.75rem)/1 var(--mono);
  transition: background 90ms ease, color 90ms ease, box-shadow 90ms ease;
}
.cell:nth-child(9n) { border-right: 0; }
.cell:nth-child(n + 73) { border-bottom: 0; }
.cell:nth-child(9n + 3), .cell:nth-child(9n + 6) { border-right-color: rgba(113, 246, 199, 0.52); border-right-width: 2px; }
.cell:nth-child(n + 19):nth-child(-n + 27), .cell:nth-child(n + 46):nth-child(-n + 54) { border-bottom-color: rgba(113, 246, 199, 0.52); border-bottom-width: 2px; }
.cell:hover { background: rgba(113, 246, 199, 0.08); }
.cell.given { color: #edf7f4; font-weight: 750; }
.cell.peer { background: rgba(112, 207, 255, 0.055); }
.cell.same { background: rgba(113, 246, 199, 0.105); }
.cell.selected { z-index: 2; background: rgba(113, 246, 199, 0.17); box-shadow: inset 0 0 0 2px var(--green); color: #cffff0; }
.cell.conflict { color: var(--danger); background: rgba(255, 130, 146, 0.10); }
.cell.error-flash { animation: error-pulse 420ms ease; }
.cell.hinted::after { content: ""; position: absolute; top: 6px; right: 6px; width: 5px; height: 5px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 10px var(--amber); }
.cell.complete-number { opacity: 0.36; }
@keyframes error-pulse { 50% { background: rgba(255, 130, 146, 0.25); } }

.notes { position: absolute; inset: 4px; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); color: rgba(179, 211, 219, 0.80); font: 600 clamp(0.36rem, 1.2vw, 0.62rem)/1 var(--mono); pointer-events: none; }
.notes i { display: grid; place-items: center; font-style: normal; }

.generating {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 15px;
  background: rgba(4, 10, 14, 0.90);
  color: #dceceb;
  font: 600 0.75rem var(--mono);
  letter-spacing: 0.03em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease;
}
.generating.visible { opacity: 1; pointer-events: auto; }
.spinner { width: 34px; height: 34px; border: 2px solid rgba(113, 246, 199, 0.16); border-top-color: var(--green); border-radius: 50%; animation: spin 750ms linear infinite; }
@keyframes spin { to { transform: rotate(1turn); } }

.number-pad { width: min(100%, 660px); display: grid; grid-template-columns: repeat(9, 1fr); gap: 7px; margin-top: 13px; }
.number-pad button {
  min-width: 0;
  height: 53px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(13, 25, 33, 0.74);
  cursor: pointer;
}
.number-pad button:hover { border-color: rgba(113, 246, 199, 0.46); background: rgba(113, 246, 199, 0.08); }
.number-pad button:disabled { opacity: 0.28; cursor: default; }
.number-pad b { font: 650 1rem var(--mono); color: #e7f5f3; }
.number-pad span { font: 550 0.52rem var(--mono); color: var(--muted); }

.control-panel {
  margin-top: 57px;
  padding: 19px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.18);
}
.panel-status { display: flex; align-items: center; gap: 11px; padding: 2px 2px 18px; border-bottom: 1px solid var(--line); }
.status-light { width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 14px rgba(113, 246, 199, 0.65); }
.panel-status div { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.panel-status small { color: var(--muted); font: 550 0.55rem var(--mono); letter-spacing: 0.12em; text-transform: uppercase; }
.panel-status strong { overflow: hidden; color: #dceae9; font-size: 0.78rem; text-overflow: ellipsis; white-space: nowrap; }
.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 16px 0; }
.tool {
  min-height: 79px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: 1fr auto;
  align-items: center;
  gap: 0 6px;
  padding: 13px 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.025);
  cursor: pointer;
  text-align: left;
}
.tool:hover:not(:disabled) { border-color: rgba(113, 246, 199, 0.38); background: rgba(113, 246, 199, 0.06); }
.tool:disabled { opacity: 0.34; cursor: default; }
.tool[aria-pressed="true"] { border-color: rgba(113, 246, 199, 0.58); background: rgba(113, 246, 199, 0.10); }
.tool > span { grid-row: 1 / 3; color: var(--green); font: 500 1.2rem var(--mono); }
.tool b { align-self: end; font-size: 0.71rem; }
.tool small { grid-column: 2; color: var(--muted); font: 500 0.51rem var(--mono); }
.new-button {
  width: 100%;
  min-height: 47px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 15px;
  border: 1px solid var(--green);
  border-radius: 9px;
  background: linear-gradient(135deg, var(--green), #91ffd9);
  color: #04100c;
  cursor: pointer;
  font: 750 0.69rem var(--mono);
}
.new-button:hover { filter: brightness(1.08); }
.key-guide { display: grid; gap: 8px; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.key-guide .eyebrow { margin-bottom: 3px; }
.key-guide p:not(.eyebrow) { display: flex; justify-content: space-between; align-items: center; margin: 0; color: #9fb1b6; font-size: 0.66rem; }
kbd { min-width: 34px; padding: 4px 6px; border: 1px solid var(--line); border-bottom-color: var(--line-strong); border-radius: 5px; background: rgba(255, 255, 255, 0.035); color: #d8e8e7; font: 600 0.54rem var(--mono); text-align: center; }
.privacy-note { margin: 22px 0 0; color: #657d84; font: 500 0.59rem/1.55 var(--mono); }

.completion {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(2, 7, 10, 0.80);
  backdrop-filter: blur(17px);
}
.completion[hidden] { display: none; }
.completion-card {
  position: relative;
  z-index: 2;
  width: min(480px, 100%);
  padding: clamp(29px, 6vw, 46px);
  border: 1px solid rgba(113, 246, 199, 0.30);
  border-radius: 18px;
  background: linear-gradient(155deg, rgba(15, 31, 38, 0.98), rgba(5, 14, 19, 0.98));
  box-shadow: 0 35px 120px rgba(0, 0, 0, 0.54);
  text-align: center;
}
.completion-card h2 { margin: 10px 0 12px; font-size: clamp(2.35rem, 9vw, 4.2rem); line-height: 0.95; letter-spacing: -0.055em; }
.completion-card > p:not(.eyebrow) { margin: 0 auto; color: #aabdc1; font-size: 0.87rem; line-height: 1.65; }
.completion-card > p strong { color: #edf7f4; }
.completion-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; overflow: hidden; margin: 25px 0; border: 1px solid var(--line); border-radius: 10px; background: var(--line); }
.completion-stats span { padding: 14px 8px; background: rgba(5, 15, 20, 0.94); }
.completion-stats small { display: block; color: var(--muted); font: 550 0.53rem var(--mono); letter-spacing: 0.10em; text-transform: uppercase; }
.completion-stats b { display: block; margin-top: 6px; font: 650 0.85rem var(--mono); }
.completion-actions { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 12px; }
.completion-actions button, .completion-actions a { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; padding: 0 18px; border-radius: 8px; text-decoration: none; cursor: pointer; font: 700 0.68rem var(--mono); }
.completion-actions .primary { border: 1px solid var(--green); background: var(--green); color: #04100c; }
.completion-actions a { border: 1px solid var(--line); color: #c7d7d8; }
.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti i { position: absolute; top: -12vh; width: 7px; height: 15px; border-radius: 1px; background: var(--green); animation: fall var(--fall, 3.2s) linear var(--delay, 0s) infinite; transform: translate3d(0, -20px, 0) rotate(0deg); }
.confetti i:nth-child(3n) { background: var(--blue); }
.confetti i:nth-child(4n) { background: var(--amber); }
.confetti i:nth-child(5n) { background: #b69cff; }
@keyframes fall { to { transform: translate3d(var(--drift, 20px), 118vh, 0) rotate(620deg); } }

.toast {
  position: fixed;
  z-index: 120;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  transform: translate(-50%, 20px);
  border: 1px solid rgba(113, 246, 199, 0.28);
  border-radius: 8px;
  background: rgba(8, 18, 24, 0.96);
  color: #d9e8e6;
  font: 600 0.66rem var(--mono);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .game-shell { width: min(710px, calc(100% - 24px)); grid-template-columns: 1fr; gap: 16px; }
  .control-panel { margin-top: 0; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 12px; }
  .panel-status, .key-guide, .privacy-note { display: none; }
  .tool-grid { grid-template-columns: repeat(4, minmax(70px, 1fr)); margin: 0; }
  .tool { min-height: 58px; }
  .new-button { width: auto; min-width: 150px; }
}

@media (max-width: 680px) {
  .game-header { min-height: 64px; grid-template-columns: 1fr auto auto; gap: 10px; padding: 8px 11px; }
  .brand-mark { width: 35px; height: 35px; }
  .brand-copy small, .best-stat, .back-copy { display: none !important; }
  .header-stats { gap: 13px; }
  .header-stats > span { min-width: 48px; }
  .header-stats strong { font-size: 0.81rem; }
  .game-shell { min-height: calc(100dvh - 64px); padding-top: 20px; padding-bottom: 20px; }
  .board-toolbar { align-items: start; flex-direction: column; gap: 14px; }
  .difficulty-switch { width: 100%; }
  .difficulty-switch button { flex: 1; }
  .board-wrap { border-radius: 11px; }
  .number-pad { gap: 4px; }
  .number-pad button { height: 48px; border-radius: 7px; }
  .control-panel { grid-template-columns: 1fr; gap: 9px; }
  .tool-grid { width: 100%; grid-template-columns: repeat(4, 1fr); }
  .tool { min-width: 0; min-height: 61px; display: flex; flex-direction: column; justify-content: center; gap: 3px; padding: 6px 3px; text-align: center; }
  .tool > span { font-size: 1rem; }
  .tool b { font-size: 0.62rem; }
  .tool small { display: none; }
  .new-button { width: 100%; }
  .notes { inset: 2px; }
  .cell.hinted::after { top: 3px; right: 3px; width: 4px; height: 4px; }
}

@media (max-width: 390px) {
  .brand-copy strong { font-size: 0.88rem; }
  .header-stats { gap: 7px; }
  .header-stats > span { min-width: 43px; }
  .number-pad button { height: 44px; }
  .number-pad b { font-size: 0.9rem; }
  .number-pad span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
