/* Спокойная светлая тема: тёплый фон, тёмный текст, один терракотовый акцент. */
:root {
  --bg: #faf9f5;
  --surface: #ffffff;
  --surface-2: #f0eee6;
  --border: #e6e3d9;
  --border-strong: #d4d0c3;
  --text: #1f1e1d;
  --muted: #6f6c64;
  --accent: #c96442;
  --accent-hover: #b4563a;
  --accent-soft: #f6e7df;
  --pos: #3d7a4f;
  --neg: #b4453a;
  --radius: 12px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #262624;
    --surface: #30302e;
    --surface-2: #3a3a37;
    --border: #41403c;
    --border-strong: #55534d;
    --text: #f0eee6;
    --muted: #a8a59b;
    --accent: #d97757;
    --accent-hover: #e38a6c;
    --accent-soft: #4a3329;
    --pos: #7fbf8e;
    --neg: #e3887c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
img { max-width: 100%; display: block; }
h1, h2, h3 { font-family: var(--serif); font-weight: 500; line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 32px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.inline { display: inline; margin: 0; }

.wrap { width: 100%; max-width: 1240px; margin: 0 auto; padding: 0 20px; }
.main { flex: 1; padding-top: 28px; padding-bottom: 48px; }

/* Шапка */
.topbar { background: var(--bg); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-in { display: flex; align-items: center; gap: 24px; min-height: 60px; flex-wrap: wrap; }
.logo { display: inline-flex; align-items: center; gap: 9px; font-family: var(--serif); font-size: 23px; text-decoration: none; letter-spacing: -.01em; }
.logo-mark { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); box-shadow: inset -3px -3px 0 rgba(0, 0, 0, .12); }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a { text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 8px; }
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { color: var(--text); background: var(--surface-2); }
.user-box { display: flex; align-items: center; gap: 8px; }
.balance-pill {
  text-decoration: none; font-weight: 600; font-variant-numeric: tabular-nums;
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
}

/* Кнопки и формы */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 500; text-decoration: none; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: 9px 16px; border-radius: 10px; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--neg); }
.btn-sm { padding: 6px 12px; font-size: 14px; }
.btn-block { width: 100%; }

label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 10px; padding: 9px 12px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.check { display: flex; gap: 8px; align-items: flex-start; color: var(--text); }
.check input { margin-top: 4px; }
.field { margin-bottom: 16px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 4px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1; min-width: 160px; }

.card-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.narrow { max-width: 420px; margin: 24px auto; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; }
.stack > * + * { margin-top: 20px; }

.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 20px; border: 1px solid var(--border); background: var(--surface); }
.alert-error { border-color: #e6b8b0; background: #fbeeeb; color: #8a3127; }
.alert-success { border-color: #bfd8c4; background: #edf5ee; color: #2d5e3a; }
.alert-info { background: var(--surface-2); }
@media (prefers-color-scheme: dark) {
  .alert-error { background: #43302c; border-color: #6b443d; color: #f0c0b7; }
  .alert-success { background: #2c3b2f; border-color: #45604b; color: #bfe0c6; }
}

/* Лобби */
.lobby-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.lobby-head h1 { margin: 0; }
.search { display: flex; gap: 8px; min-width: 280px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 24px; }
.chip {
  text-decoration: none; font-size: 14px; color: var(--muted);
  border: 1px solid var(--border); background: var(--surface); padding: 5px 12px; border-radius: 999px;
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip.active { color: var(--text); border-color: var(--text); }
.chip .count { opacity: .6; margin-left: 4px; }

.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 20px; }
.game { display: flex; flex-direction: column; }
.game-thumb {
  position: relative; aspect-ratio: 1 / 1; border-radius: var(--radius); overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border);
}
.game-thumb img { position: relative; width: 100%; height: 100%; object-fit: cover; }
.game-fallback {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 12px; font-family: var(--serif); font-size: 17px; color: var(--muted);
}
.game-thumb .badge { position: absolute; top: 8px; left: 8px; }
.game-actions {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 8px; align-items: center; justify-content: center;
  background: rgba(31, 30, 29, .55); opacity: 0; transition: opacity .15s;
}
.game-thumb:hover .game-actions, .game-thumb:focus-within .game-actions { opacity: 1; }
.game-actions .btn { min-width: 110px; }
.game-actions .btn-demo { background: rgba(255,255,255,.92); border-color: transparent; color: #1f1e1d; }
.game-name { margin-top: 10px; font-weight: 500; line-height: 1.3; }
.game-name a { text-decoration: none; }
.game-provider { font-size: 13px; color: var(--muted); }
@media (hover: none) {
  .game-actions { position: static; opacity: 1; background: none; flex-direction: row; padding: 8px 0 0; }
  .game-thumb { overflow: visible; aspect-ratio: auto; background: none; border: 0; }
  .game-thumb img { aspect-ratio: 1 / 1; border-radius: var(--radius); border: 1px solid var(--border); }
  .game-fallback { position: static; aspect-ratio: 1 / 1; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); }
  .game-fallback:has(+ img) { display: none; }
  .game-actions .btn { min-width: 0; flex: 1; padding: 6px 8px; font-size: 13px; }
  .game-actions .btn-demo { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); }
}
.badge {
  display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
.badge-accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.empty { text-align: center; padding: 64px 20px; color: var(--muted); }

/* Экран игры */
body.play { height: 100vh; overflow: hidden; }
body.play .main { padding: 0; max-width: none; display: flex; flex-direction: column; }
body.play .footer { display: none; }
.play-bar { display: flex; align-items: center; gap: 12px; padding: 8px 20px; border-bottom: 1px solid var(--border); }
.play-bar .title { font-family: var(--serif); font-size: 18px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.play-frame { flex: 1; width: 100%; border: 0; background: #000; }

/* Таблицы */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-weight: 500; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td .thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.copy-line { display: flex; gap: 8px; }
.copy-line input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-family: var(--serif); font-size: 26px; margin-top: 4px; font-variant-numeric: tabular-nums; }

.pager { display: flex; gap: 16px; align-items: center; justify-content: center; margin: 28px 0 0; color: var(--muted); }
.pager a { text-decoration: none; color: var(--text); border: 1px solid var(--border-strong); padding: 6px 14px; border-radius: 10px; background: var(--surface); }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 32px 0 12px; }
.section-title h2 { margin: 0; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar input, .toolbar select { width: auto; }
.prose { white-space: pre-line; }

.footer { border-top: 1px solid var(--border); color: var(--muted); font-size: 14px; }
.footer-in { display: flex; gap: 20px; align-items: center; padding: 20px; flex-wrap: wrap; }
.footer .age { border: 1px solid var(--border-strong); border-radius: 6px; padding: 0 6px; font-weight: 600; font-size: 12px; }

@media (max-width: 720px) {
  .wrap { padding: 0 16px; }
  h1 { font-size: 26px; }
  .topbar-in { gap: 10px; padding-top: 8px; padding-bottom: 8px; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .nav a { white-space: nowrap; }
  .user-box { margin-left: auto; }
  .games { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
  .search { min-width: 0; width: 100%; }
  .card-box { padding: 18px; }
  .play-bar { padding: 6px 12px; }
}
