:root {
  --bg: #09111a;
  --bg-soft: #101d2b;
  --panel: rgba(7, 15, 24, 0.78);
  --panel-strong: rgba(8, 18, 31, 0.92);
  --line: rgba(140, 188, 255, 0.18);
  --text: #f7f3e8;
  --muted: #a6b6c8;
  --accent: #ffb347;
  --accent-strong: #ff8647;
  --cyan: #76e3ff;
  --danger: #ff6b6b;
  --success: #78f2b3;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  --radius: 24px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--text);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top, rgba(118, 227, 255, 0.16), transparent 34%),
    radial-gradient(circle at 20% 20%, rgba(255, 179, 71, 0.2), transparent 26%),
    linear-gradient(135deg, #081018 0%, #111f31 48%, #0a121d 100%);
  background-attachment: fixed;
  padding-bottom: 44px;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      120deg,
      rgba(255, 255, 255, 0.02) 0,
      rgba(255, 255, 255, 0.02) 2px,
      transparent 2px,
      transparent 24px
    );
  opacity: 0.35;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 20px auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding: 18px 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(8, 19, 31, 0.88), rgba(16, 28, 45, 0.92));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.brand-mark,
.brand-subtitle,
.eyebrow,
.card-label {
  font-family: "Avenir Next Condensed", "Bebas Neue", "Franklin Gothic Medium", sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.brand-mark {
  font-size: clamp(2rem, 3vw, 3.4rem);
  line-height: 0.9;
}

.brand-subtitle {
  font-size: 0.95rem;
  color: var(--cyan);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ghost-button,
.difficulty-button {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.ghost-button:hover,
.difficulty-button:hover,
.primary-button:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.3);
}

.ghost-button {
  padding: 12px 16px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(280px, 0.9fr);
  gap: 18px;
}

.stage-panel,
.sidebar {
  min-width: 0;
}

.stage-frame {
  position: relative;
  min-height: 720px;
  border-radius: 30px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(4, 11, 18, 0.84), rgba(7, 16, 28, 0.96));
  box-shadow: var(--shadow);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 720px;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, rgba(2, 6, 10, 0.38), rgba(2, 6, 10, 0.72));
  backdrop-filter: blur(10px);
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(680px, 100%);
  padding: 30px;
  border-radius: 28px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background:
    linear-gradient(135deg, rgba(17, 28, 43, 0.92), rgba(9, 18, 30, 0.96)),
    rgba(0, 0, 0, 0.4);
  box-shadow: var(--shadow);
}

.hero-card h1,
.compact-card h2 {
  margin: 0;
  font-family: "Avenir Next Condensed", "Bebas Neue", "Franklin Gothic Medium", sans-serif;
  font-size: clamp(2.4rem, 5vw, 4.6rem);
  line-height: 0.95;
  letter-spacing: 0.04em;
}

.lead {
  max-width: 58ch;
  color: var(--muted);
  font-size: 1.05rem;
}

.eyebrow,
.card-label {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 0.92rem;
}

.difficulty-box,
.card {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.difficulty-box {
  margin-top: 28px;
  padding: 18px;
}

.difficulty-label {
  margin: 0 0 12px;
  color: var(--muted);
}

.difficulty-controls {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 14px;
}

.difficulty-button {
  width: 48px;
  height: 48px;
  font-size: 1.6rem;
}

.difficulty-readout {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: "Avenir Next Condensed", "Bebas Neue", sans-serif;
}

.difficulty-readout span {
  font-size: 3rem;
}

#difficulty-range {
  width: 100%;
  accent-color: var(--accent);
}

.hero-actions {
  display: flex;
  justify-content: flex-start;
  margin-top: 22px;
}

.primary-button {
  padding: 14px 24px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #1b1208;
  font-family: "Avenir Next Condensed", "Bebas Neue", sans-serif;
  font-size: 1.2rem;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: transform 160ms ease, filter 160ms ease;
}

.primary-button:hover {
  filter: brightness(1.04);
}

.compact-card {
  width: min(420px, 100%);
  text-align: center;
}

.results-grid,
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.results-grid {
  margin: 20px 0;
}

.results-grid div,
.stats-grid div {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.05);
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.results-grid strong,
.stats-grid strong {
  font-size: 1.8rem;
}

.new-best {
  margin-top: 0;
  color: var(--success);
  font-family: "Avenir Next Condensed", "Bebas Neue", sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hidden {
  display: none !important;
}

.controls-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
}

.controls-strip span {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar {
  display: grid;
  gap: 18px;
  align-content: start;
}

.card {
  padding: 18px;
}

.stat-card {
  background: linear-gradient(180deg, rgba(12, 24, 38, 0.96), rgba(8, 18, 29, 0.95));
}

.rule-list,
.event-feed {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.rule-list li + li {
  margin-top: 8px;
}

.event-feed {
  min-height: 170px;
}

.event-feed li {
  margin-bottom: 10px;
}

.event-feed li[data-tone="good"] {
  color: var(--success);
}

.event-feed li[data-tone="warning"] {
  color: var(--accent);
}

.event-feed li[data-tone="danger"] {
  color: var(--danger);
}

.status-copy {
  margin: 0;
  line-height: 1.55;
  color: var(--text);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100vw, calc(100vw - 20px));
    margin: 10px auto 24px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .stage-frame,
  #game-canvas {
    min-height: 620px;
    height: 620px;
  }

  .overlay-card {
    padding: 22px;
  }

  .sidebar {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 540px) {
  .brand-mark {
    font-size: 2.4rem;
  }

  .stage-frame,
  #game-canvas {
    min-height: 700px;
    height: 700px;
  }

  .results-grid,
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .controls-strip {
    display: none;
  }

  .controls-strip span {
    width: calc(50% - 5px);
    text-align: center;
  }
}
