:root {
  color-scheme: dark;
  --bg: #080d12;
  --panel: #101820;
  --panel-2: #16212c;
  --line: #263746;
  --text: #f4f7f9;
  --muted: #9eabb7;
  --accent: #31d17c;
  --accent-2: #20ad64;
  --danger: #ff5b5b;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 10% 0%, rgba(49, 209, 124, 0.09), transparent 30rem),
    linear-gradient(180deg, #0a1118, var(--bg));
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body { padding: 24px; }

button { font: inherit; }

.shell {
  width: min(1120px, 100%);
  margin: 0 auto;
}

.topbar, .leaderboard-card, .game-card {
  border: 1px solid var(--line);
  background: rgba(16, 24, 32, 0.92);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-radius: 18px;
  margin-bottom: 14px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--accent);
  color: #07110c;
  transform: skew(-8deg);
  font-weight: 900;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 2px;
  font-size: clamp(1.2rem, 3vw, 1.6rem);
  letter-spacing: -0.04em;
}

.brand p, .leaderboard-card p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.game-card {
  overflow: hidden;
  border-radius: 22px;
}

.hud {
  display: grid;
  grid-template-columns: repeat(5, minmax(74px, auto)) 1fr;
  gap: 16px;
  align-items: center;
  padding: 13px 16px;
  background: #0e171f;
  border-bottom: 1px solid var(--line);
}

.hud > div { min-width: 0; }

.hud-label {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 800;
}

.hud strong { font-variant-numeric: tabular-nums; }

.progress-wrap { width: 100%; }

.progress-track {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #26333e;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 100ms linear;
}

.canvas-wrap {
  position: relative;
  aspect-ratio: 16 / 10;
  background: #1b2832;
}

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

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(5, 10, 14, 0.46);
  backdrop-filter: blur(3px);
}

.overlay.hidden { display: none; }

.panel {
  width: min(470px, 94%);
  padding: 28px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  background: rgba(10, 17, 23, 0.94);
  box-shadow: var(--shadow);
  text-align: center;
}

.panel h2 {
  margin-bottom: 10px;
  font-size: clamp(1.65rem, 5vw, 2.5rem);
  letter-spacing: -0.05em;
}

.panel p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.55;
}

.eyebrow {
  margin-bottom: 7px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.13em;
}

.button {
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  font-weight: 850;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, background 120ms ease;
}

.button:hover { filter: brightness(1.07); }
.button:active { transform: translateY(1px) scale(0.99); }

.button-primary {
  background: var(--accent);
  color: #06110b;
}

.button-ghost {
  border: 1px solid var(--line);
  background: #111c25;
  color: var(--text);
}

.full { width: 100%; }

.touch-controls {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  background: #0d151c;
  border-top: 1px solid var(--line);
}

.touch-group {
  display: flex;
  gap: 10px;
}

.touch-button {
  min-width: 64px;
  min-height: 48px;
  padding: 0 17px;
  border: 1px solid #304353;
  border-radius: 12px;
  background: #17232d;
  color: var(--text);
  font-weight: 900;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.touch-button.small { min-width: 82px; font-size: 0.72rem; }
.touch-button.accent { background: #173826; border-color: #286943; color: #dfffee; }
.touch-button.active { transform: translateY(1px); filter: brightness(1.35); }

.leaderboard-card {
  display: grid;
  grid-template-columns: 0.8fr 1.2fr;
  gap: 24px;
  align-items: start;
  margin-top: 14px;
  padding: 20px;
  border-radius: 18px;
}

.leaderboard-card h2 { margin-bottom: 6px; }

#mis-leaderboard {
  min-height: 92px;
  padding: 14px;
  border: 1px dashed #314657;
  border-radius: 12px;
  background: #0c141b;
}

.leaderboard-fallback {
  color: var(--muted);
  margin: 0;
}

dialog {
  width: min(560px, calc(100% - 28px));
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0;
  background: #111a22;
  box-shadow: var(--shadow);
}

dialog::backdrop { background: rgba(0, 0, 0, 0.68); }

dialog form { padding: 22px; }

.dialog-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.dialog-head h2 { margin-bottom: 0; }

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #192631;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
}

.instructions {
  margin: 18px 0 22px;
  color: #c9d2da;
  line-height: 1.55;
}

.instructions p { margin-bottom: 12px; }

@media (max-width: 720px) {
  body { padding: 10px; }
  .topbar { padding: 12px; border-radius: 14px; }
  .brand p { display: none; }
  .game-card { border-radius: 16px; }

  .hud {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 10px;
  }

  .progress-wrap {
    grid-column: 1 / -1;
  }

  .hud > div:nth-child(5) {
    grid-column: span 2;
  }

  .canvas-wrap { aspect-ratio: 4 / 5; }

  .leaderboard-card {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .touch-button { min-width: 56px; padding: 0 12px; }
  .touch-button.small { min-width: 72px; }
}

@media (min-width: 900px) and (pointer: fine) {
  .touch-controls { opacity: 0.78; }
}
