/* style.css — судоку для zharkevich.ru.
   Минимализм: системный шрифт, один акцент, темы через CSS-переменные.
   Mobile-first: раскладка перестраивается медиазапросами, а не скриптом. */

/* ---------- темы ---------- */

:root {
  --accent: #1f8a70;
  --accent-ink: #ffffff;

  --bg: #f7f7f5;
  --panel: #ffffff;
  --ink: #22262b;
  --ink-soft: #6b7280;
  --line: #d9dce0;
  --line-strong: #22262b;

  --cell-bg: #ffffff;
  --cell-given: #22262b;
  --cell-ink: #2f6f5f;
  --cell-sel: #d8efe8;
  --cell-peer: #eef4f2;
  --cell-same: #bfe3d9;
  --cell-error: #c0392b;
  --cell-error-bg: #f9e5e2;
  --notes-ink: #7b8494;

  --shadow: 0 1px 3px rgb(0 0 0 / 0.08);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181c;
    --panel: #1c2229;
    --ink: #e8eaed;
    --ink-soft: #9aa3ad;
    --line: #38414b;
    --line-strong: #e8eaed;

    --cell-bg: #1c2229;
    --cell-given: #e8eaed;
    --cell-ink: #7fd4bb;
    --cell-sel: #1f4a3e;
    --cell-peer: #232b33;
    --cell-same: #29584a;
    --cell-error: #e4736a;
    --cell-error-bg: #43211e;
    --notes-ink: #8a94a8;

    --shadow: 0 1px 3px rgb(0 0 0 / 0.4);
  }
}

:root[data-theme="dark"] {
  --bg: #14181c;
  --panel: #1c2229;
  --ink: #e8eaed;
  --ink-soft: #9aa3ad;
  --line: #38414b;
  --line-strong: #e8eaed;
  --cell-bg: #1c2229;
  --cell-given: #e8eaed;
  --cell-ink: #7fd4bb;
  --cell-sel: #1f4a3e;
  --cell-peer: #232b33;
  --cell-same: #29584a;
  --cell-error: #e4736a;
  --cell-error-bg: #43211e;
  --notes-ink: #8a94a8;
  --shadow: 0 1px 3px rgb(0 0 0 / 0.4);
}

/* ---------- каркас ---------- */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px clamp(12px, 3vw, 32px);
}

/* ---------- hud ---------- */

.hud {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 0 16px;
}

.hud__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.02em;
  color: var(--accent);
}

.hud__logo-link { display: block; line-height: 0; }

.hud__logo {
  display: block;
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.hud__word { line-height: 1; }

.hud__profile {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.hud__name {
  background: none;
  border: none;
  padding: 4px 2px;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  border-bottom: 1px dashed var(--ink-soft);
  max-width: 30vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud__points {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--accent);
}

.hud__session {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud__meta {
  color: var(--ink-soft);
  font-size: 14px;
  white-space: nowrap;
}

.hud__clock {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.hud__btn,
.pad__btn {
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  touch-action: manipulation;
}

.hud__btn--accent {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.hud__btn:focus-visible,
.pad__btn:focus-visible,
.cell:focus-visible,
.field__select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- раскладка: поле + панель ---------- */

.app__main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: start;
}

/* ---------- поле ---------- */

.board-wrap {
  position: relative;
  display: flex;
  justify-content: center;
}

.board {
  width: min(100%, calc(100dvh - 260px));
  max-width: 640px;
  aspect-ratio: 1;
  display: grid;
  background: var(--cell-bg);
  border: 2px solid var(--line-strong);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: var(--shadow);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* размерность поля только классами: inline-стили закрыты CSP */
.board--n6 { grid-template: repeat(6, 1fr) / repeat(6, 1fr); }
.board--n9 { grid-template: repeat(9, 1fr) / repeat(9, 1fr); }
.board--n16 { grid-template: repeat(16, 1fr) / repeat(16, 1fr); }

.board--n16 .cell { font-size: clamp(10px, 2.4vw, 20px); }

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-left-width: 0;
  border-top-width: 0;
  font-size: clamp(14px, 4.2vw, 30px);
  font-variant-numeric: tabular-nums;
  color: var(--cell-ink);
  background: transparent;
  cursor: pointer;
  position: relative;
  padding: 0;
  font-family: inherit;
}

.cell--given { color: var(--cell-given); font-weight: 600; cursor: default; }
.cell--peer { background: var(--cell-peer); }
.cell--same { background: var(--cell-same); }
.cell--sel { background: var(--cell-sel); }
.cell--error { color: var(--cell-error); }
.cell--error-bg { background: var(--cell-error-bg); }

/* толстые границы боксов ставит ui.js через модификаторы */
.cell--br { border-right: 2px solid var(--line-strong); }
.cell--bb { border-bottom: 2px solid var(--line-strong); }

.notes {
  position: absolute;
  inset: 0;
  display: grid;
  pointer-events: none;
}

/* геометрия заметок совпадает с геометрией боксов: 2×3 / 3×3 / 4×4 */
.notes--n6 { grid-template: repeat(2, 1fr) / repeat(3, 1fr); }
.notes--n9 { grid-template: repeat(3, 1fr) / repeat(3, 1fr); }
.notes--n16 { grid-template: repeat(4, 1fr) / repeat(4, 1fr); }

.notes--n16 span { font-size: 0.14em; }
.notes--n6 span { font-size: 0.4em; }

.notes span {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.32em;
  line-height: 1;
  color: var(--notes-ink);
}

.board-veil {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--bg);
  text-align: center;
  padding: 10px;
  overflow-y: auto;
}

.board-veil[hidden] { display: none; }

.board-veil__text {
  font-size: 22px;
  color: var(--ink);
  letter-spacing: 0.06em;
  margin: 0;
}

.board-veil__lines {
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1.35;
}

/* у строк разбора дефолтные margin'ы <p> — главный источник «воздуха» */
.board-veil__lines p { margin: 0; }

.board-veil__lines .board-veil__total {
  color: var(--accent);
  font-weight: 700;
  font-size: 19px;
}

/* ---------- настройки ---------- */

.settings {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--panel);
  max-width: 640px;
}

.settings summary {
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 14px;
}

.settings__grid {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}

.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.settings__hint {
  font-size: 12px;
  color: var(--ink-soft);
  margin: 4px 0 0 26px;
}

.rules { font-size: 14px; }
.rules__head { font-size: 15px; margin: 0 0 6px; }
.rules p { margin: 0 0 8px; }
.rules ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.rules kbd {
  font: inherit;
  font-size: 12px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  background: var(--panel);
}

.settings__row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.hud__input {
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 3px 8px;
  width: 12ch;
}

.pad__btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ---------- панель ввода ---------- */

.pad {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.pad__control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field { display: flex; flex-direction: column; gap: 4px; }
.field__label { font-size: 12px; color: var(--ink-soft); }
.field__select {
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 40px;
  touch-action: manipulation;
}

.pad__digits {
  --n: 9;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(52px, 1fr));
  gap: 8px;
}

.digit {
  font: inherit;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  min-height: 48px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.digit__left {
  font-size: 10px;
  color: var(--ink-soft);
  line-height: 1;
}

.digit--done {
  opacity: 0.35;
}

.pad__tools {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.pad__btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.pad__status {
  min-height: 20px;
  margin: 0;
  font-size: 14px;
  color: var(--ink-soft);
}

/* ---------- подвал ---------- */

.app__foot { padding: 16px 0 4px; }
.app__foot-note { font-size: 12px; color: var(--ink-soft); }

.app__foot-link {
  margin-left: 12px;
  font-size: 12px;
  color: var(--ink-soft);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
}

.app__foot-link:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- десктоп ---------- */

@media (min-width: 920px) {
  .app__main {
    grid-template-columns: minmax(0, auto) 300px;
    gap: 28px;
  }
  .pad__digits { grid-template-columns: repeat(3, 1fr); }
  .pad__digits--n16 { grid-template-columns: repeat(4, 1fr); }
  .pad__digits--n6 { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 480px) {
  .board-veil__text { font-size: 18px; }
  .board-veil__lines { font-size: 14px; }
  .board-veil__lines .board-veil__total { font-size: 16px; }
  .hud__meta { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
