:root {
  --bg: #0f0f14;
  --panel: #171720;
  --panel-2: #222233;
  --text: #f5f3e8;
  --muted: #b8b3a8;
  --line: #38384d;
  --accent: #66e3a6;
  --accent-2: #ffd166;
  --danger: #ff6678;
  --blue: #7cc4ff;
  --shadow: 0 24px 80px rgba(0,0,0,.45);
  --font: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(circle at 20% 0%, rgba(102,227,166,.18), transparent 28rem),
    radial-gradient(circle at 80% 10%, rgba(124,196,255,.14), transparent 26rem),
    var(--bg);
  overflow: hidden;
  touch-action: manipulation;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.phone-shell {
  min-height: 100dvh;
  width: 100%;
  display: grid;
  place-items: center;
  padding: 18px;
}

.game-card {
  width: min(100vw - 36px, 430px, calc((100dvh - 36px) * 9 / 16));
  height: min(100dvh - 36px, 820px, calc((100vw - 36px) * 16 / 9));
  min-height: 560px;
  background: #111118;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 22px;
  image-rendering: pixelated;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  overflow-y: auto;
  background:
    linear-gradient(180deg, rgba(255,255,255,.03), transparent 28%),
    #111118;
  border-radius: 22px;
}
.screen.active { display: block; }

.sound-btn {
  position: absolute;
  z-index: 10;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  min-height: 30px;
  padding: 5px 9px;
  border: 2px solid rgba(255,255,255,.15);
  background: rgba(0,0,0,.35);
  color: var(--muted);
  box-shadow: 3px 3px 0 #000;
  cursor: pointer;
  text-transform: uppercase;
  font-size: .7rem;
  font-weight: 900;
}
.sound-btn.on { color: #07130d; background: var(--accent-2); border-color: var(--accent-2); }

.brand-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
  padding-right: 86px;
}
.pixel-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 6px 10px;
  border: 2px solid var(--accent);
  color: #07130d;
  background: var(--accent);
  box-shadow: 4px 4px 0 #000;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.tiny-text, .privacy {
  color: var(--muted);
  font-size: .78rem;
}

h1, h2, p { margin-top: 0; }
h1 {
  margin-bottom: 8px;
  font-size: clamp(2rem, 11vw, 3.1rem);
  line-height: .9;
  letter-spacing: -.08em;
  text-shadow: 4px 4px 0 #000;
}
h2 {
  margin-bottom: 12px;
  font-size: clamp(1.55rem, 7vw, 2.3rem);
  line-height: 1;
  text-shadow: 3px 3px 0 #000;
}
.subtitle, .mission-panel p {
  color: var(--muted);
  line-height: 1.5;
}

.preview-wrap {
  display: grid;
  place-items: center;
  margin: 18px auto;
  width: 188px;
  height: 188px;
  border: 2px solid var(--line);
  background:
    linear-gradient(45deg, rgba(255,255,255,.04) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.04) 75%),
    linear-gradient(45deg, rgba(255,255,255,.04) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.04) 75%);
  background-size: 28px 28px;
  background-position: 0 0, 14px 14px;
  box-shadow: 6px 6px 0 #000;
}
#previewCanvas {
  width: 160px;
  height: 160px;
  image-rendering: pixelated;
}

.field {
  display: grid;
  gap: 8px;
  margin: 0 0 16px;
}
.field span, .chooser > span {
  color: var(--accent-2);
  font-size: .82rem;
  font-weight: 800;
  text-transform: uppercase;
}
.field input {
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 0;
  background: #0b0b10;
  color: var(--text);
  min-height: 48px;
  padding: 0 12px;
  outline: none;
  box-shadow: 4px 4px 0 #000;
}
.field input:focus { border-color: var(--accent); }

.creator-grid {
  display: grid;
  gap: 14px;
}
.chooser {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 2px solid var(--line);
  background: var(--panel);
  box-shadow: 4px 4px 0 #000;
}
.choice-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.choice-btn {
  min-height: 44px;
  border: 2px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  box-shadow: 3px 3px 0 #000;
}
.choice-btn.active {
  border-color: var(--accent);
  outline: 2px solid rgba(102,227,166,.25);
}
.choice-swatch {
  display: inline-block;
  width: 22px;
  height: 22px;
  border: 2px solid #000;
  vertical-align: middle;
}

.primary-btn, .secondary-btn {
  width: 100%;
  min-height: 54px;
  margin-top: 16px;
  border: 0;
  cursor: pointer;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .03em;
  box-shadow: 5px 5px 0 #000;
}
.primary-btn { background: var(--accent); color: #07130d; }
.secondary-btn { background: var(--panel-2); color: var(--text); border: 2px solid var(--line); }
.ghost-link {
  margin-top: 14px;
  border: 0;
  background: transparent;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
}
.primary-btn:active, .secondary-btn:active, .choice-btn:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 #000; }

.privacy { text-align: center; margin: 14px 0 0; }

.mission-panel {
  min-height: calc(100% - 36px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}
.result-panel { text-align: center; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 18px 0 4px;
}
.stats-grid div {
  padding: 12px 6px;
  border: 2px solid var(--line);
  background: var(--panel);
  box-shadow: 3px 3px 0 #000;
}
.stats-grid strong { display: block; font-size: 1.35rem; color: var(--accent-2); }
.stats-grid span { display: block; margin-top: 4px; color: var(--muted); font-size: .72rem; }
.quote-text {
  color: var(--accent-2) !important;
  border: 2px solid var(--line);
  background: rgba(255,209,102,.08);
  padding: 12px;
  margin: 14px 0 0;
  box-shadow: 3px 3px 0 #000;
}

.game-screen { padding: 0; overflow: hidden; background: #07070a; }
#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  background: #07070a;
  touch-action: none;
}
.touch-hint {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: max(10px, env(safe-area-inset-bottom));
  text-align: center;
  color: rgba(245,243,232,.68);
  font-size: .72rem;
  pointer-events: none;
  text-shadow: 2px 2px 0 #000;
  animation: fadeHint 4s ease forwards;
}
@keyframes fadeHint { 0%, 60% { opacity: 1; } 100% { opacity: .15; } }

@media (max-width: 519px) {
  .phone-shell { display: flex; align-items: stretch; justify-content: center; padding: 0; }
  .game-card {
    width: 100vw;
    height: 100dvh;
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
  }
  .screen { border-radius: 0; }
}

@media (max-height: 650px) and (min-width: 520px) {
  .game-card { min-height: 0; }
  .preview-wrap { width: 150px; height: 150px; margin: 10px auto; }
  #previewCanvas { width: 128px; height: 128px; }
  .creator-grid { gap: 8px; }
  .chooser { padding: 8px; }
  .primary-btn, .secondary-btn { min-height: 46px; margin-top: 10px; }
}

.compact-btn {
  margin-top: 10px;
  min-height: 46px;
}

.small-subtitle {
  font-size: .86rem;
}

.total-score-line {
  margin: 12px 0 0;
  padding: 10px;
  border: 2px solid var(--accent);
  background: rgba(102, 227, 166, .08);
  color: var(--accent);
  box-shadow: 3px 3px 0 #000;
  font-weight: 900;
}

.leaderboard-preview {
  margin-top: 14px;
  border: 2px solid var(--line);
  background: rgba(0,0,0,.22);
  box-shadow: 3px 3px 0 #000;
  padding: 12px;
  text-align: left;
}

.leaderboard-preview h3 {
  margin: 0 0 8px;
  color: var(--accent-2);
  font-size: .95rem;
  text-transform: uppercase;
}

.leaderboard-list {
  display: grid;
  gap: 8px;
  list-style-position: inside;
  padding: 0;
  margin: 14px 0 4px;
  text-align: left;
}

.leaderboard-list li,
.leaderboard-row {
  padding: 10px;
  border: 2px solid var(--line);
  background: var(--panel);
  box-shadow: 3px 3px 0 #000;
  color: var(--text);
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  margin: 6px 0;
}

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

.leaderboard-score {
  color: var(--accent-2);
  font-weight: 900;
}

.leaderboard-meta {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: .68rem;
}

.leaderboard-empty {
  color: var(--muted);
  border: 2px dashed var(--line);
  padding: 14px;
  background: rgba(255,255,255,.03);
}
