:root {
  color-scheme: dark;
  --bg: #170f22;
  --panel: rgba(18, 12, 28, 0.86);
  --card: rgba(255, 255, 255, 0.05);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f3eef6;
  --muted: #b3a9bd;
  --accent: #ffb547;
  --on-accent: #1a1204;
  --hp: #ffcf4d;
  --hp-low: #ff6b4a;
  --sans: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --mono: "Cascadia Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  display: block;
  touch-action: none;
}

/* HUD: two health bars and the timer */

.hud {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}
.side { display: grid; gap: 5px; min-width: 0; }
.who { display: flex; align-items: center; gap: 10px; }
.side.right .who { justify-content: flex-end; }
.nm { font-size: 1.05rem; font-weight: 800; letter-spacing: 0.01em; white-space: nowrap; }
.wins { display: inline-flex; gap: 4px; }
.wins i { width: 12px; height: 12px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.5); }
.wins i.on { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 8px rgba(255, 181, 71, 0.8); }
.bar {
  position: relative;
  height: 18px;
  border-radius: 4px;
  background: rgba(20, 8, 12, 0.75);
  border: 2px solid rgba(255, 255, 255, 0.85);
  overflow: hidden;
}
.bar i { position: absolute; inset: 0; transform-origin: left center; }
.side.right .bar i { transform-origin: right center; }
.bar .lag { background: #fff2d6; }
.bar .hp { background: linear-gradient(180deg, #ffe08a, var(--hp) 55%, #e8a52a); }
.bar.low .hp { background: linear-gradient(180deg, #ff9a7a, var(--hp-low) 55%, #c9402a); }
.sp { height: 5px; width: 62%; border-radius: 3px; background: rgba(255, 255, 255, 0.15); overflow: hidden; }
.side.right .sp { justify-self: end; }
.sp i { display: block; height: 100%; background: #7fc8ff; transform-origin: left center; }
.side.right .sp i { transform-origin: right center; }
.sp.ready i { background: #9fe8ff; box-shadow: 0 0 8px #9fe8ff; }
.mid { display: grid; justify-items: center; gap: 6px; }
.timer {
  margin: 0;
  min-width: 2.2ch;
  text-align: center;
  font-family: var(--mono);
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1;
  color: var(--accent);
  letter-spacing: -0.04em;
}
.timer.low { color: #ff6b5b; }
.hud-btns { display: flex; gap: 6px; pointer-events: auto; }
.icon-btn {
  min-width: 34px;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(18, 12, 28, 0.55);
  font-weight: 700;
  font-size: 0.75rem;
  cursor: pointer;
}
.icon-btn[aria-pressed="false"] { opacity: 0.45; text-decoration: line-through; }

.combo {
  position: fixed;
  left: max(16px, env(safe-area-inset-left));
  top: calc(max(12px, env(safe-area-inset-top)) + 70px);
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 2px 0 #2a0f06, 0 0 10px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  opacity: 0;
  transform: translateX(-12px);
  transition: opacity 0.2s, transform 0.2s;
}
.combo.right { left: auto; right: max(16px, env(safe-area-inset-right)); transform: translateX(12px); }
.combo.show { opacity: 1; transform: none; }

@media (max-width: 560px) {
  .hud { gap: 8px; padding-left: 10px; padding-right: 10px; }
  .nm { font-size: 0.85rem; }
  .bar { height: 14px; }
  .timer { font-size: 1.8rem; }
  .wins i { width: 9px; height: 9px; }
  .icon-btn { min-width: 30px; height: 30px; padding: 0 7px; font-size: 0.7rem; }
  #muteBtn { display: none; }
  .combo { font-size: 1.1rem; top: calc(max(12px, env(safe-area-inset-top)) + 60px); }
}

/* banner: big Kazakh word plus a small translation */

.banner {
  position: fixed;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  width: max-content;
  max-width: 94vw;
}
.banner.show { animation: banner var(--dur, 1.6s) ease-out forwards; }
.banner b {
  display: block;
  font-size: clamp(2.2rem, min(11vw, 15vh), 5.6rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1;
  color: #ffd25a;
  -webkit-text-stroke: 2px #2a0f06;
  text-shadow: 0 4px 0 #2a0f06, 0 10px 30px rgba(0, 0, 0, 0.6);
}
.banner span { display: block; margin-top: 10px; font-size: 1.15rem; font-weight: 800; color: var(--text); text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8); }
.banner.red b { color: #ff7a5a; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.6); }
  10% { opacity: 1; transform: translate(-50%, -50%) scale(0.95); }
  16% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* touch controls */

.touch { position: fixed; inset: auto 0 0 0; height: 40dvh; pointer-events: none; }
.stick {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 50%;
  height: 100%;
  pointer-events: auto;
  touch-action: none;
}
.stick .base {
  position: absolute;
  left: max(80px, 22%);
  top: 58%;
  width: 104px;
  height: 104px;
  margin: -52px 0 0 -52px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.28);
  background: rgba(18, 12, 28, 0.35);
}
.stick .knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
}
.stick.on .base { border-color: rgba(255, 181, 71, 0.7); }
.btns {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 70px 70px;
  grid-template-rows: 70px 70px;
  gap: 12px;
  pointer-events: auto;
}
.tbtn {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(18, 12, 28, 0.5);
  font-weight: 800;
  font-size: 0.8rem;
  touch-action: none;
  padding: 0;
}
.tbtn.punch { border-color: rgba(255, 210, 90, 0.75); color: #ffd25a; }
.tbtn.kick { border-color: rgba(255, 140, 90, 0.75); color: #ff9a6a; }
.tbtn.block { border-color: rgba(159, 224, 255, 0.7); color: #9fe0ff; }
.tbtn.special { border-color: rgba(200, 160, 255, 0.75); color: #d6b8ff; }
.tbtn.special.cool { opacity: 0.4; }
.tbtn.on { background: rgba(255, 255, 255, 0.3); }
@media (orientation: landscape) {
  .touch { height: 46dvh; }
  .btns { grid-template-columns: 62px 62px; grid-template-rows: 62px 62px; gap: 10px; }
  .tbtn { width: 62px; height: 62px; }
}

/* panels */

#ui:empty { display: none; }

.panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(460px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow: auto;
  overscroll-behavior: contain;
  display: grid;
  gap: 14px;
  justify-items: start;
  align-content: start;
  padding: 24px 24px 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  user-select: text;
  -webkit-user-select: text;
}
.panel.wide { width: min(780px, calc(100vw - 24px)); }
.panel-top { width: 100%; display: flex; align-items: center; justify-content: space-between; }
.mark { width: 34px; height: 6px; border-radius: 3px; background: var(--accent); }
.panel h1 { margin: 0; font-size: clamp(2.6rem, 11vw, 3.8rem); font-weight: 900; letter-spacing: -0.04em; line-height: 1; }
.panel h1 small { display: block; margin-top: 6px; font-size: 0.95rem; letter-spacing: 0.02em; font-weight: 700; color: var(--accent); }
.panel h2 { margin: 0; font-size: 1.7rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; }
.panel h3 { margin: 4px 0 0; font-size: 1.05rem; font-weight: 800; }
.panel p { margin: 0; }
.tag { color: var(--muted); font-size: 1.0625rem; line-height: 1.45; }
.keys { font-family: var(--mono); font-size: 0.8125rem; color: var(--muted); line-height: 1.55; }
.links { display: grid; gap: 6px; }
.more { font-size: 0.9rem; color: var(--muted); }
.more:hover { color: var(--text); }
.about { width: 100%; display: grid; gap: 4px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 0.8125rem; color: var(--muted); line-height: 1.45; }
.about a { color: var(--accent); font-weight: 700; }
.note { min-height: 1.3em; font-size: 0.9rem; color: var(--accent); font-weight: 600; }
.row { display: flex; flex-wrap: wrap; gap: 10px; }

.panel-head { width: 100%; display: flex; align-items: center; gap: 12px; }
.panel-head h2 { flex: 1; }
.back {
  width: 40px;
  height: 40px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
}

.top-right { display: flex; align-items: center; gap: 8px; }
.chip-btn { padding: 4px 11px; border: 1px solid var(--line); border-radius: 999px; background: none; font-size: 0.75rem; font-weight: 700; color: var(--muted); cursor: pointer; }
.chip-btn[aria-pressed="true"] { color: var(--text); background: rgba(255, 255, 255, 0.08); }
.langs { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 999px; }
.langs button { border: 0; background: none; padding: 3px 11px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; color: var(--muted); cursor: pointer; }
.langs button[aria-pressed="true"] { background: rgba(255, 255, 255, 0.12); color: var(--text); }

.btn {
  min-height: 46px;
  padding: 11px 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.15s, background-color 0.15s;
}
.btn:active { transform: translateY(1px) scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: #ffc46b; }

.menu { width: 100%; display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
.menu .menu-item.primary { grid-column: 1 / -1; }
.panel.main { width: min(600px, calc(100vw - 24px)); }
.menu-item {
  display: grid;
  gap: 2px;
  justify-items: start;
  width: 100%;
  padding: 13px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  text-align: left;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}
.menu-item:hover:not([disabled]) { border-color: rgba(255, 255, 255, 0.3); }
.menu-item:active:not([disabled]) { transform: scale(0.99); }
.menu-item[disabled] { opacity: 0.5; cursor: default; }
.menu-item b { font-size: 1.15rem; font-weight: 800; }
.menu-item span { font-size: 0.875rem; color: var(--muted); }
.menu-item.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.menu-item.primary span { color: rgba(26, 18, 4, 0.72); }

/* fighter select */

.pick { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.pick-col { display: grid; gap: 8px; align-content: start; }
.pick-col > b { font-size: 0.8125rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.fcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.fcard {
  display: grid;
  gap: 2px;
  padding: 6px 6px 8px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  cursor: pointer;
  text-align: center;
  font-weight: 800;
  font-size: 0.9rem;
}
.fcard canvas { width: 100%; height: auto; display: block; border-radius: 10px; }
.fcard.on { border-color: var(--accent); background: rgba(255, 181, 71, 0.12); }
.fcard.rand { place-content: center; min-height: 100px; font-size: 2rem; color: var(--muted); }
.fcard.rand small { font-size: 0.8rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 7px 14px; border: 1px solid var(--line); border-radius: 999px; background: none; font-size: 0.875rem; font-weight: 700; color: var(--muted); cursor: pointer; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.bio { width: 100%; display: grid; gap: 6px; padding: 12px 14px; border-radius: 12px; background: var(--card); font-size: 0.9rem; line-height: 1.45; color: var(--muted); }
.bio b { color: var(--text); }
.bio p { margin: 0; }

/* how to play */

.moves { width: 100%; margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 0.9rem; }
.moves dt { font-weight: 800; white-space: nowrap; }
.moves dd { margin: 0; color: var(--muted); }

/* result */

.result-title { font-size: clamp(2.2rem, 9vw, 3.4rem) !important; color: #ffd25a; }
.stats { width: 100%; display: grid; grid-template-columns: 1fr auto auto; gap: 6px 16px; font-size: 0.95rem; }
.stats span { color: var(--muted); }
.stats b { font-family: var(--mono); text-align: right; }
.stats .head { font-weight: 800; color: var(--text); font-family: var(--sans); }

@media (max-width: 520px) {
  .panel { padding: 20px 16px 18px; }
  .pick { grid-template-columns: 1fr; gap: 12px; }
  .fcards { grid-template-columns: repeat(3, 1fr); }
  .moves { grid-template-columns: 1fr; gap: 2px; }
  .moves dd { margin-bottom: 6px; }
}

.noscript { position: fixed; inset: 0; display: grid; place-items: center; font-weight: 700; }

/* link preview frame, see ?og in js/main.js */
.og #ui, .og .hud, .og .touch { display: none !important; }
.og-title {
  position: fixed;
  left: 60px;
  top: 48px;
  display: grid;
  gap: 8px;
  text-shadow: 0 4px 0 #2a0f06, 0 8px 24px rgba(0, 0, 0, 0.5);
}
.og-title b { font-size: 112px; font-weight: 900; letter-spacing: -0.04em; line-height: 1; color: #ffd25a; -webkit-text-stroke: 3px #2a0f06; }
.og-title span { font-size: 34px; font-weight: 800; color: #fff; }

@media (prefers-reduced-motion: reduce) {
  .banner.show { animation-timing-function: steps(1); }
  .menu-item, .btn { transition: none; }
}

/* toasts and the replay / waiting badge */

.toasts { position: fixed; left: 50%; top: calc(max(12px, env(safe-area-inset-top)) + 96px); transform: translateX(-50%); display: grid; gap: 6px; justify-items: center; pointer-events: none; z-index: 30; }
.toast { padding: 7px 16px; border-radius: 999px; background: rgba(18, 12, 28, 0.9); border: 1px solid var(--line); font-weight: 800; font-size: 0.95rem; opacity: 0; transform: translateY(-6px); transition: opacity 0.25s, transform 0.25s; white-space: nowrap; }
.toast.gold { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.toast.show { opacity: 1; transform: none; }
.badge { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); padding: 8px 18px; border-radius: 999px; background: rgba(224, 57, 47, 0.92); color: #fff; font-weight: 900; letter-spacing: 0.08em; pointer-events: none; }

/* fighter select: two slots on top, one grid below */

.slots { width: 100%; display: grid; grid-template-columns: minmax(0, 190px) auto minmax(0, 190px); justify-content: center; gap: 14px; align-items: center; }
.slots:has(> :only-child) { grid-template-columns: minmax(0, 210px); }
.slot { display: grid; gap: 2px; padding: 6px 6px 10px; border: 2px solid var(--line); border-radius: 16px; background: var(--card); cursor: pointer; text-align: center; }
.slot canvas { width: 100%; height: auto; display: block; border-radius: 12px; }
.slot.on { border-color: var(--accent); background: rgba(255, 181, 71, 0.12); }
.slot[disabled] { cursor: default; }
.slot small { font-size: 0.75rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.slot b { font-size: 1.05rem; }
.qmark { display: grid; place-items: center; aspect-ratio: 220 / 230; font-size: 4rem; font-weight: 900; color: var(--muted); }
.qmark.small { aspect-ratio: 16 / 9; font-size: 2rem; }
.vs { font-size: 1.6rem; font-weight: 900; color: #ffd25a; -webkit-text-stroke: 1px #2a0f06; }
.fcards, .arenas, .chips, .bio, .tower { width: 100%; }
.select .fcards { grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); }
.arenas { display: grid; grid-template-columns: repeat(auto-fill, minmax(116px, 1fr)); gap: 8px; }
.acard { display: grid; gap: 4px; padding: 4px 4px 7px; border: 2px solid var(--line); border-radius: 12px; background: var(--card); cursor: pointer; font-size: 0.8rem; font-weight: 700; text-align: center; }
.acard img { width: 100%; aspect-ratio: 16 / 9; display: block; border-radius: 8px; object-fit: cover; }
.acard.on { border-color: var(--accent); }
.pick-col { width: 100%; }

/* arcade: story, ladder, ending */

.story-pic { width: min(300px, 100%); height: auto; justify-self: center; border-radius: 16px; border: 1px solid var(--line); }
.story-pic.wide { width: 100%; }
.story-text { font-size: 1.1rem; }
.tower { width: 100%; margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.rung { display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 12px; padding: 4px 12px 4px 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.rung canvas { width: 56px; height: auto; border-radius: 8px; display: block; }
.rung span { display: grid; }
.rung small { color: var(--muted); font-size: 0.78rem; }
.rung.now { border-color: var(--accent); background: rgba(255, 181, 71, 0.14); }
.rung.done { opacity: 0.55; }
.rung .check { font-style: normal; font-weight: 900; color: #7dff8a; }
.goal { color: #ffd25a; font-weight: 700; }
.big-stars { font-size: 2.4rem; font-weight: 900; color: #ffd25a; }
.unlocks { width: 100%; margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.unlocks li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 12px; border-radius: 10px; background: var(--card); color: var(--muted); }
.unlocks li.open { color: var(--text); }
.unlocks li.open span { color: #7dff8a; font-weight: 800; }
.board { width: 100%; margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; }
.row-entry { display: grid; grid-template-columns: 2em 1fr auto; gap: 10px; padding: 7px 10px; border-radius: 10px; }
.row-entry:nth-child(odd) { background: var(--card); }
.row-entry .pos { font-family: var(--mono); color: var(--muted); text-align: right; }
.row-entry .val { font-family: var(--mono); font-weight: 800; }
.board .empty { padding: 10px; color: var(--muted); }
.name-box { width: 100%; display: grid; gap: 6px; }
.name-box label { font-weight: 700; font-size: 0.9rem; }
.name-box .row { flex-wrap: nowrap; }
.name-box input { flex: 1; min-width: 0; height: 46px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255, 255, 255, 0.06); color: var(--text); font: inherit; }
.hint { font-size: 0.82rem; color: var(--muted); line-height: 1.45; }

/* online */

.net-box { width: 100%; display: grid; gap: 10px; }
textarea.code { width: 100%; min-height: 84px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, 0.06); color: var(--text); font-family: var(--mono); font-size: 0.75rem; word-break: break-all; resize: vertical; }

@media (max-width: 520px) {
  .menu { grid-template-columns: 1fr; }
  .slots { gap: 6px; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
  .vs { font-size: 1.1rem; }
  .select .fcards { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .fcard { font-size: 0.72rem; padding: 4px 4px 6px; }
  .arenas { grid-template-columns: repeat(3, 1fr); }
}

/* short room codes when the server is there */
.room-code { margin: 4px 0; font-family: var(--mono); font-size: 2.2rem; font-weight: 800; letter-spacing: 0.3em; text-align: center; color: var(--gold, #ffd25a); }
.room-input { width: 9em; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, 0.06); color: var(--text); font-family: var(--mono); font-size: 1.1rem; letter-spacing: 0.2em; text-transform: uppercase; }
