:root {
  --bg: #0b0e14;
  --panel: #131824;
  --line: #1f2736;
  --text: #d7e0f0;
  --muted: #63708a;
  --accent: #00e5ff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(120% 90% at 50% 0%, #131b2a 0%, var(--bg) 60%) fixed;
  color: var(--text);
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
}

/* ---------- Экран загрузки ---------- */

.boot {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  transition: opacity .35s ease, visibility .35s;
}

.boot.done { opacity: 0; visibility: hidden; }

.boot-box { width: min(280px, 76vw); text-align: center; }

.boot-title {
  font-size: 22px;
  letter-spacing: .3em;
  color: var(--accent);
  margin-bottom: 18px;
  text-shadow: 0 0 22px rgba(0, 229, 255, .5);
}

.boot-track {
  height: 8px;
  border-radius: 99px;
  background: #1a2131;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px #222c3f;
}

.boot-bar {
  width: 0;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #00a7c4, #35f0ff);
  box-shadow: 0 0 14px rgba(0, 229, 255, .75);
  transition: width .18s ease;
}

.boot-pct {
  margin-top: 10px;
  font-size: 11px;
  letter-spacing: .18em;
  color: var(--muted);
}

/* ---------- HUD (только мобильный) ---------- */

.hud { display: none; }

/* ---------- Раскладка ---------- */

/* Ширина поля: до 300px на десктопе, но не выше ~76% высоты окна.
   --touch-h — место под кнопки (0 на десктопе, 148px на мобиле). */
:root {
  --board-w: min(300px, calc((100dvh - 48px) * 0.5));
}

.app {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
  max-width: 560px;
}

.board-wrap {
  position: relative;
  line-height: 0;
  border-radius: 10px;
  overflow: hidden;
  flex: 0 0 auto;
  box-shadow: 0 0 0 1px var(--line), 0 24px 60px rgba(0, 0, 0, .55), 0 0 80px rgba(0, 229, 255, .06);
}

canvas#board {
  display: block;
  width: var(--board-w, 300px);
  max-width: 100%;
  height: auto;
  aspect-ratio: 1 / 2;
  background: #070a10;
  touch-action: none;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 116px;
  flex: 1 1 auto;
}

.side section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
}

.label {
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 3px;
}

.value {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  line-height: 1.1;
}

.value.small { font-size: 19px; color: var(--text); }

canvas#next {
  display: block;
  width: 68px;
  height: 68px;
  margin: 2px auto 0;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 10px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 700;
  letter-spacing: .06em;
  color: #04121a;
  background: linear-gradient(180deg, #35f0ff, #00c4dd);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .08s ease, filter .15s ease;
}

.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px) scale(.99); }

.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 500;
  font-size: 13px;
  padding: 9px 12px;
}

.hint {
  font-size: 11px;
  line-height: 1.9;
  color: var(--muted);
}

kbd {
  display: inline-block;
  min-width: 16px;
  padding: 1px 5px;
  margin-right: 2px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #0f141f;
  color: var(--text);
  font-size: 10px;
  text-align: center;
}

/* ---------- Оверлей ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px;
  text-align: center;
  line-height: 1.5;
  background: rgba(7, 10, 16, .84);
  backdrop-filter: blur(3px);
  transition: opacity .2s ease;
}

.overlay.hidden { opacity: 0; pointer-events: none; }

.overlay h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: .2em;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(0, 229, 255, .45);
}

.overlay p {
  margin: 0 0 4px;
  font-size: 12px;
  color: var(--muted);
  max-width: 230px;
}

/* ---------- Тач-кнопки ---------- */

.touch { display: none; }

/* ---------- Мобильный режим ---------- */

@media (max-width: 700px), (pointer: coarse) {
  body {
    padding: calc(6px + env(safe-area-inset-top)) 8px calc(8px + env(safe-area-inset-bottom));
    gap: 8px;
    justify-content: flex-start;
  }

  .hud {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    width: 100%;
    max-width: 440px;
  }

  .hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 5px 4px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    line-height: 1.1;
  }

  .hud-item i {
    font-style: normal;
    font-size: 9px;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--muted);
  }

  .hud-item b {
    font-size: 15px;
    font-variant-numeric: tabular-nums;
    color: var(--accent);
  }

  .hud-item b.dim { color: var(--text); }

  .app { flex-direction: column; align-items: center; gap: 8px; max-width: 440px; }

  .board-wrap {
    /* высота поля = доступная высота минус HUD, панель, кнопки и отступы */
    width: min(
      100%,
      max(170px, calc((100dvh - 250px) * 0.5)),
      46vw
    );
  }

  canvas#board { width: 100%; }

  /* Правая колонка превращается в компактную строку «следующая + пауза» */
  .side {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-width: 0;
  }

  .side section:not(:last-of-type) { display: none; }

  .side section {
    order: 1;
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
  }

  .side section .label { margin: 0; font-size: 9px; }

  canvas#next { width: 42px; height: 42px; margin: 0; }

  .side > .btn.ghost {
    order: 2;
    flex: 0 0 auto;
    padding: 11px 16px;
    font-size: 13px;
  }

  .hint { display: none; }

  .overlay { padding: 14px; }
  .overlay h1 { font-size: 24px; }
  .overlay p { font-size: 11px; max-width: 200px; }
  .overlay .btn { padding: 14px 30px; font-size: 16px; }

  /* Крупные кнопки управления */
  .touch {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    width: 100%;
    max-width: 440px;
    margin-top: auto;
    padding-top: 2px;
  }

  .tbtn {
    font: inherit;
    font-size: 26px;
    line-height: 1;
    min-height: 62px;
    padding: 0;
    color: var(--text);
    background: linear-gradient(180deg, #1b2436, #141a26);
    border: 1px solid #2a3550;
    border-radius: 12px;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    transition: transform .06s ease, background .12s ease;
  }

  .tbtn:active,
  .tbtn.held {
    background: #26344c;
    transform: scale(.97);
  }

  .tbtn-wide { min-height: 56px; font-size: 22px; }

  .tbtn-accent {
    color: #04121a;
    background: linear-gradient(180deg, #35f0ff, #00c4dd);
    border-color: #35f0ff;
  }

  .tbtn-accent:active { background: #63f6ff; }
}

/* Совсем узкие экраны: экономим вертикаль под поле */
@media (max-width: 700px) and (max-height: 700px) {
  .board-wrap {
    width: min(
      100%,
      max(150px, calc((100dvh - 205px) * 0.5)),
      42vw
    );
  }
  .tbtn { min-height: 54px; font-size: 22px; }
  .tbtn-wide { min-height: 48px; }
}

/* Ландшафт на телефоне: поле слева, кнопки справа */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 560px) {
  body {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 10px;
  }
  .hud { display: none; }
  .app { flex-direction: column; width: auto; }
  .board-wrap {
    width: min(max(160px, calc((100dvh - 24px) * 0.5)), 34vw);
  }
  .touch {
    width: min(40vw, 240px);
    margin-top: 0;
    grid-template-columns: repeat(3, 1fr);
  }
  .tbtn { min-height: 46px; font-size: 20px; }
  .tbtn-wide { min-height: 42px; }
}
