:root {
  color-scheme: dark;
  --bg: #0b0f19;
  --panel: #121826;
  --panel-strong: #172033;
  --ink: #f8fafc;
  --muted: #94a3b8;
  --line: rgba(255, 255, 255, 0.1);
  --gold: #f59e0b;
  --accent: #38bdf8;
  --danger: #ef4444;
  --event: #22c55e;
  --event-soft: rgba(34, 197, 94, 0.12);
  --cell: min(3.6vw, 4.4vh, 38px);
  --piece-cell: min(1.8vw, 2.35vh, 20px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: auto;
  min-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
a {
  font: inherit;
}

.play-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto;
  overflow: visible;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  padding: 8px clamp(14px, 2vw, 26px);
  border-bottom: 1px solid var(--line);
  background: rgba(11, 15, 25, 0.92);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.brand img {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.store-link,
.ghost-link,
.sound-toggle,
.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  font-weight: 800;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.store-link,
.primary-button {
  background: linear-gradient(135deg, #22c55e, #38bdf8);
  color: #03111d;
  padding: 10px 15px;
}

.ghost-link,
.sound-toggle,
.secondary-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  padding: 9px 13px;
}

.store-link:hover,
.ghost-link:hover,
.sound-toggle:hover,
.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

.sound-toggle[aria-pressed="true"] {
  border-color: rgba(34, 197, 94, 0.45);
  background: rgba(34, 197, 94, 0.15);
  color: #bbf7d0;
}

.game-layout {
  width: min(1240px, 100%);
  min-height: calc(100vh - 58px);
  margin: 0 auto;
  padding: clamp(10px, 1.5vw, 18px);
  display: grid;
  grid-template-columns: 204px minmax(430px, 1fr) minmax(250px, 286px);
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(10px, 1.4vw, 16px);
  align-items: stretch;
  overflow: visible;
}

.campaign-strip {
  grid-column: 3;
  grid-row: 1;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  flex-direction: column;
  gap: 10px;
  border: 1px solid color-mix(in srgb, var(--event) 34%, transparent);
  border-left: 4px solid var(--event);
  border-radius: 14px;
  background: linear-gradient(135deg, var(--event-soft), rgba(255, 255, 255, 0.035));
  padding: 12px;
  box-shadow: 0 16px 46px rgba(0, 0, 0, 0.2);
}

.campaign-strip h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.05;
}

.campaign-strip p:last-child {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.challenge-reward {
  display: inline-flex;
  margin-top: 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: #bbf7d0;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 900;
}

.game-panel,
.ad-rail,
.side-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 18px 58px rgba(0, 0, 0, 0.24);
}

.ad-rail {
  grid-column: 1;
  grid-row: 1 / 3;
  display: grid;
  grid-template-rows: auto repeat(5, 150px);
  justify-items: center;
  align-content: start;
  gap: 12px;
  min-height: 0;
  border-radius: 12px;
  padding: 12px;
}

.ad-rail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ad-rail-header .eyebrow {
  margin: 0;
}

.ad-rail-header span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.ad-slot {
  display: grid;
  align-content: center;
  justify-items: center;
  width: 180px;
  height: 150px;
  min-height: 150px;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: 7px;
  background:
    linear-gradient(135deg, rgba(56, 189, 248, 0.1), rgba(245, 158, 11, 0.08)),
    rgba(255, 255, 255, 0.035);
  text-align: center;
}

.ad-slot span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.ad-slot strong {
  margin-top: 3px;
  color: var(--ink);
  font-size: 15px;
}

.game-panel {
  grid-column: 2;
  grid-row: 1 / 3;
  display: grid;
  grid-template-rows: auto minmax(0, auto) auto;
  align-content: start;
  justify-items: center;
  min-height: 0;
  padding: clamp(10px, 1.4vw, 16px);
  border-radius: 16px;
}

.hud {
  width: min(100%, 488px);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.stat {
  min-height: 54px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-strong);
  padding: 8px 10px;
}

.label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.value {
  margin-top: 4px;
  font-size: clamp(20px, 3vw, 30px);
  line-height: 1;
  font-weight: 950;
}

.board-wrap {
  display: flex;
  justify-content: center;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(10, var(--cell));
  grid-template-rows: repeat(10, var(--cell));
  gap: 3px;
  padding: 9px;
  border-radius: 16px;
  background: #202736;
  border: 1px solid rgba(255, 255, 255, 0.16);
  touch-action: none;
  user-select: none;
}

.board-cell {
  width: var(--cell);
  height: var(--cell);
  padding: 0;
  border-radius: 7px;
  background: #111827;
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.board-cell.filled {
  background: var(--block-color);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.22), inset 0 4px 0 rgba(255, 255, 255, 0.2);
}

.board-cell.preview {
  outline: 2px solid rgba(56, 189, 248, 0.95);
  background: color-mix(in srgb, var(--block-color) 62%, #111827);
}

.board-cell.invalid {
  outline: 2px solid rgba(239, 68, 68, 0.88);
  background: rgba(239, 68, 68, 0.2);
}

.board-cell.clearing {
  animation: clearPulse 260ms ease;
}

@keyframes clearPulse {
  50% {
    transform: scale(0.86);
    filter: brightness(1.6);
  }
}

.pieces {
  width: min(100%, 488px);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.piece-slot {
  min-height: clamp(72px, 12vh, 96px);
  display: grid;
  place-items: center;
  border: 1px dashed rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.035);
}

.piece {
  display: grid;
  gap: 3px;
  padding: 6px;
  border-radius: 12px;
  cursor: grab;
  touch-action: none;
}

.piece.selected {
  outline: 2px solid var(--accent);
  background: rgba(56, 189, 248, 0.1);
}

.piece:active {
  cursor: grabbing;
}

.mini-cell {
  width: var(--piece-cell);
  height: var(--piece-cell);
  border-radius: 5px;
}

.mini-cell.on {
  background: var(--block-color);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.2), inset 0 3px 0 rgba(255, 255, 255, 0.2);
}

.drag-piece {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 100;
  pointer-events: none;
  opacity: 0.9;
  transform: translate(-50%, -50%) scale(1.05);
}

.side-panel {
  grid-column: 3;
  grid-row: 2;
  min-height: 0;
  overflow: visible;
  border-radius: 12px;
  padding: 14px;
}

.side-panel h1 {
  margin: 0 0 8px;
  font-size: clamp(24px, 3vw, 32px);
  line-height: 1;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 950;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.side-panel p {
  color: var(--muted);
  line-height: 1.42;
  font-size: 13px;
}

.actions {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.feedback {
  min-height: 20px;
  margin: 10px 0 0;
  color: #7dd3fc;
  font-size: 13px;
  font-weight: 800;
}

.feedback.dark {
  color: #0f766e;
}

.section-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.section-title h2 {
  margin: 0;
  font-size: 22px;
}

.section-title span {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 900;
}

.ranking-card,
.install-card,
.telemetry-card {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.045);
  padding: 12px;
}

.ranking-list {
  display: grid;
  gap: 6px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.ranking-list li {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.72);
  padding: 7px 8px;
}

.ranking-list li.ranking-empty {
  display: block;
  grid-template-columns: none;
}

.ranking-list .rank {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
  font-weight: 950;
}

.ranking-list .name {
  overflow: hidden;
  color: var(--ink);
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking-list .score {
  color: #7dd3fc;
  font-weight: 950;
}

.ranking-empty {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.ranking-status {
  margin: 10px 0 0;
  color: #7dd3fc;
  font-size: 12px;
  font-weight: 850;
}

.ranking-link {
  display: inline-flex;
  margin-top: 10px;
  color: #7dd3fc;
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
}

.ranking-link:hover {
  color: #bae6fd;
}

.install-card {
  display: grid;
  grid-template-columns: 1fr 84px;
  gap: 10px;
  align-items: center;
}

.install-card strong {
  display: block;
  color: var(--ink);
  font-size: 15px;
}

.install-card p {
  margin-bottom: 0;
}

.qr-code {
  width: 84px;
  height: 84px;
  border-radius: 12px;
  background: #fff;
  padding: 8px;
}

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

.telemetry-grid div {
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.65);
  padding: 8px;
  text-align: center;
}

.telemetry-grid strong {
  display: block;
  color: var(--ink);
  font-size: 18px;
  line-height: 1;
}

.telemetry-grid span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.mobile-callout {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.mobile-callout strong {
  color: #fbbf24;
}

.ranking-shell {
  min-height: 100vh;
}

.ranking-page {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: clamp(18px, 3vw, 34px);
}

.ranking-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
  gap: clamp(16px, 3vw, 28px);
  align-items: stretch;
}

.ranking-hero > div,
.weekly-feature,
.public-ranking-card,
.ranking-side-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background:
    linear-gradient(135deg, rgba(56, 189, 248, 0.07), rgba(34, 197, 94, 0.05)),
    var(--panel);
  box-shadow: 0 18px 58px rgba(0, 0, 0, 0.22);
}

.ranking-hero > div {
  padding: clamp(22px, 4vw, 36px);
}

.ranking-hero h1 {
  max-width: 620px;
  margin: 0;
  font-size: clamp(38px, 7vw, 70px);
  line-height: 0.95;
}

.ranking-hero p {
  max-width: 650px;
  color: var(--muted);
  line-height: 1.6;
}

.ranking-hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

.weekly-feature {
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-left: 4px solid var(--event);
  background:
    linear-gradient(135deg, var(--event-soft), rgba(255, 255, 255, 0.035)),
    var(--panel);
  padding: clamp(18px, 3vw, 28px);
}

.weekly-feature h2 {
  margin: 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 0.98;
}

.weekly-feature p {
  color: var(--muted);
  line-height: 1.5;
}

.weekly-feature strong {
  display: inline-flex;
  width: fit-content;
  margin-top: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  color: #bbf7d0;
  padding: 8px 11px;
  font-size: 13px;
}

.ranking-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
  gap: clamp(16px, 3vw, 28px);
  margin-top: clamp(16px, 3vw, 28px);
  align-items: start;
}

.public-ranking-card,
.ranking-side-card {
  padding: clamp(16px, 3vw, 24px);
}

.public-ranking-list {
  display: grid;
  gap: 10px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}

.public-ranking-list li {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.72);
  padding: 9px 12px;
}

.public-ranking-list li:first-child {
  border-color: rgba(245, 158, 11, 0.35);
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.18), rgba(15, 23, 42, 0.74));
}

.public-ranking-list li.ranking-empty {
  display: block;
  color: var(--muted);
}

.public-ranking-list .rank {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
  font-weight: 950;
}

.public-ranking-list .name {
  overflow: hidden;
  color: var(--ink);
  font-size: 17px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.public-ranking-list .lines {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.public-ranking-list .score {
  color: #7dd3fc;
  font-size: 18px;
  font-weight: 950;
}

.ranking-side-card {
  position: sticky;
  top: 76px;
}

.ranking-side-card h2 {
  margin: 0;
  font-size: 30px;
  line-height: 1;
}

.ranking-side-card p {
  color: var(--muted);
  line-height: 1.5;
}

.ranking-side-card .primary-button {
  width: 100%;
  margin-top: 10px;
}

.growth-section {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 0 clamp(10px, 1.5vw, 18px) 36px;
}

.growth-heading {
  border: 1px solid var(--line);
  border-radius: 12px;
  background:
    linear-gradient(135deg, rgba(56, 189, 248, 0.08), rgba(34, 197, 94, 0.06)),
    var(--panel);
  padding: clamp(18px, 3vw, 26px);
}

.growth-heading h2 {
  margin: 0;
  font-size: clamp(30px, 4vw, 48px);
  line-height: 1;
}

.growth-heading p:last-child {
  max-width: 760px;
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.growth-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.growth-card {
  min-height: 210px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent-line, var(--accent));
  border-radius: 10px;
  background:
    linear-gradient(180deg, var(--accent-soft, rgba(56, 189, 248, 0.08)), rgba(255, 255, 255, 0.035)),
    var(--panel);
  padding: 16px;
}

.growth-card h3 {
  margin: 14px 0 8px;
  font-size: 22px;
  line-height: 1.05;
}

.growth-card p,
.growth-card li {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.growth-card ul {
  display: grid;
  gap: 6px;
  margin: 10px 0 0;
  padding-left: 18px;
}

.status-pill {
  display: inline-flex;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  padding: 6px 9px;
  font-size: 11px;
  font-weight: 950;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.accent-cyan {
  --accent-line: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.11);
}

.accent-green {
  --accent-line: #22c55e;
  --accent-soft: rgba(34, 197, 94, 0.11);
}

.accent-gold {
  --accent-line: #f59e0b;
  --accent-soft: rgba(245, 158, 11, 0.12);
}

.accent-pink {
  --accent-line: #ec4899;
  --accent-soft: rgba(236, 72, 153, 0.11);
}

.game-over {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  z-index: 80;
  background: rgba(0, 0, 0, 0.7);
  padding: 18px;
}

.game-over.show {
  display: grid;
}

.game-over-card {
  width: min(420px, 100%);
  border-radius: 18px;
  background: #f8fafc;
  color: #0f172a;
  padding: 26px;
  text-align: center;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.35);
}

.game-over-card h2 {
  margin: 0;
  font-size: 32px;
}

.game-over-card p {
  color: #475569;
}

.name-field {
  display: grid;
  gap: 7px;
  margin: 18px 0 8px;
  text-align: left;
}

.name-field span {
  color: #475569;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.name-field input {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  background: #fff;
  color: #0f172a;
  font: inherit;
  font-weight: 850;
  outline: 0;
  padding: 12px 14px;
}

.name-field input:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

.game-over-card .primary-button,
.game-over-card .secondary-button {
  width: 100%;
  margin-top: 10px;
}

.tutorial {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  z-index: 90;
  background: rgba(2, 6, 23, 0.76);
  padding: 18px;
}

.tutorial.show {
  display: grid;
}

.tutorial-card {
  width: min(520px, 100%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  background: #101827;
  padding: clamp(22px, 4vw, 32px);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.42);
}

.tutorial-card h2 {
  margin: 0 0 18px;
  font-size: clamp(30px, 5vw, 46px);
  line-height: 1;
}

.tutorial-steps {
  display: grid;
  gap: 10px;
  margin-bottom: 22px;
}

.tutorial-steps div {
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: center;
  gap: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  padding: 12px;
}

.tutorial-steps strong {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--event);
  color: #02111a;
  font-weight: 950;
}

.tutorial-steps span {
  color: var(--ink);
  font-weight: 800;
}

@media (max-width: 1020px) {
  html,
  body {
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .play-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .game-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    height: auto;
    overflow: visible;
  }

  .campaign-strip {
    grid-column: 1;
    grid-row: auto;
    align-items: stretch;
    flex-direction: column;
  }

  .ad-rail {
    grid-column: 1;
    grid-row: auto;
    grid-template-columns: repeat(5, 180px);
    grid-template-rows: auto 150px;
    justify-content: start;
    overflow-x: auto;
  }

  .ad-rail-header {
    grid-column: 1 / -1;
  }

  .game-panel {
    grid-column: 1;
    grid-row: auto;
  }

  .side-panel {
    grid-column: 1;
    grid-row: auto;
    overflow: visible;
    position: static;
  }

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

  .ranking-hero,
  .ranking-content {
    grid-template-columns: 1fr;
  }

  .ranking-side-card {
    position: static;
  }
}

@media (max-width: 560px) {
  :root {
    --cell: min(7vw, 34px);
  }

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

  .topbar nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

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

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

  .piece-slot {
    min-height: 104px;
  }

  .install-card {
    grid-template-columns: 1fr;
  }

  .qr-code {
    width: 150px;
    height: 150px;
  }

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

  .public-ranking-list li {
    grid-template-columns: 38px minmax(0, 1fr) auto;
  }

  .public-ranking-list .lines {
    display: none;
  }
}
