:root {
  color-scheme: dark;
  --bg: #05040c;
  --panel: rgba(18, 14, 34, 0.78);
  --panel-strong: rgba(29, 23, 55, 0.92);
  --glass: rgba(255, 255, 255, 0.08);
  --line: rgba(255, 255, 255, 0.16);
  --line-hot: rgba(255, 212, 116, 0.45);
  --text: #fff9ff;
  --muted: #b9b2d6;
  --cyan: #43f4ff;
  --pink: #ff4fdc;
  --violet: #8c62ff;
  --gold: #ffd66b;
  --green: #63ffbd;
  --red: #ff426d;
  font-family: Inter, "Segoe UI", "Noto Sans Thai", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    radial-gradient(circle at 15% 6%, rgba(255, 79, 220, 0.34), transparent 28%),
    radial-gradient(circle at 82% 14%, rgba(67, 244, 255, 0.25), transparent 30%),
    radial-gradient(circle at 48% 100%, rgba(255, 214, 107, 0.18), transparent 34%),
    linear-gradient(145deg, #05040c 0%, #171332 48%, #070511 100%);
  color: var(--text);
  overflow-x: hidden;
}

body::before,
body::after,
.ambient-ribbons {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.88), transparent 70%);
}

body::after {
  background: linear-gradient(120deg, transparent 12%, rgba(255, 255, 255, 0.11) 13%, transparent 15%, transparent 62%, rgba(67, 244, 255, 0.1) 64%, transparent 66%);
  opacity: 0.34;
  animation: sweep 9s linear infinite;
}

.ambient-ribbons {
  background:
    conic-gradient(from 140deg at 15% 70%, transparent, rgba(255, 79, 220, 0.16), transparent 22%),
    conic-gradient(from 20deg at 90% 40%, transparent, rgba(67, 244, 255, 0.14), transparent 18%);
  filter: blur(18px);
}

@keyframes sweep {
  from { transform: translateX(-8%); }
  to { transform: translateX(8%); }
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

.app-shell {
  width: min(1220px, calc(100vw - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 344px;
  gap: 18px;
  align-items: start;
}

.game-panel,
.rank-panel {
  border: 1px solid var(--line);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.11), rgba(255, 255, 255, 0.045)), var(--panel);
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(24px);
}

.game-panel {
  border-radius: 8px;
  padding: 18px;
}

.hero-bar,
.brand-lockup,
.section-head,
.name-row,
.control-strip,
.profile-panel {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hero-bar,
.section-head,
.control-strip {
  justify-content: space-between;
}

.brand-lockup {
  min-width: 0;
}

.app-mark,
.avatar-ring {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 214, 107, 0.95), rgba(255, 79, 220, 0.88) 48%, rgba(67, 244, 255, 0.92)),
    #19112e;
  color: #160a21;
  font-weight: 1000;
  box-shadow: 0 0 32px rgba(255, 79, 220, 0.28), 0 0 44px rgba(67, 244, 255, 0.18);
}

.app-mark {
  width: 58px;
  height: 58px;
  font-size: 20px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--cyan);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(32px, 4.5vw, 66px);
  line-height: 0.92;
  letter-spacing: 0;
  text-shadow: 0 0 28px rgba(255, 79, 220, 0.34);
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
  line-height: 1.18;
  letter-spacing: 0;
}

.season-chip {
  display: grid;
  gap: 2px;
  margin-left: auto;
  min-width: 124px;
  border: 1px solid var(--line-hot);
  border-radius: 8px;
  padding: 10px 12px;
  background: linear-gradient(135deg, rgba(255, 214, 107, 0.19), rgba(255, 255, 255, 0.06));
}

.season-chip span,
.hud-card span,
.tool-btn span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.season-chip strong {
  color: var(--gold);
  font-size: 15px;
}

.icon-btn,
.ghost-btn,
.tool-btn,
.hook-grid button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass);
  min-height: 42px;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.icon-btn:hover,
.ghost-btn:hover,
.tool-btn:hover,
.hook-grid button:hover {
  transform: translateY(-1px);
  border-color: rgba(67, 244, 255, 0.48);
  background: rgba(255, 255, 255, 0.13);
}

.icon-btn {
  width: 46px;
  font-weight: 1000;
}

.hud-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr 1fr 1fr;
  gap: 10px;
  margin: 16px 0;
}

.hud-card {
  position: relative;
  min-height: 82px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.045)),
    rgba(15, 11, 31, 0.86);
}

.hud-card::after {
  content: "";
  position: absolute;
  inset: auto -20% -45% 18%;
  height: 78px;
  background: radial-gradient(circle, rgba(67, 244, 255, 0.28), transparent 62%);
}

.hud-card strong {
  display: block;
  margin-top: 6px;
  font-size: 28px;
  line-height: 1;
  text-shadow: 0 0 18px rgba(67, 244, 255, 0.28);
}

.hud-card small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
}

.score-card strong {
  font-size: 34px;
}

.hud-card.accent strong {
  color: var(--gold);
}

.stage-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 760 / 980;
  overflow: hidden;
  border: 1px solid rgba(67, 244, 255, 0.34);
  border-radius: 8px;
  background: #05040c;
  box-shadow: inset 0 0 70px rgba(67, 244, 255, 0.1), 0 0 36px rgba(255, 79, 220, 0.16);
}

.stage-header {
  position: absolute;
  z-index: 2;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  padding: 0 10px;
  background: rgba(6, 6, 18, 0.42);
  color: rgba(255, 255, 255, 0.82);
  font-size: 12px;
  font-weight: 800;
  backdrop-filter: blur(12px);
}

.live-pill {
  padding: 4px 8px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--red), var(--pink));
  color: white;
  box-shadow: 0 0 18px rgba(255, 66, 109, 0.38);
}

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

.overlay {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(180deg, rgba(5, 4, 12, 0.08), rgba(5, 4, 12, 0.82));
}

.overlay.hidden {
  display: none;
}

.overlay-content {
  width: min(560px, 100%);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.055)),
    rgba(10, 8, 25, 0.8);
  box-shadow: 0 0 54px rgba(67, 244, 255, 0.2), 0 0 86px rgba(255, 79, 220, 0.13);
}

.overlay-content h2 {
  margin-bottom: 18px;
  font-size: clamp(24px, 4.6vw, 43px);
  text-shadow: 0 0 24px rgba(255, 214, 107, 0.2);
}

.name-row {
  justify-content: space-between;
}

.name-row input {
  min-width: 0;
  flex: 1;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  outline: none;
}

.primary-btn {
  height: 48px;
  border-radius: 8px;
  padding: 0 20px;
  background: linear-gradient(135deg, var(--gold), var(--pink) 52%, var(--cyan));
  color: #11081a;
  font-weight: 1000;
  white-space: nowrap;
  box-shadow: 0 12px 34px rgba(255, 79, 220, 0.28);
}

.mini-missions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.mini-missions span {
  border: 1px solid rgba(255, 214, 107, 0.28);
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(255, 214, 107, 0.1);
  color: var(--gold);
  font-size: 12px;
  font-weight: 900;
}

.control-strip {
  margin-top: 12px;
}

.tool-btn {
  flex: 1;
  min-height: 58px;
  padding: 8px 12px;
  text-align: left;
  color: var(--text);
  font-weight: 900;
}

.tool-btn strong {
  display: block;
  margin-top: 2px;
}

.tool-btn.active {
  border-color: rgba(255, 214, 107, 0.9);
  background: linear-gradient(135deg, rgba(255, 214, 107, 0.21), rgba(255, 79, 220, 0.12));
  color: var(--gold);
}

.side-panel {
  display: grid;
  gap: 14px;
}

.rank-panel {
  border-radius: 8px;
  padding: 16px;
}

.rank-panel.compact {
  padding: 14px;
}

.leaderboard-panel {
  background:
    linear-gradient(160deg, rgba(255, 214, 107, 0.12), rgba(255, 255, 255, 0.04)),
    var(--panel-strong);
}

.ghost-btn {
  padding: 0 12px;
  color: var(--muted);
}

.leaderboard {
  list-style: none;
  padding: 0;
  margin: 14px 0 0;
  display: grid;
  gap: 9px;
}

.leaderboard li {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.07);
}

.leaderboard li:first-child {
  border-color: rgba(255, 214, 107, 0.58);
  background: linear-gradient(135deg, rgba(255, 214, 107, 0.18), rgba(255, 79, 220, 0.08));
}

.leaderboard .rank {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: rgba(255, 214, 107, 0.14);
  color: var(--gold);
  font-weight: 1000;
}

.leaderboard .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 900;
}

.leaderboard .score {
  color: var(--cyan);
  font-weight: 1000;
}

.avatar-ring {
  width: 66px;
  height: 66px;
  font-size: 18px;
}

.muted-copy {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: 13px;
}

.hook-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.hook-grid button {
  padding: 0 10px;
  color: var(--text);
  font-weight: 900;
}

.rules {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.65;
  font-size: 14px;
}

.result-line {
  color: var(--muted);
  line-height: 1.5;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-panel {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100vw - 16px, 520px);
    padding: 8px 0;
  }

  .game-panel {
    padding: 10px;
  }

  .hero-bar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .season-chip {
    order: 3;
    width: 100%;
  }

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

  .side-panel {
    grid-template-columns: 1fr;
  }

  .name-row,
  .control-strip {
    flex-direction: column;
  }

  .name-row input,
  .primary-btn,
  .tool-btn {
    width: 100%;
  }

  .stage-header {
    font-size: 11px;
  }
}
