:root {
  --bg-0: #07080f;
  --bg-1: #0b0d18;
  --bg-2: #141728;
  --bg-3: #1c2036;
  --ink-1: #ff5a8a; /* magenta — player 1 */
  --ink-2: #54d6ff; /* cyan — player 2 */
  --neutral: #c6c8d4;
  --accent: #f7d046;
  --good: #6cf09a;
  --bad: #ff6470;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --glow-1: 0 0 18px rgba(255, 90, 138, 0.55);
  --glow-2: 0 0 18px rgba(84, 214, 255, 0.55);
  --font-display:
    "Space Grotesk", "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Menlo, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(1200px 900px at 30% 20%, #11142a 0%, var(--bg-0) 60%);
  color: var(--neutral);
  font-family: var(--font-display);
  letter-spacing: 0.01em;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: grid;
  place-items: center;
}

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: -webkit-optimize-contrast;
  /* Canvas paints inside this; UI overlays above */
}

#ui-root {
  position: absolute;
  inset: 0;
  pointer-events: none; /* children opt in to pointer-events: auto */
  z-index: 5;
}

#ui-root > * {
  pointer-events: auto;
}

/* Persistent fullscreen toggle, floats bottom-right above the canvas. */
.fullscreen-btn {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-size: 18px;
  color: var(--neutral);
  background: rgba(20, 24, 40, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: var(--shadow);
  transition:
    transform 0.15s ease,
    background 0.15s ease,
    border-color 0.15s ease;
}
.fullscreen-btn:hover {
  transform: translateY(-2px);
  background: rgba(28, 32, 54, 0.9);
  border-color: rgba(255, 255, 255, 0.35);
}
.fullscreen-btn.active {
  color: #0b0d18;
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 16px rgba(247, 208, 70, 0.5);
}

/* Shared button styling used across screens */
button.btn {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 14px;
  padding: 12px 22px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
  color: var(--neutral);
  cursor: pointer;
  transition:
    transform 120ms ease,
    background 200ms ease,
    border-color 200ms ease,
    box-shadow 200ms ease;
  backdrop-filter: blur(8px);
}
button.btn:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.25);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.04));
}
button.btn:active {
  transform: translateY(0);
}
/* Keyboard focus ring — clear outline without hammering mouse users. */
button:focus-visible,
.toggle:focus-visible,
.swatch:focus-visible,
.seg-btn:focus-visible,
.tut-btn:focus-visible,
input[type="range"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button.btn.primary {
  background: linear-gradient(180deg, var(--ink-1), #d43b6f);
  border-color: transparent;
  color: #1a0712;
  box-shadow: var(--glow-1);
}
button.btn.primary:hover {
  box-shadow: 0 0 28px rgba(255, 90, 138, 0.75);
}
button.btn.secondary {
  background: linear-gradient(180deg, var(--ink-2), #2fa6cf);
  border-color: transparent;
  color: #06212c;
  box-shadow: var(--glow-2);
}
button.btn.subtle {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--neutral);
}

.fade-in {
  animation: fadeIn 220ms ease-out both;
}
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- Screen layer ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
}
.screen-menu {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  pointer-events: auto;
}
.title {
  font-family: var(--font-display);
  font-size: 64px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1;
  display: flex;
  gap: 12px;
  align-items: baseline;
  text-shadow: 0 0 40px rgba(255, 255, 255, 0.06);
}
.title-ink {
  background: linear-gradient(180deg, var(--ink-1) 0%, #ff2d6b 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.title-region {
  background: linear-gradient(180deg, var(--ink-2) 0%, #2fa6cf 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle {
  color: rgba(255, 255, 255, 0.55);
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 12px;
}
.stats-card {
  display: flex;
  gap: 28px;
  padding: 14px 22px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(28, 32, 54, 0.7), rgba(11, 13, 24, 0.7));
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
}
.stats-card .stat .num {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}
.stats-card .stat .lbl {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.5);
  margin-top: 2px;
}

.seg-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.seg-label {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
  min-width: 64px;
  text-align: right;
}
.segmented {
  display: inline-flex;
  border-radius: 12px;
  background: rgba(7, 8, 15, 0.55);
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  gap: 2px;
}
.seg-btn {
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, transform 80ms ease;
}
.seg-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
}
.seg-btn:active {
  transform: scale(0.96);
}
.seg-btn.active {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.06));
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.color-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.player-line {
  display: flex;
  align-items: center;
  gap: 12px;
}
.player-tag {
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.6);
  min-width: 28px;
  text-align: right;
}
.swatches {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  background: rgba(7, 8, 15, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
}
.swatch {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 100ms ease, border-color 120ms ease, box-shadow 120ms ease;
  background-clip: padding-box;
}
.swatch:hover {
  transform: scale(1.1);
}
.swatch.active {
  border-color: #fff;
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.4);
}

.play-btn {
  margin-top: 8px;
  font-size: 16px;
  padding: 14px 36px;
}

.hint {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
}

.menu-actions {
  display: flex;
  gap: 12px;
  margin-top: 6px;
}
.menu-actions button.btn {
  font-size: 12px;
  padding: 10px 18px;
}

/* ---------- How to Play ---------- */
.screen-howto {
  background: rgba(7, 8, 15, 0.55);
  backdrop-filter: blur(8px);
  pointer-events: auto;
}
.screen-howto .card {
  max-width: 460px;
  min-width: 340px;
  align-items: stretch;
  text-align: left;
}
.howto-body {
  font-size: 13px;
  line-height: 1.55;
  color: var(--neutral);
}
.howto-body p {
  margin: 4px 0 10px;
}
.howto-section {
  margin: 12px 0;
}
.howto-section h3 {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 6px;
}
.howto-section ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.howto-section li {
  margin: 5px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.howto-body kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.16);
}
.pu-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  box-shadow: 0 0 8px currentColor;
}
.howto-tip {
  border-left: 2px solid var(--accent);
  padding-left: 10px;
  color: rgba(255, 255, 255, 0.75);
}

/* ---------- First-run Tutorial ---------- */
.screen-tutorial {
  background:
    radial-gradient(900px 600px at 20% 10%, rgba(255, 90, 138, 0.12), transparent 60%),
    radial-gradient(900px 600px at 80% 90%, rgba(84, 214, 255, 0.12), transparent 60%),
    rgba(7, 8, 15, 0.82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  pointer-events: auto;
}
.tut-card {
  width: min(460px, 92vw);
  background: linear-gradient(180deg, rgba(28, 32, 54, 0.96), rgba(11, 13, 24, 0.97));
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 24px;
  padding: 26px 30px 22px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: tutPop 240ms cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes tutPop {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
.tut-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tut-kicker {
  font-size: 11px;
  letter-spacing: 0.16em;
  font-weight: 700;
  color: var(--accent);
}
.tut-skip {
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.5);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  transition: color 140ms ease, background 140ms ease;
}
.tut-skip:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}
.tut-art {
  height: 132px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.06);
  overflow: hidden;
}
.tut-art svg {
  width: 160px;
  height: 120px;
}
.tut-title {
  font-size: 24px;
  font-weight: 800;
  margin: 0;
  letter-spacing: 0.01em;
}
.tut-body {
  font-size: 14px;
  line-height: 1.6;
  color: var(--neutral);
  margin: 0;
  min-height: 66px;
}
.tut-footer {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 4px;
}
.tut-btn {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 13px;
  padding: 11px 20px;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.14);
  transition: transform 120ms ease, background 180ms ease, border-color 180ms ease;
}
.tut-btn.back {
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.7);
}
.tut-btn.back:hover {
  background: rgba(255, 255, 255, 0.1);
}
.tut-btn.next {
  background: linear-gradient(180deg, var(--ink-1), #d43b6f);
  border-color: transparent;
  color: #fff;
  margin-left: auto;
}
.tut-btn.next:hover {
  transform: translateY(-1px);
  box-shadow: var(--glow-1);
}
.tut-progress {
  flex: 1;
  display: flex;
  gap: 6px;
  align-items: center;
}
.tut-seg {
  flex: 1;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.14);
  transition: background 180ms ease, transform 180ms ease;
}
.tut-seg.on {
  background: linear-gradient(90deg, var(--ink-1), #ff8a7a);
}
.tut-seg.cur {
  box-shadow: 0 0 10px rgba(255, 90, 138, 0.6);
}

/* ---------- Pause / Settings ---------- */
.screen-pause,
.screen-settings {
  background: rgba(7, 8, 15, 0.55);
  backdrop-filter: blur(8px);
  pointer-events: auto;
}
.card {
  background: linear-gradient(180deg, rgba(28, 32, 54, 0.95), rgba(11, 13, 24, 0.95));
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 22px;
  padding: 30px 40px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-width: 320px;
}
.modal-title {
  font-size: 32px;
  font-weight: 800;
  margin: 0;
}
.modal-sub {
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
  text-align: center;
}
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.modal-back {
  margin-top: 8px;
}
.settings-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  justify-content: space-between;
}
.settings-label {
  color: rgba(255, 255, 255, 0.75);
  font-size: 13px;
  font-weight: 500;
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 200px;
  height: 4px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 4px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  cursor: pointer;
}
.toggle {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 6px 14px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 160ms ease;
}
.toggle.on {
  background: linear-gradient(180deg, var(--accent), #c89816);
  color: #1a0712;
  border-color: transparent;
  box-shadow: 0 0 14px rgba(247, 208, 70, 0.55);
}

/* ---------- Match end overlay (DOM chips over the canvas card) ---------- */
.match-end-overlay {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 36px;
  pointer-events: none;
}
.match-end-overlay .row {
  display: flex;
  gap: 10px;
  pointer-events: auto;
}
