/* БАЗАР — Бык vs Медведь (арена 1v1) */
:root {
  --bazar-lime: #adff00;
  --bazar-lime-hover: #9eeb00;
  --bazar-lime-soft: rgba(173, 255, 0, 0.18);
  --bazar-black: #000;
  --bazar-text: #f2f0f7;
  --bazar-text-secondary: #a89fc0;
  --bazar-muted: #7a7196;
  --bazar-bg: #0e0819;
  --bazar-surface: #1a1230;
  --bazar-card: #221a3a;
  --bazar-border: rgba(255, 255, 255, 0.08);
  --bazar-border-strong: rgba(255, 255, 255, 0.14);
  --bull: #adff00;
  --bull-deep: #60b900;
  --bear: #ff4545;
  --bear-deep: #c62828;
  --bazar-radius-md: 16px;
  --bazar-radius-lg: 24px;
  --bazar-radius-pill: 99px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --control-min: 48px;
  --font-display: "Montserrat", system-ui, sans-serif;
  --font-body: "Roboto", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bazar-bg);
  color: var(--bazar-text);
  font-family: var(--font-body);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  min-height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  min-height: 0;
  position: relative;
  background: radial-gradient(120% 80% at 50% 0%, #1c1233 0%, #0e0819 55%, #090512 100%);
  box-shadow: 0 0 0 1px var(--bazar-border);
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px 10px;
  border-bottom: 0.5px solid var(--bazar-border);
  z-index: 2;
  background: linear-gradient(180deg, rgba(26, 18, 48, 0.95) 0%, rgba(14, 8, 25, 0.4) 100%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bazar-lime);
  flex-shrink: 0;
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
}

.brand-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.06em;
}

.brand-sub {
  font-size: 11px;
  color: var(--bazar-text-secondary);
  margin-top: 2px;
}

.conn-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--bazar-radius-pill);
  background: rgba(255, 255, 255, 0.06);
  font-size: 11px;
  font-weight: 600;
  color: var(--bazar-muted);
}

.conn-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bazar-muted);
}

.conn-pill.is-on {
  color: var(--bazar-text);
  background: rgba(96, 185, 0, 0.15);
}

.conn-pill.is-on .dot {
  background: #60b900;
  box-shadow: 0 0 0 3px rgba(96, 185, 0, 0.25);
}

.conn-pill.is-err .dot {
  background: var(--bear);
}

/* Score */
.score-bar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
  padding: 10px 14px 8px;
  border-bottom: 0.5px solid var(--bazar-border);
  z-index: 2;
}

.score-side .role-tag {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.score-side.bull .role-tag {
  color: var(--bull);
}

.score-side.bear .role-tag {
  color: var(--bear);
  text-align: right;
}

.score-name {
  font-size: 12px;
  font-weight: 700;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-side.bear .score-name {
  text-align: right;
}

.score-pips {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}

.score-side.bear .score-pips {
  justify-content: flex-end;
}

.pip {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: transparent;
}

.pip.on.bull {
  background: var(--bull);
  border-color: var(--bull);
  box-shadow: 0 0 8px rgba(173, 255, 0, 0.45);
}

.pip.on.bear {
  background: var(--bear);
  border-color: var(--bear);
  box-shadow: 0 0 8px rgba(255, 69, 69, 0.45);
}

.score-mid {
  text-align: center;
  min-width: 72px;
}

.round-label {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 14px;
}

.round-hint {
  font-size: 10px;
  color: var(--bazar-muted);
  margin-top: 2px;
}

/* Stage */
.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.countdown-big {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 4;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 108px;
  color: #fff;
  text-shadow: 0 0 24px rgba(173, 255, 0, 0.55), 0 6px 0 rgba(0, 0, 0, 0.35);
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.countdown-big.is-on {
  opacity: 1;
  transform: scale(1);
}

.ko-banner {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  z-index: 5;
  padding: 10px 22px;
  border-radius: var(--bazar-radius-pill);
  background: #000;
  color: var(--bazar-lime);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 0.08em;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.ko-banner[hidden] {
  display: none !important;
}

.status-toast {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  border-radius: var(--bazar-radius-pill);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.status-toast.is-on {
  opacity: 1;
}

/* Full-screen touch pads (under visual controls, over canvas) */
.touch-pads {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr 1fr;
  pointer-events: none;
}

.touch-pads[hidden] {
  display: none !important;
}

.touch-pad {
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch-pad.move {
  /* left 55% feels better for thumbs */
  margin-right: -10%;
}

.touch-pad.dash {
  margin-left: -10%;
}

/* Floating stick follows thumb on left pad */
.stick-zone.is-floating {
  position: fixed;
  z-index: 7;
  margin: 0;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.stick-zone.is-floating .stick-label {
  display: none;
}

/* Controls */
.controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 16px calc(16px + var(--safe-bottom));
  pointer-events: none;
}

.controls[hidden] {
  display: none !important;
}

.stick-zone {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.stick-base {
  width: 128px;
  height: 128px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.16);
  position: relative;
  touch-action: none;
}

.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: linear-gradient(160deg, #fff 0%, #cfc6e8 100%);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  will-change: transform;
}

.stick-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--bazar-muted);
  max-width: 120px;
  text-align: center;
  line-height: 1.2;
}

.btn-dash {
  pointer-events: auto;
  width: 100px;
  height: 100px;
  min-width: 100px;
  min-height: 100px;
  border-radius: 50%;
  border: 3px solid var(--bazar-lime);
  background: radial-gradient(circle at 35% 30%, #2a203f 0%, #120c22 70%);
  color: var(--bazar-lime);
  font-family: var(--font-display);
  box-shadow: 0 0 0 4px rgba(173, 255, 0, 0.12), 0 10px 24px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn-dash:active {
  transform: scale(0.96);
  background: radial-gradient(circle at 35% 30%, #3a2f55 0%, #1a1230 70%);
}

.btn-dash.is-cd {
  opacity: 0.55;
  border-color: var(--bazar-muted);
  color: var(--bazar-muted);
  box-shadow: none;
}

.dash-title {
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.04em;
}

.dash-sub {
  font-size: 10px;
  font-weight: 600;
  opacity: 0.8;
}

/* Larger thumbs on phones */
@media (max-width: 480px), (pointer: coarse) {
  .stick-base {
    width: 140px;
    height: 140px;
  }

  .stick-knob {
    width: 58px;
    height: 58px;
    margin: -29px 0 0 -29px;
  }

  .btn-dash {
    width: 110px;
    height: 110px;
    min-width: 110px;
    min-height: 110px;
  }

  .controls {
    padding-bottom: calc(18px + var(--safe-bottom));
  }
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 5, 16, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  overflow-y: auto;
}

.overlay[hidden] {
  display: none !important;
}

.overlay-card {
  width: 100%;
  max-width: 400px;
  margin: auto 0 8px;
  background: var(--bazar-card);
  border-radius: var(--bazar-radius-lg);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45), 0 0 0 1px var(--bazar-border);
  padding: 22px 20px 18px;
  text-align: center;
  color: var(--bazar-text);
}

.overlay-logo {
  width: 48px;
  height: 48px;
  margin: 0 auto 10px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bazar-lime);
}

.overlay-logo img {
  width: 100%;
  height: 100%;
  display: block;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--bazar-text-secondary);
}

.overlay-card h1 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 26px;
  line-height: 1.15;
}

.tagline {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--bazar-text-secondary);
}

.tagline strong {
  color: #fff;
}

.roles-preview {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
}

.role-card {
  padding: 12px 8px;
  border-radius: var(--bazar-radius-md);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--bazar-border);
}

.role-card.bull {
  border-color: rgba(173, 255, 0, 0.35);
}

.role-card.bear {
  border-color: rgba(255, 69, 69, 0.35);
}

.role-emoji {
  font-size: 28px;
  line-height: 1;
}

.role-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 14px;
  margin-top: 4px;
}

.role-desc {
  font-size: 10px;
  color: var(--bazar-muted);
  margin-top: 2px;
}

.role-vs {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 12px;
  color: var(--bazar-muted);
}

.field {
  text-align: left;
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--bazar-text-secondary);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  height: 48px;
  border: 1px solid var(--bazar-border-strong);
  border-radius: var(--bazar-radius-md);
  padding: 0 14px;
  font-size: 16px;
  font-family: var(--font-body);
  font-weight: 600;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  outline: none;
  touch-action: manipulation;
  user-select: text;
  -webkit-user-select: text;
}

.field input:focus {
  border-color: var(--bazar-lime);
  box-shadow: 0 0 0 3px var(--bazar-lime-soft);
}

.field input.code-input {
  text-align: center;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 20px;
}

.btn-row {
  display: grid;
  gap: 10px;
  margin-top: 4px;
}

.btn-primary,
.btn-secondary,
.btn-ghost {
  min-height: var(--control-min);
  border: none;
  border-radius: var(--bazar-radius-pill);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 15px;
  cursor: pointer;
  padding: 0 18px;
  touch-action: manipulation;
}

.btn-primary {
  background: var(--bazar-lime);
  color: #000;
}

.btn-primary:hover {
  background: var(--bazar-lime-hover);
}

.btn-primary.btn-random {
  background: linear-gradient(135deg, #adff00 0%, #e8ff6a 45%, #adff00 100%);
  box-shadow: 0 0 0 1px rgba(173, 255, 0, 0.25), 0 8px 24px rgba(173, 255, 0, 0.18);
  font-size: 16px;
}

.btn-primary.bear-btn {
  background: var(--bear);
  color: #fff;
}

.queue-spinner {
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--bazar-lime);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.queue-meta {
  margin: 0 0 16px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 15px;
  color: var(--bazar-lime);
}

.btn-secondary {
  background: #fff;
  color: #111;
}

.btn-ghost {
  background: transparent;
  color: var(--bazar-text-secondary);
  border: 1px solid var(--bazar-border-strong);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.05);
}

.split-or {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 10px;
  color: var(--bazar-muted);
  font-size: 12px;
  font-weight: 600;
}

.split-or::before,
.split-or::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--bazar-border);
}

.rules {
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
  text-align: left;
  font-size: 12px;
  line-height: 1.5;
  color: var(--bazar-text-secondary);
}

.rules li {
  position: relative;
  padding-left: 14px;
  margin-bottom: 4px;
}

.rules li::before {
  content: '·';
  position: absolute;
  left: 2px;
  font-weight: 800;
  color: var(--bazar-lime);
}

.room-code-big {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 40px;
  letter-spacing: 0.2em;
  margin: 8px 0 4px;
  color: var(--bazar-lime);
}

.room-hint {
  font-size: 13px;
  color: var(--bazar-text-secondary);
  margin: 0 0 16px;
}

.players-list {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.player-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--bazar-radius-md);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--bazar-border);
  text-align: left;
}

.player-chip.is-you {
  border-color: rgba(173, 255, 0, 0.4);
}

.player-chip.is-ready .p-ready {
  color: var(--bull);
}

.player-chip.is-empty {
  opacity: 0.55;
  border-style: dashed;
}

.p-name {
  font-weight: 700;
  font-size: 14px;
}

.p-meta {
  font-size: 11px;
  color: var(--bazar-muted);
  margin-top: 2px;
}

.p-ready {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--bazar-muted);
}

.result-badge {
  display: inline-block;
  padding: 6px 12px;
  border-radius: var(--bazar-radius-pill);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.result-badge.win {
  background: var(--bazar-lime);
  color: #000;
}

.result-badge.lose {
  background: #111;
  color: #fff;
  border: 1px solid var(--bazar-border-strong);
}

.result-badge.draw {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.final-score-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
  margin: 12px 0 16px;
}

.final-side .fs-role {
  font-size: 22px;
}

.final-side .fs-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--bazar-text-secondary);
  margin-top: 2px;
}

.final-side .fs-score {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 28px;
  margin-top: 2px;
}

.final-side.bull .fs-score {
  color: var(--bull);
}

.final-side.bear .fs-score {
  color: var(--bear);
}

.final-side.bear {
  text-align: right;
}

.final-vs {
  font-weight: 800;
  color: var(--bazar-muted);
  font-size: 18px;
}

@media (min-height: 720px) {
  .overlay-card {
    margin: auto;
  }
}
