/* Бәйге — бір ғана көркем әлем: киіз-қоңыр панельдер, алтын ою, көгілдір ту түсі.
   Layout: 3D сахна толық экранда; ауыл режимінде панель сол жақта (телефонда төменде). */
:root {
  --ink: #15100c;
  --panel: rgba(28, 20, 14, 0.88);
  --panel-solid: #1f1711;
  --line: #5a4632;
  --text: #f4ead8;
  --muted: #bfae92;
  --gold: #e3b04b;
  --gold-deep: #b98524;
  --sky: #14b8c9;
  --red: #d4553a;
  --green: #7fc46a;
  --display: "Unbounded", "Golos Text", system-ui, sans-serif;
  --body: "Golos Text", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --r: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; overflow: hidden; background: var(--ink); color: var(--text);
  font: 15px/1.45 var(--body); -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
.layer, .overlay { position: absolute; inset: 0; pointer-events: none; }
.toasts { pointer-events: none; }
.layer > *, .overlay > *, .toasts > *, .modal-wrap, .loading { pointer-events: auto; }
[hidden] { display: none !important; }

h1, h2, h3, h4 { margin: 0; font-family: var(--display); font-weight: 700; text-wrap: balance; letter-spacing: 0.01em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.02rem; }
h4 { font-size: 0.92rem; font-family: var(--body); font-weight: 700; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.mono { font-variant-numeric: tabular-nums; }
.eyebrow { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--gold); font-weight: 600; }
.warn { color: #ffd59a; background: rgba(212, 85, 58, 0.18); border: 1px solid rgba(212, 85, 58, 0.5); padding: 8px 12px; border-radius: var(--r); font-size: 0.86rem; }

.brand { font-family: var(--display); font-weight: 900; letter-spacing: 0.08em; color: var(--gold); }
.brand.big { font-size: clamp(3.2rem, 11vw, 6.5rem); line-height: 0.95; text-shadow: 0 4px 30px rgba(0, 0, 0, 0.55); }
.brand.link { background: none; border: 0; padding: 0; font-size: 1.15rem; cursor: pointer; }

.ornament {
  height: 16px; width: min(320px, 70vw); opacity: 0.9;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='16' viewBox='0 0 40 16'%3E%3Cpath d='M2 14C2 6 8 2 13 5c4 3 1 8-2 6-2-1-1-4 1-3M38 14c0-8-6-12-11-9-4 3-1 8 2 6 2-1 1-4-1-3M13 5q7-4 14 0' fill='none' stroke='%23e3b04b' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") repeat-x center / 40px 16px;
}

/* ---------- Батырмалар ---------- */
.btn {
  font: 600 0.92rem var(--body); color: var(--text); background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line); border-radius: 999px; padding: 10px 18px; cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.08s; min-height: 42px;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); border-color: #7b6146; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible, .tab:focus-visible, .card:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--sky); outline-offset: 2px; }
.btn.primary { background: var(--gold); color: #24170a; border-color: var(--gold); }
.btn.primary:hover:not(:disabled) { background: #f0c164; }
.btn.danger { background: transparent; border-color: var(--red); color: #ffb4a3; }
.btn.ghost { background: transparent; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: 0.82rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35); }

/* ---------- Жүктеу ---------- */
.loading {
  position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 18px;
  background: radial-gradient(circle at 50% 40%, #2a1f16, var(--ink) 70%); z-index: 20; text-align: center;
  padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px));
}
.progress { width: min(320px, 80vw); height: 6px; border-radius: 6px; background: #2e241b; overflow: hidden; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold-deep), var(--gold)); transition: width 0.2s; }
.loading.error .progress { display: none; }
.loading.error p { color: #ffb4a3; max-width: 40ch; }

/* ---------- Мәзір ---------- */
.menu {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; gap: 28px;
  padding-block: 32px; padding-left: max(5vw, 16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: linear-gradient(90deg, rgba(21, 16, 12, 0.88) 0%, rgba(21, 16, 12, 0.55) 38%, rgba(21, 16, 12, 0) 62%);
}
.menu-head { display: grid; gap: 12px; max-width: 34rem; }
.lede { font-size: 1.05rem; max-width: 30ch; color: #eadfca; }
.menu-actions { display: grid; gap: 10px; width: min(320px, 100%); }
.menu-actions .btn { text-align: left; padding-inline: 20px; }
.panel.narrow { width: min(420px, 100%); padding: 24px; display: grid; gap: 14px; }
.field { display: grid; gap: 6px; font-size: 0.82rem; color: var(--muted); }
input, select {
  font: 500 1rem var(--body); color: var(--text); background: #120d09; border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; width: 100%;
}

/* ---------- Ауыл ---------- */
.hub {
  position: absolute; top: 0; bottom: 0; left: 0; width: min(470px, 100%); display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--line); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding-block: 14px 10px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: 16px;
}
.who { display: grid; line-height: 1.2; min-width: 0; }
.who strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.money { margin-left: auto; font: 700 1.05rem var(--display); color: var(--gold); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 4px; padding-inline: 12px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tab {
  font: 600 0.86rem var(--body); color: var(--muted); background: none; border: 0; padding: 10px 10px 12px;
  cursor: pointer; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.on { color: var(--text); border-bottom-color: var(--gold); }
.hub-body { flex: 1; overflow-y: auto; padding-block: 14px 24px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: 16px; display: grid; align-content: start; gap: 12px; }
.hub-foot { display: flex; gap: 8px; align-items: baseline; padding: 10px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; padding-bottom: max(10px, env(safe-area-inset-bottom, 0px)); }
.lead-note { margin-bottom: 2px; }
.list { display: grid; gap: 10px; }
.list.compact { gap: 6px; }
h3.group { margin-top: 8px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--gold); font-family: var(--body); }

.card { background: rgba(255, 255, 255, 0.035); border: 1px solid #3c2f22; border-radius: var(--r); padding: 14px; display: grid; gap: 10px; min-width: 0; }
.card.active { border-color: var(--gold-deep); }
.card.market { cursor: pointer; }
.card.market.sel { border-color: var(--sky); background: rgba(20, 184, 201, 0.07); }
.card.locked { opacity: 0.55; }
.card-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.card-head > div { min-width: 0; }
.price, .dist { font: 700 0.98rem var(--display); color: var(--gold); white-space: nowrap; font-variant-numeric: tabular-nums; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; font-size: 0.86rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; min-width: 0; }
.stats { display: grid; gap: 5px; }
.stat { display: grid; grid-template-columns: 6.6rem 1fr 4.2rem; gap: 8px; align-items: center; font-size: 0.8rem; }
.stat-name { color: var(--muted); }
.stat-val { text-align: right; font-variant-numeric: tabular-nums; }
.stat-val em { color: var(--gold); font-style: normal; font-size: 0.75rem; }
.bar { position: relative; height: 6px; border-radius: 4px; background: #33281d; overflow: hidden; display: block; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; background: #d9cbb0; border-radius: 4px; }
.bar b { position: absolute; top: 0; bottom: 0; background: var(--gold); }
.gear-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 0.76rem; padding: 3px 9px; border-radius: 999px; border: 1px solid #4a3a2a; color: var(--muted); }
.chip.on { color: var(--text); border-color: #6b5439; }
.chip small { color: var(--muted); font-size: 0.72rem; }
.chip.gold { color: #24170a; background: var(--gold); border-color: var(--gold); font-weight: 600; margin-left: 8px; }
.chip.lock { border-style: dashed; }
.chip .x { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 0 0 2px; }
.item { grid-template-columns: 1fr auto; align-items: center; padding: 10px 12px; }
.item-main { display: flex; gap: 10px; align-items: center; min-width: 0; }
.swatch { width: 22px; height: 22px; border-radius: 6px; border: 3px solid; flex: none; }
.empty { padding: 22px; display: grid; gap: 12px; justify-items: start; }

/* ---------- Модаль, хабарлама ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(8, 6, 4, 0.55); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal { width: min(460px, 100%); padding: 22px; display: grid; gap: 14px; background: var(--panel-solid); max-height: 90vh; overflow-y: auto; }
.prose { display: grid; gap: 10px; font-size: 0.9rem; max-width: 62ch; }
.prose h3 { font-size: 0.86rem; color: var(--gold); margin-top: 4px; }
.toasts { position: fixed; top: max(14px, env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%); display: grid; gap: 6px; z-index: 30; width: min(440px, calc(100% - 32px)); }
.toast { background: var(--panel-solid); border: 1px solid var(--line); border-left: 4px solid var(--gold); padding: 10px 14px; border-radius: 10px; font-size: 0.88rem; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); transition: opacity 0.4s, transform 0.4s; }
.toast.bad { border-left-color: var(--red); }
.toast.good { border-left-color: var(--green); }
.toast.speed { border-left-color: var(--sky); }
.toast.out { opacity: 0; transform: translateY(-6px); }

/* ---------- Жарыс HUD ---------- */
.hud { position: absolute; inset: 0; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud-top {
  position: absolute; top: 0; left: 0; right: 0; display: flex; gap: 8px; align-items: flex-start;
  padding-top: max(12px, env(safe-area-inset-top, 0px)); padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  pointer-events: none;
}
.hud-top > * { pointer-events: auto; }
.grow { flex: 1; }
.hud-box { background: rgba(21, 16, 12, 0.78); border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px; display: grid; gap: 0; line-height: 1.2; }
.hud-box .pos { font: 900 1.6rem var(--display); color: var(--gold); font-variant-numeric: tabular-nums; }
.hud-box span { font-variant-numeric: tabular-nums; white-space: nowrap; }
.hud-box .pos { white-space: nowrap; }
.hud-side { position: absolute; top: calc(max(12px, env(safe-area-inset-top, 0px)) + 66px); right: max(16px, env(safe-area-inset-right, 0px)); display: grid; gap: 8px; justify-items: end; pointer-events: none; }
.minimap { width: 180px; height: 110px; background: rgba(21, 16, 12, 0.6); border: 1px solid var(--line); border-radius: 10px; }
.standings { list-style: none; margin: 0; padding: 6px 8px; background: rgba(21, 16, 12, 0.6); border: 1px solid var(--line); border-radius: 10px; font-size: 0.78rem; display: grid; gap: 1px; min-width: 150px; }
.standings li { display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.standings li.me { color: var(--gold); font-weight: 700; }
.standings .n { width: 1.2em; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; border: 1px solid rgba(0, 0, 0, 0.5); margin-right: 4px; }
.hud-bottom { position: absolute; left: max(16px, env(safe-area-inset-left, 0px)); bottom: max(14px, env(safe-area-inset-bottom, 0px)); display: grid; gap: 6px; pointer-events: none; }
.meter { min-width: 230px; gap: 6px; }
.meter .speed { font: 900 2rem var(--display); }
.stam { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; }
.stam .bar { height: 8px; }
.stam .bar i { background: var(--green); width: 100%; transition: width 0.15s; }
.stam .bar i.low { background: var(--red); }
.stam .bar { overflow: visible; }
.stam .bar u { position: absolute; top: -4px; bottom: -4px; width: 2px; background: #fff; border-radius: 1px; box-shadow: 0 0 0 1px rgba(0,0,0,.5); }
.stam .bar.ready { box-shadow: 0 0 0 2px var(--gold); }
.chip.boost { color: #052b30; background: var(--sky); border-color: var(--sky); font-weight: 700; justify-self: start; }
.keys { background: rgba(21, 16, 12, 0.5); padding: 3px 8px; border-radius: 6px; }
.hint { max-width: 300px; }
.touch { display: none; }
.ctl {
  font: 800 1.05rem var(--display); color: var(--text); background: rgba(21, 16, 12, 0.6); border: 2px solid rgba(244, 234, 216, 0.4);
  border-radius: 50%; width: 68px; height: 68px; touch-action: none; user-select: none; -webkit-user-select: none; cursor: pointer;
}
.ctl.down { background: rgba(227, 176, 75, 0.85); color: #24170a; border-color: var(--gold); }
.ctl.whip { width: 104px; height: 104px; font-size: 0.95rem; border-color: rgba(227, 176, 75, 0.7); }

.intro {
  position: absolute; left: max(16px, env(safe-area-inset-left, 0px)); bottom: max(16px, env(safe-area-inset-bottom, 0px));
  width: min(440px, calc(100% - 32px)); padding: 16px 18px; display: grid; gap: 12px; animation: rise 0.35s ease-out;
}
.intro-head { display: flex; gap: 12px; align-items: center; }
.intro h2 { font-size: 1.5rem; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.num { width: 46px; height: 46px; border-radius: 10px; display: grid; place-items: center; font: 900 1.35rem var(--display); color: #fff; text-shadow: 0 1px 3px #000; border: 2px solid rgba(255, 255, 255, 0.7); flex: none; }
.facts.two { grid-template-columns: auto 1fr; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.countdown { position: absolute; inset: 0; display: grid; place-items: center; font: 900 clamp(4rem, 18vw, 9rem) var(--display); color: var(--gold); text-shadow: 0 6px 30px rgba(0, 0, 0, 0.6); pointer-events: none !important; }
.countdown.pop { animation: pop 0.9s ease-out; }
.countdown.go { color: #fff; animation: pop 0.9s ease-out; }
@keyframes pop { from { transform: scale(1.5); opacity: 0; } 25% { opacity: 1; } to { transform: scale(1); opacity: 0.9; } }
.banner { position: absolute; top: 22%; left: 50%; transform: translateX(-50%); text-align: center; display: grid; gap: 4px; background: rgba(21, 16, 12, 0.8); border: 1px solid var(--gold-deep); border-radius: 14px; padding: 14px 28px; pointer-events: none !important; }
.banner strong { font: 900 2.4rem var(--display); color: var(--gold); }

/* ---------- Нәтижелер ---------- */
.results { position: absolute; inset: 0; overflow-y: auto; display: grid; place-items: start center; padding-block: max(20px, env(safe-area-inset-top, 0px)) 24px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); background: rgba(10, 7, 5, 0.45); }
.panel.wide { width: min(940px, 100%); padding: 22px; display: grid; gap: 16px; }
.res-head { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.res-head > div { display: grid; gap: 4px; min-width: 0; flex: 1; }
.place-big { font: 900 4.4rem/1 var(--display); color: var(--text); display: flex; align-items: baseline; gap: 2px; }
.place-big small { font-size: 1.2rem; color: var(--muted); }
.place-big.win { color: var(--gold); }
.res-head > .place-big { display: flex; flex: none; }
.prize { font: 700 1.3rem var(--display); color: var(--green); }
.prize.none { color: var(--muted); font-size: 1.05rem; }
.unlock { background: rgba(20, 184, 201, 0.13); border: 1px solid var(--sky); border-radius: 10px; padding: 10px 14px; font-size: 0.9rem; }
.table-wrap { overflow-x: auto; border: 1px solid #3c2f22; border-radius: 10px; }
.res-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; min-width: 640px; }
.res-table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em; padding: 9px 10px; border-bottom: 1px solid #3c2f22; }
.res-table td { padding: 8px 10px; border-bottom: 1px solid #2c2219; vertical-align: middle; }
.res-table tr.me td { background: rgba(227, 176, 75, 0.12); }
.res-table tr:last-child td { border-bottom: 0; }

/* ---------- Телефон ---------- */
@media (max-width: 819px) {
  .menu { justify-content: flex-end; background: linear-gradient(0deg, rgba(21, 16, 12, 0.92) 0%, rgba(21, 16, 12, 0.6) 55%, rgba(21, 16, 12, 0) 80%); }
  .hub { top: auto; height: 62%; width: 100%; border-right: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; }
  .facts.two { grid-template-columns: auto 1fr; }
  .intro { padding: 12px 14px; gap: 8px; bottom: max(10px, env(safe-area-inset-bottom, 0px)); }
  .intro .stats { display: none; }
  .intro h2 { font-size: 1.2rem; }
  .standings { display: none; }
  .res-table { min-width: 0; font-size: 0.8rem; }
  .res-table th:nth-child(4), .res-table td:nth-child(4), .res-table th:nth-child(6), .res-table td:nth-child(6) { display: none; }
  .res-table th, .res-table td { padding: 7px 6px; }
  .place-big { font-size: 3.2rem; }
  .panel.wide { padding: 16px; }
  .minimap { width: 130px; height: 80px; }
  .hud-side { top: calc(max(12px, env(safe-area-inset-top, 0px)) + 64px); }
}
@media (pointer: coarse), (max-width: 819px) {
  .touch {
    display: flex; position: absolute; left: 0; right: 0; bottom: 0; justify-content: space-between; align-items: flex-end; pointer-events: none;
    padding-bottom: max(16px, env(safe-area-inset-bottom, 0px)); padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  }
  .touch > * { pointer-events: auto; }
  .pad { display: flex; gap: 12px; }
  .keys { display: none; }
  .hud-bottom { bottom: calc(max(16px, env(safe-area-inset-bottom, 0px)) + 112px); }
  .meter { min-width: 0; width: min(230px, 60vw); }
  .meter .speed { font-size: 1.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
