/* MathRuner — сайт и страница игры. Без сборщиков и библиотек: один файл. */
:root {
  --bg: #11151f;
  --panel: #1a2030;
  --panel-2: #222a3d;
  --line: #2f3a52;
  --text: #e8ecf4;
  --muted: #9aa6bd;
  --accent: #ffb547;
  --accent-2: #5fd0ff;
  --good: #59d98e;
  --bad: #ff6b6b;
  --topbar: 44px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent-2); }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }

/* шапка */
.topbar {
  height: var(--topbar);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: #0b0e15;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.brand { color: var(--accent); font-weight: 700; text-decoration: none; letter-spacing: .5px; }
.player-info { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.topbar-links { margin-left: auto; display: flex; gap: 16px; align-items: center; }
.topbar-links a { color: var(--text); text-decoration: none; opacity: .85; }
.topbar-links a:hover { opacity: 1; text-decoration: underline; }
.link-button { background: none; border: 0; color: var(--text); font: inherit; cursor: pointer; opacity: .85; padding: 0; }
.link-button:hover { opacity: 1; }

/* обычные страницы */
.page { padding: 32px 16px; display: flex; justify-content: center; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
  width: 100%;
  max-width: 460px;
  min-width: 0; /* иначе flex не даёт карточке сжаться, и широкая таблица распирает её за край экрана */
}
.card.wide { max-width: 980px; }
h1 { margin: 0 0 12px; font-size: 26px; }
.lead { color: var(--muted); margin: 0 0 20px; }
.hint { color: var(--muted); font-size: 14px; }
.empty { color: var(--muted); padding: 24px 0; }

form label { display: block; margin-bottom: 14px; color: var(--muted); font-size: 14px; }
form input, form select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
form input:focus, form select:focus { outline: 2px solid var(--accent); border-color: transparent; }
.button {
  display: inline-block;
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  font: inherit;
  font-weight: 700;
  color: #1b1300;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}
.button:hover { filter: brightness(1.08); }
.button.small { width: auto; padding: 6px 12px; margin: 0; }
.button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.form-error {
  background: rgba(255, 107, 107, .12);
  border: 1px solid var(--bad);
  color: #ffd0d0;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 16px;
}

/* главная: форма входа + верх таблицы рекордов; на узком экране — одно под другим */
.home {
  display: grid;
  grid-template-columns: minmax(0, 420px) minmax(0, 560px);
  gap: 24px;
  align-items: start;
  justify-content: center;
  width: 100%;
}
.home .card { max-width: none; }
.home-board h2 { margin: 0; font-size: 22px; }
.home-board .board-head { margin-bottom: 4px; }
@media (max-width: 900px) {
  .home { grid-template-columns: minmax(0, 560px); }
}

/* таблица рекордов */
.board-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.group-filter select { width: auto; min-width: 160px; margin: 0; }
.my-place { background: var(--panel-2); border-radius: 8px; padding: 10px 14px; }
.table-wrap { overflow-x: auto; }
table.board { width: 100%; border-collapse: collapse; margin-top: 8px; }
.board th, .board td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.board th { color: var(--muted); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: .4px; }
.board .num { text-align: right; font-variant-numeric: tabular-nums; }
.board td.place { width: 42px; color: var(--muted); font-weight: 700; }
.board tr.top1 td.place { color: #ffd34d; }
.board tr.top2 td.place { color: #d6dde8; }
.board tr.top3 td.place { color: #e0a070; }
.board tr.me { background: rgba(255, 181, 71, .12); }
@media (max-width: 640px) {
  .board .opt { display: none; }
  .board th, .board td { padding: 8px 6px; }
  .card { padding: 20px 14px; }
  .page { padding: 16px 10px; }
  h1 { font-size: 22px; }
  .topbar { gap: 10px; padding: 0 10px; }
  .topbar-links { gap: 12px; }
}

/* страница игры */
body.game-page { overflow: hidden; }
.game-area {
  position: fixed;
  top: var(--topbar);
  left: 0; right: 0; bottom: 0;
  background: #000;
}
#unity-canvas { width: 100%; height: 100%; display: block; background: #000; outline: none; }
.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--bg);
  padding: 20px;
  text-align: center;
}
.loading-title { font-size: 20px; }
.progress { width: min(360px, 80vw); height: 10px; background: var(--panel-2); border-radius: 5px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.loading-hint { color: var(--muted); font-size: 14px; max-width: 420px; }
.loading.failed .progress { display: none; }
.loading.failed .loading-title { color: var(--bad); }

.rotate-hint { display: none; }
@media (orientation: portrait) and (max-width: 820px) {
  .rotate-hint {
    display: flex;
    position: absolute;
    inset: 0;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
    font-size: 20px;
    background: rgba(17, 21, 31, .96);
    z-index: 5;
  }
}
@media (max-height: 480px) {
  :root { --topbar: 32px; }
  .topbar { gap: 10px; font-size: 13px; }
  .player-info { display: none; }
}

/* окно результата поверх игры */
.run-result {
  position: fixed;
  top: calc(var(--topbar) + 12px);
  right: 12px;
  width: min(360px, calc(100vw - 24px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
  z-index: 10;
}
.run-result[hidden] { display: none; }
.run-result h2 { margin: 0 0 8px; font-size: 18px; }
.run-result .big { font-size: 28px; font-weight: 700; color: var(--accent); }
.run-result .pb { color: var(--good); font-weight: 700; }
.run-result .err { color: var(--bad); }
.run-result .row { display: flex; gap: 8px; margin-top: 12px; }
.run-result .row .button { margin: 0; padding: 8px; font-size: 14px; }
.run-result .close {
  position: absolute; top: 8px; right: 10px;
  background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer;
}
