/* style.css — «Небоскрёбы» для лаборатории zharkevich.ru.
   Общая дизайн-система семейства игр; специфика — рамка подсказок (n+2)×(n+2). */

: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;
  --clue-active-bg: #d8efe8;
  --clue-active-ink: #1f8a70;
  --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;
    --clue-active-bg: #1f4a3e;
    --clue-active-ink: #7fd4bb;
    --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;
  --clue-active-bg: #1f4a3e;
  --clue-active-ink: #7fd4bb;
  --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; margin-left: auto; }

.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__input {
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 3px 8px;
  width: 12ch;
}

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

.hud__session {
  margin-left: 24px;
  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,
.sky-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;
}

.ms-board {
  display: grid;
  background: var(--board, #e9e4da);
  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;
  width: min(100%, calc(100dvh - 320px));
  max-width: 640px;
  aspect-ratio: 1;
}

.ms-board--c9 { grid-template: repeat(9, 1fr) / repeat(9, 1fr); }
.ms-board--c12 { grid-template: repeat(12, 1fr) / repeat(12, 1fr); }
.ms-board--c16 { grid-template: repeat(16, 1fr) / repeat(16, 1fr); }

.ms-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-left-width: 0;
  border-top-width: 0;
  font-family: inherit;
  font-weight: 700;
  font-size: clamp(12px, 3.2vw, 24px);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  padding: 0;
  background: var(--cell-bg);
  color: var(--ink);
}

.ms-cell--closed {
  background: var(--cell);
  box-shadow: inset 0 -2px 0 rgb(0 0 0 / 0.08);
}

.ms-cell--open {
  background: var(--panel);
  cursor: default;
  box-shadow: none;
}

.ms-cell--flag { color: var(--cell-error, #c0392b); }

.ms-cell--wrongflag {
  text-decoration: line-through;
  background: var(--cell-error-bg, #f9e5e2);
}

.ms-cell--mine { color: var(--ink); }

.ms-cell--exploded {
  background: var(--cell-error, #c0392b);
  color: #fff;
}

/* классические цвета чисел сапёра */
.ms-cell[data-n="1"] { color: #3b6fd4; }
.ms-cell[data-n="2"] { color: #2f8f4e; }
.ms-cell[data-n="3"] { color: #d43d3d; }
.ms-cell[data-n="4"] { color: #7b4dbf; }
.ms-cell[data-n="5"] { color: #a0552b; }
.ms-cell[data-n="6"] { color: #2b9a91; }
.ms-cell[data-n="7"] { color: #333333; }
.ms-cell[data-n="8"] { color: #888888; }

.ms-cell--sel { outline: 2px solid var(--accent); outline-offset: -2px; z-index: 1; }

.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; }
.board-veil__lines p { margin: 0; }
.board-veil__lines .board-veil__total { color: var(--accent); font-weight: 700; font-size: 19px; }

.hud__mines {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--cell-error, #c0392b);
}

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

.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 {
  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__btn:disabled { opacity: 0.4; cursor: default; }

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

/* ---------- футер, настройки, правила ---------- */

.app__foot { padding: 16px 0 4px; }

.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; }
.settings__row { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.settings__row .pad__btn { min-height: 40px; }

.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);
}

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

.app__foot-link {
  margin-left: 24px;
  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;
  }
}

@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; }
}

/* навигация breadcrumbs в шапке: Игры · название */
.hud__nav {
  color: var(--ink);
  text-decoration: none;
  font-weight: 400;
}

.hud__nav:hover { color: var(--accent); }
.hud__sep { color: var(--ink-soft); font-weight: 400; }

/* профиль — отдельный блок рядом с навигацией (не липнет к часам) */
.hud__profile { margin-left: 0; }

@media (min-width: 520px) {
  .hud__profile {
    margin-left: 20px;
    padding-left: 20px;
    border-left: 1px solid var(--line);
  }
}

.hud__session { margin-left: auto; }

/* очки не липнут к длинному имени */
.hud__points { margin-left: 24px; }

/* переключатель игр в шапке (без JS: focus-within) */
.switcher { position: relative; }

.switcher__btn {
  font: inherit;
  font-weight: 700;
  font-size: inherit;
  letter-spacing: 0.02em;
  color: var(--accent);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

.switcher__menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: -8px;
  min-width: 190px;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 10;
}

.switcher:focus-within .switcher__menu { display: block; }

.switcher__menu a {
  display: block;
  padding: 8px 10px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 400;
  border-radius: 6px;
}

.switcher__menu a:hover { background: var(--cell-peer); }

.switcher__here {
  display: block;
  padding: 8px 10px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}
