:root {
  --bg: #101625;
  --bg-grad-1: rgba(120, 168, 255, 0.12);
  --bg-grad-2: rgba(57, 198, 121, 0.08);

  --panel: rgba(27, 36, 58, 0.9);
  --panel-solid: #1b243a;
  --panel-2: #202b44;

  --text: #eef3ff;
  --muted: #b5c1de;

  --accent: #78a8ff;
  --accent-2: #8dc0ff;
  --accent-3: #4e83f1;
  --success: #38c978;
  --danger: #ff6a6a;
  --warning: #ffd45f;

  --line: #60729f;
  --line-soft: #4d6088;
  --line-strong: #a5b6e4;

  --cell-bg: #22304f;
  --cell-fixed-text: #f5f8ff;
  --cell-editable-text: #9fc3ff;

  --related-bg: #3a4f7e;
  --selected-bg: #5c5138;
  --selected-ring: #ffd45f;
  --same-bg: #172a35;
  --same-ring: #39d084;

  --invalid-bg: rgba(255, 106, 106, 0.18);
  --invalid-text: #ffe0e0;

  --btn-bg: #2c3858;
  --btn-bg-hover: #344366;
  --btn-subtle-bg: #25304c;
  --btn-border: rgba(255, 255, 255, 0.07);

  --card-border: rgba(255, 255, 255, 0.06);
  --soft-fill: rgba(255, 255, 255, 0.03);
  --soft-fill-2: rgba(255, 255, 255, 0.04);
  --soft-fill-3: rgba(255, 255, 255, 0.06);

  --shadow: 0 14px 34px rgba(0, 0, 0, 0.24);
  --overlay: rgba(6, 10, 18, 0.58);

  --radius: 16px;
  --cell-size: 54px;
}

body[data-theme="light"] {
  --bg: #edf2fb;
  --bg-grad-1: rgba(109, 155, 241, 0.12);
  --bg-grad-2: rgba(56, 201, 120, 0.08);

  --panel: rgba(255, 255, 255, 0.88);
  --panel-solid: #ffffff;
  --panel-2: #eef3fb;

  --text: #1a2742;
  --muted: #66738f;

  --accent: #5d90f6;
  --accent-2: #7aa8ff;
  --accent-3: #447be8;
  --success: #24a864;
  --danger: #e25a5a;
  --warning: #d3a22b;

  --line: #9fb1d4;
  --line-soft: #b8c5df;
  --line-strong: #5f6f92;

  --cell-bg: #f8fbff;
  --cell-fixed-text: #18233c;
  --cell-editable-text: #4c79c7;

  --related-bg: #dce6f7;
  --selected-bg: #ebddab;
  --selected-ring: #d1a335;
  --same-bg: #d7ebe2;
  --same-ring: #1ea763;

  --invalid-bg: rgba(226, 90, 90, 0.16);
  --invalid-text: #ae2f2f;

  --btn-bg: #e8eefb;
  --btn-bg-hover: #dde7fa;
  --btn-subtle-bg: #eef3fb;
  --btn-border: rgba(95, 111, 146, 0.18);

  --card-border: rgba(95, 111, 146, 0.16);
  --soft-fill: rgba(95, 111, 146, 0.06);
  --soft-fill-2: rgba(95, 111, 146, 0.08);
  --soft-fill-3: rgba(95, 111, 146, 0.1);

  --shadow: 0 14px 34px rgba(59, 79, 117, 0.12);
  --overlay: rgba(29, 38, 58, 0.3);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  color: var(--text);
  font-family: Inter, Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body {
  padding: 18px;
  background:
    radial-gradient(circle at top left, var(--bg-grad-1), transparent 22%),
    radial-gradient(circle at top right, var(--bg-grad-2), transparent 18%),
    var(--bg);
  transition: background 0.2s ease, color 0.2s ease;
}

button {
  font: inherit;
  touch-action: manipulation;
}

.app {
  max-width: 1420px;
  height: calc(100dvh - 36px);
  margin: 0 auto;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.brand-wrap {
  min-width: 0;
}

.brand {
  margin: 0 0 6px;
  font-size: 30px;
  line-height: 1.05;
  color: var(--text);
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(118px, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 420px;
}

.stat,
.side-card,
.center,
.board-wrap,
.number-pad,
.toolbar,
.rules-card {
  background: var(--panel);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow);
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.stat {
  min-width: 0;
  padding: 12px 14px;
  border-radius: 14px;
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.stat-value {
  display: block;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.15;
  color: var(--text);
}

.lives {
  color: #ff9d9d;
  letter-spacing: 2px;
}

body[data-theme="light"] .lives {
  color: #d95555;
}

.game-shell {
  display: grid;
  grid-template-columns: 240px minmax(560px, 1fr);
  gap: 16px;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.side-card {
  border-radius: 16px;
  padding: 14px;
}

.side-title {
  font-size: 14px;
  font-weight: 800;
  margin-bottom: 12px;
  color: var(--text);
}

.side-control-stack {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.side-wide-btn {
  width: 100%;
}

.difficulty-list,
.progress-list {
  display: grid;
  gap: 8px;
}

.difficulty-item,
.progress-item {
  width: 100%;
  border: 1px solid var(--card-border);
  background: var(--soft-fill);
  border-radius: 12px;
  padding: 10px 12px;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  transition:
    transform 0.16s ease,
    background 0.16s ease,
    border-color 0.16s ease,
    box-shadow 0.16s ease,
    opacity 0.16s ease,
    color 0.16s ease;
}

.difficulty-item:hover:not(.locked):not(:disabled) {
  transform: translateY(-1px);
  background: rgba(120, 168, 255, 0.08);
  border-color: rgba(120, 168, 255, 0.28);
}

body[data-theme="light"] .difficulty-item:hover:not(.locked):not(:disabled) {
  background: rgba(93, 144, 246, 0.09);
  border-color: rgba(93, 144, 246, 0.28);
}

.difficulty-item:active,
.tool-btn:active,
.number-btn:active,
.cell:active {
  transform: scale(0.985);
}

.difficulty-item.active {
  background: rgba(120, 168, 255, 0.14);
  border-color: rgba(120, 168, 255, 0.45);
  box-shadow: 0 0 0 1px rgba(120, 168, 255, 0.2) inset;
}

body[data-theme="light"] .difficulty-item.active {
  background: rgba(93, 144, 246, 0.14);
  border-color: rgba(93, 144, 246, 0.34);
  box-shadow: 0 0 0 1px rgba(93, 144, 246, 0.18) inset;
}

.mode-switch.active {
  background: rgba(57, 198, 121, 0.12);
  border-color: rgba(57, 198, 121, 0.38);
  box-shadow: 0 0 0 1px rgba(57, 198, 121, 0.18) inset;
}

body[data-theme="light"] .mode-switch.active {
  background: rgba(36, 168, 100, 0.12);
  border-color: rgba(36, 168, 100, 0.32);
  box-shadow: 0 0 0 1px rgba(36, 168, 100, 0.16) inset;
}

.theme-switch.active {
  background: rgba(120, 168, 255, 0.14);
  border-color: rgba(120, 168, 255, 0.34);
  box-shadow: 0 0 0 1px rgba(120, 168, 255, 0.18) inset;
}

body[data-theme="light"] .theme-switch.active {
  background: rgba(93, 144, 246, 0.12);
  border-color: rgba(93, 144, 246, 0.28);
  box-shadow: 0 0 0 1px rgba(93, 144, 246, 0.16) inset;
}

.difficulty-item.locked,
.mode-switch.locked,
.mode-switch:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.mode-switch:disabled:hover,
.mode-switch.locked:hover {
  transform: none;
  background: var(--soft-fill);
  border-color: var(--card-border);
}

.difficulty-main,
.progress-main {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.difficulty-name,
.progress-name {
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
}

.difficulty-meta,
.progress-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.difficulty-badge,
.progress-badge {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  padding: 6px 8px;
  border-radius: 999px;
  background: var(--soft-fill-3);
  white-space: nowrap;
}

.progress-item.done {
  border-color: rgba(57, 198, 121, 0.24);
  background: rgba(57, 198, 121, 0.08);
}

.progress-item.done .progress-badge {
  background: rgba(57, 198, 121, 0.18);
  color: #defdea;
}

body[data-theme="light"] .progress-item.done {
  border-color: rgba(36, 168, 100, 0.22);
  background: rgba(36, 168, 100, 0.08);
}

body[data-theme="light"] .progress-item.done .progress-badge {
  background: rgba(36, 168, 100, 0.14);
  color: #1c7d4e;
}

.center {
  border-radius: 18px;
  padding: 14px;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  border-radius: 14px;
  padding: 8px;
  margin-bottom: 12px;
}

.tool-btn {
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 10px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition:
    transform 0.16s ease,
    background 0.16s ease,
    border-color 0.16s ease,
    opacity 0.16s ease,
    box-shadow 0.16s ease,
    color 0.16s ease;
}

.tool-btn:hover {
  transform: translateY(-1px);
  background: var(--btn-bg-hover);
}

.tool-btn.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-3));
  color: #f8fbff;
}

.tool-btn.primary:hover {
  background: linear-gradient(180deg, var(--accent-2), #588af3);
}

body[data-theme="light"] .tool-btn.primary:hover {
  background: linear-gradient(180deg, #6e9df8, #4e83f1);
}

.tool-btn.danger {
  background: linear-gradient(180deg, #ff7d7d, #f16363);
  color: #fff8f8;
}

.tool-btn.subtle {
  background: var(--btn-subtle-bg);
  color: var(--muted);
}

.tool-btn.active {
  box-shadow: 0 0 0 2px rgba(120, 168, 255, 0.28) inset;
  border-color: rgba(120, 168, 255, 0.45);
}

.tool-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
}

.tool-btn:disabled:hover {
  background: var(--btn-bg);
}

.board-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 12px;
}

.board-title {
  font-size: 20px;
  font-weight: 900;
  color: var(--text);
}

.board-subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.hint-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.board-wrap {
  padding: 10px;
  border-radius: 18px;
  overflow: auto;
  margin-bottom: 12px;
}

.board {
  display: grid;
  width: max-content;
  margin: 0 auto;
  border: 3px solid var(--line-strong);
  background: color-mix(in srgb, var(--cell-bg) 78%, black 22%);
  transition: background 0.2s ease, border-color 0.2s ease;
}

body[data-theme="light"] .board {
  background: #eef4ff;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border: 1px solid var(--line-soft);
  background: var(--cell-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  font-size: calc(var(--cell-size) * 0.41);
  font-weight: 900;
  cursor: pointer;
  user-select: none;
  transition:
    background 0.14s ease,
    transform 0.12s ease,
    color 0.14s ease,
    box-shadow 0.14s ease,
    border-color 0.14s ease;
}

.cell.sector-a,
.cell.sector-b {
  background: var(--cell-bg);
}

.cell.fixed {
  color: var(--cell-fixed-text);
}

.cell.editable {
  color: var(--cell-editable-text);
}

.cell.related {
  background: var(--related-bg) !important;
}

.cell.selected {
  background: var(--selected-bg) !important;
  box-shadow: inset 0 0 0 2px var(--selected-ring);
}

.cell.same-value {
  background: var(--same-bg) !important;
  box-shadow: inset 0 0 0 2px var(--same-ring);
}

.cell.selected.same-value {
  background: var(--selected-bg) !important;
  box-shadow: inset 0 0 0 2px var(--selected-ring);
}

.cell.invalid {
  background: var(--invalid-bg) !important;
  color: var(--invalid-text) !important;
  animation: shake 0.18s linear 2;
}

.cell.thick-top {
  border-top: 3px solid var(--line-strong);
}

.cell.thick-left {
  border-left: 3px solid var(--line-strong);
}

.cell.thick-right {
  border-right: 3px solid var(--line-strong);
}

.cell.thick-bottom {
  border-bottom: 3px solid var(--line-strong);
}

.cell.notes-mode-preview::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  pointer-events: none;
}

body[data-theme="light"] .cell.notes-mode-preview::after {
  border-color: rgba(95, 111, 146, 0.24);
}

.notes-grid {
  position: absolute;
  inset: 4px;
  display: grid;
  gap: 2px;
  align-items: center;
  justify-items: center;
  color: color-mix(in srgb, var(--cell-editable-text) 75%, white 25%);
  font-weight: 700;
}

body[data-theme="light"] .notes-grid {
  color: #6e84b8;
}

.note-item {
  font-size: 10px;
  line-height: 1;
}

.number-pad {
  display: grid;
  gap: 8px;
  padding: 8px;
  border-radius: 14px;
  grid-template-columns: repeat(9, minmax(0, 1fr));
}

.number-btn {
  min-height: 56px;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--text);
  border-radius: 12px;
  font-size: 22px;
  font-weight: 900;
  cursor: pointer;
  transition:
    transform 0.16s ease,
    background 0.16s ease,
    border-color 0.16s ease,
    box-shadow 0.16s ease,
    opacity 0.16s ease,
    color 0.16s ease;
}

.number-btn:hover {
  transform: translateY(-1px);
  background: var(--btn-bg-hover);
}

.notes-panel {
  display: grid;
  grid-template-columns: 1fr;
  margin-top: 8px;
}

.notes-panel-btn {
  width: 100%;
  min-height: 56px;
}

.number-btn.completed {
  background: linear-gradient(180deg, #36c77b, #229657);
  border-color: rgba(255, 255, 255, 0.14);
  color: #f5fff8;
}

body[data-theme="light"] .number-btn.completed {
  background: linear-gradient(180deg, #41c782, #28a764);
}

.rules-card {
  margin-top: 16px;
  border-radius: 18px;
  padding: 16px;
}

.rules-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.rules-head h2 {
  margin: 0;
  font-size: 18px;
  color: var(--text);
}

.rules-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding: 6px 8px;
  border-radius: 999px;
  background: var(--soft-fill-3);
}

.rules-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.rule-item {
  min-height: 72px;
  padding: 12px;
  border-radius: 14px;
  background: var(--soft-fill-2);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 40;
  opacity: 1;
  transition: opacity 0.2s ease, background 0.2s ease;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  width: min(520px, 100%);
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--panel-solid) 95%, white 5%),
    color-mix(in srgb, var(--panel-2) 92%, black 8%)
  );
  border: 1px solid var(--card-border);
  border-radius: 22px;
  padding: 24px;
  box-shadow: 0 28px 60px rgba(0, 0, 0, 0.42);
  animation: modalIn 0.2s ease;
  transition: background 0.2s ease, border-color 0.2s ease;
}

body[data-theme="light"] .modal-card {
  box-shadow: 0 24px 50px rgba(59, 79, 117, 0.16);
}

.modal-card h2 {
  margin: 0 0 10px;
  font-size: 28px;
  color: var(--text);
}

.modal-text {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.45;
}

.modal-note {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--soft-fill-2);
  color: var(--text);
  font-size: 14px;
}

.modal-info {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.modal-info-item {
  padding: 12px;
  border-radius: 12px;
  background: var(--soft-fill-2);
}

.modal-info-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.modal-info-item strong {
  font-size: 22px;
  color: var(--text);
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

#surrenderModal {
  place-items: start center;
  padding-top: 72px;
  pointer-events: none;
}

#surrenderModal .modal-card {
  width: min(460px, calc(100vw - 24px));
  pointer-events: auto;
  padding: 20px 22px;
}

#surrenderModal .modal-card h2 {
  font-size: 22px;
  margin-bottom: 8px;
}

#surrenderModal .modal-text {
  margin-bottom: 12px;
}

.hidden {
  display: none !important;
}

body.game-paused .board-wrap,
body.game-paused .number-pad,
body.game-paused .notes-panel {
  opacity: 0.62;
  filter: saturate(0.75);
}

body.game-paused .board-wrap::after {
  content: "Пауза";
  position: absolute;
  inset: 10px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(6, 10, 18, 0.42);
  color: #fff;
  font-size: 28px;
  font-weight: 900;
  pointer-events: none;
}

.board-wrap {
  position: relative;
}

@keyframes shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-2px); }
  50% { transform: translateX(2px); }
  75% { transform: translateX(-2px); }
  100% { transform: translateX(0); }
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 1100px) {
  .game-shell {
    grid-template-columns: 1fr;
  }

  .side {
    order: 2;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .center {
    order: 1;
  }
}

@media (max-width: 760px) {
  body {
    padding: 12px;
  }

  .app {
    height: calc(100dvh - 24px);
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .stats {
    max-width: none;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stat {
    padding: 12px;
  }

  .stat-value {
    font-size: 19px;
  }

  .lives {
    font-size: 18px;
    letter-spacing: 1px;
  }

  .side {
    grid-template-columns: 1fr;
  }

  .brand {
    font-size: 25px;
  }

  .toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .board-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .number-pad {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .notes-panel {
    grid-template-columns: 1fr;
  }

  .board-wrap {
    padding: 7px;
  }

  .rules-grid {
    grid-template-columns: 1fr;
  }

  .rule-item {
    min-height: auto;
  }

  :root {
    --cell-size: 38px;
  }

  .cell {
    font-size: calc(var(--cell-size) * 0.39);
  }

  .note-item {
    font-size: 8px;
  }

  .number-btn {
    min-height: 52px;
    font-size: 19px;
  }

  .modal-card {
    width: min(92vw, 520px);
    padding: 22px 20px;
  }

  .modal-card h2 {
    font-size: 24px;
  }

  #surrenderModal {
    padding-top: 58px;
  }
}

@media (max-width: 430px) {
  .board-wrap {
    padding: 5px;
  }

  .toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .number-pad {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .board-wrap {
    padding: 7px;
  }

  .rules-grid {
    grid-template-columns: 1fr;
  }

  .rule-item {
    min-height: auto;
  }

  :root {
    --cell-size: 34px;
  }

  .stat-label {
    font-size: 11px;
  }

  .stat-value {
    font-size: 17px;
  }

  .lives {
    font-size: 16px;
  }
}