:root {
  --bg: #080d1a;
  --bg2: #0e1730;
  --panel: #141f3a;
  --panel2: #1a2748;
  --line: #26365c;
  --text: #e9eeff;
  --muted: #93a2c6;
  --accent: #4ade80;
  --accent-ink: #052e16;
  --accent2: #38bdf8;
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Helvetica Neue", sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(56, 189, 248, 0.14), transparent 60%),
    radial-gradient(900px 500px at 0% 0%, rgba(74, 222, 128, 0.12), transparent 55%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.focus .topbar { display: none; }

a { color: inherit; text-decoration: none; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
}

input {
  font: inherit;
  color: inherit;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: calc(env(safe-area-inset-top) + 10px) 18px 10px;
  background: rgba(8, 13, 26, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(38, 54, 92, 0.7);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-size: 19px;
}

.brand-wheel {
  position: relative;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  display: block;
  flex: 0 0 auto;
}

.brand-wheel::before,
.brand-wheel::after {
  content: "";
  position: absolute;
  background: var(--accent2);
  border-radius: 2px;
}

.brand-wheel::before { left: 50%; top: 2px; bottom: 2px; width: 2px; margin-left: -1px; }
.brand-wheel::after { top: 50%; left: 2px; right: 2px; height: 2px; margin-top: -1px; }
.brand-wheel i { position: absolute; inset: 6px; border-radius: 50%; background: var(--bg); }

.nav { display: flex; gap: 4px; margin-left: 8px; }

.nav a {
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.nav a:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.nav a.active { color: var(--text); background: rgba(255, 255, 255, 0.09); }

.userchip {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  max-width: 40vw;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chip-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-block;
  flex: 0 0 auto;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
}

/* ---------- shared bits ---------- */

main { display: block; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 18px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 15px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  transition: transform 0.12s ease, background 0.15s ease;
}

.btn:active { transform: scale(0.97); }
.btn.accent { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: rgba(255, 255, 255, 0.04); }
.btn.small { padding: 8px 13px; font-size: 13px; border-radius: 10px; }
.btn:hover { background: rgba(255, 255, 255, 0.13); }
.btn.accent:hover { background: #5ee98f; }

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  font-size: 22px;
  line-height: 1;
  padding-bottom: 4px;
}

.icon-btn:active { transform: scale(0.95); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translate(-50%, 16px);
  background: #eaf1ff;
  color: #0b1020;
  font-weight: 700;
  font-size: 14px;
  padding: 11px 18px;
  border-radius: 999px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 90;
  max-width: 80vw;
  text-align: center;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

.missing {
  padding: 80px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.6;
}

.missing a { color: var(--accent); font-weight: 700; }

.empty {
  color: var(--muted);
  padding: 30px 4px;
  font-size: 15px;
}

/* ---------- home ---------- */

.hero {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 24px;
  align-items: center;
  padding: 34px 18px 10px;
  max-width: 1120px;
  margin: 0 auto;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 11px;
  font-weight: 800;
  color: var(--accent);
  margin: 0 0 10px;
}

.hero h1 {
  margin: 0;
  font-size: clamp(30px, 6.4vw, 52px);
  line-height: 1.04;
  letter-spacing: -0.03em;
}

.hero .sub {
  color: var(--muted);
  font-size: 16px;
  line-height: 1.55;
  margin: 14px 0 22px;
  max-width: 46ch;
}

.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.hero-art {
  position: relative;
  aspect-ratio: 1 / 1;
  max-height: 360px;
  border-radius: 26px;
  background:
    radial-gradient(circle at 50% 30%, rgba(74, 222, 128, 0.22), transparent 62%),
    linear-gradient(160deg, #16294a, #0b1428);
  border: 1px solid var(--line);
  overflow: hidden;
}

.hero-art canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: pan-y; }

.hero-tag {
  position: absolute;
  left: 14px;
  bottom: 12px;
  font-size: 12px;
  font-weight: 700;
  color: rgba(233, 238, 255, 0.8);
  background: rgba(0, 0, 0, 0.35);
  padding: 5px 11px;
  border-radius: 999px;
  backdrop-filter: blur(6px);
}

.discover {
  max-width: 1120px;
  margin: 0 auto;
  padding: 22px 18px 40px;
}

.row-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.row-head h2 {
  font-size: 21px;
  margin: 0;
  letter-spacing: -0.02em;
}

.search {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  width: min(240px, 50vw);
  outline: none;
}

.search:focus { border-color: var(--accent2); background: rgba(56, 189, 248, 0.08); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(225px, 1fr));
  gap: 16px;
}

.card {
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.thumb-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #0b1225;
  overflow: hidden;
}

.thumb-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 4px; flex: 1; }

.card-body h3 {
  margin: 0;
  font-size: 16px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-body .meta {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}

.card-actions { display: flex; gap: 8px; margin-top: 10px; }

.foot {
  text-align: center;
  color: #5d6b8c;
  font-size: 12.5px;
  padding: 10px 18px calc(env(safe-area-inset-bottom) + 30px);
}

/* ---------- editor / studio ---------- */

.studio {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: #0a1428;
  overflow: hidden;
}

.studio-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.studio-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: linear-gradient(rgba(7, 13, 27, 0.92), rgba(7, 13, 27, 0.35) 75%, transparent);
}

.title-input {
  flex: 1;
  min-width: 0;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 9px 12px;
  font-size: 15px;
  font-weight: 700;
  outline: none;
}

.title-input:focus { border-color: var(--accent); background: rgba(74, 222, 128, 0.1); }

.block-count {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.studio-hud {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  padding: 14px 12px calc(env(safe-area-inset-bottom) + 12px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(transparent, rgba(5, 10, 22, 0.9) 45%);
}

.studio-hint {
  margin: 0;
  font-size: 11.5px;
  color: rgba(147, 162, 198, 0.85);
  text-align: center;
  pointer-events: none;
}

.seg {
  align-self: center;
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(12, 21, 41, 0.9);
  border: 1px solid var(--line);
}

.seg-btn {
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--muted);
}

.seg-btn.active { background: var(--accent); color: var(--accent-ink); }

.palette {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 4px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.palette::-webkit-scrollbar { display: none; }

.swatch {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  border: 2px solid rgba(255, 255, 255, 0.16);
  flex: 0 0 auto;
  padding: 0;
}

.swatch.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.8);
}

/* ---------- play ---------- */

.play {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow: hidden;
  background: #0a1428;
}

.play-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.play-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 10px;
  background: linear-gradient(rgba(5, 12, 26, 0.85), transparent);
}

.play-title {
  font-weight: 800;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.coin-pill {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(10, 20, 40, 0.8);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 800;
}

.coin-pill .dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #fbbf24;
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.7);
}

.play-foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 20px calc(env(safe-area-inset-bottom) + 22px);
  pointer-events: none;
}

.stick {
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.22);
  display: grid;
  place-items: center;
  pointer-events: auto;
  touch-action: none;
}

.knob {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  transition: transform 0.06s linear;
}

.jump-btn {
  pointer-events: auto;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: rgba(74, 222, 128, 0.85);
  color: var(--accent-ink);
  font-weight: 800;
  font-size: 15px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
  touch-action: none;
}

.jump-btn:active { transform: scale(0.94); }

.win {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  place-items: center;
  background: rgba(5, 10, 22, 0.72);
  backdrop-filter: blur(6px);
  text-align: center;
  padding: 24px;
}

.win.show { display: grid; }
.win h2 { font-size: 30px; margin: 0 0 6px; }
.win p { color: var(--muted); margin: 0 0 20px; }

/* ---------- avatar page ---------- */

.avatar-page {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  max-width: 1000px;
  margin: 0 auto;
  padding: 24px 18px 60px;
  align-items: start;
}

.avatar-stage {
  position: sticky;
  top: 84px;
  aspect-ratio: 1 / 1;
  border-radius: 26px;
  background:
    radial-gradient(circle at 50% 32%, rgba(56, 189, 248, 0.22), transparent 62%),
    linear-gradient(160deg, #16294a, #0b1428);
  border: 1px solid var(--line);
  overflow: hidden;
}

.avatar-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: pan-y; }

.avatar-panel h1 { margin: 0 0 16px; font-size: 26px; letter-spacing: -0.02em; }

.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 20px; }

.field span, .group-label {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.field input {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 15px;
  font-weight: 600;
  outline: none;
}

.field input:focus { border-color: var(--accent2); }

.group { margin-bottom: 16px; display: flex; flex-direction: column; gap: 9px; }

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

.swatches .swatch { width: 34px; height: 34px; border-radius: 11px; }

.hat-row { display: flex; flex-wrap: wrap; gap: 8px; }

.pill {
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.pill.active { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

.note { color: #6a7899; font-size: 12.5px; line-height: 1.5; margin: 16px 0 0; }

/* ---------- sign up / log in ---------- */

.auth {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 24px;
  max-width: 1000px;
  margin: 0 auto;
  padding: 26px 18px 60px;
  align-items: start;
}

.auth-art {
  position: sticky;
  top: 84px;
  aspect-ratio: 1 / 1;
  border-radius: 26px;
  background:
    radial-gradient(circle at 50% 30%, rgba(74, 222, 128, 0.2), transparent 60%),
    linear-gradient(160deg, #16294a, #0b1428);
  border: 1px solid var(--line);
  overflow: hidden;
}

.auth-art canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: pan-y; }

.auth-art-tag {
  position: absolute;
  left: 14px;
  bottom: 12px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(233, 238, 255, 0.72);
}

.auth-panel {
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px;
}

.auth-panel h1 { margin: 0 0 6px; font-size: 25px; letter-spacing: -0.02em; }

.auth-sub { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0 0 18px; }

.auth-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  width: fit-content;
  margin-bottom: 18px;
}

.auth-tab { padding: 8px 16px; border-radius: 999px; font-size: 13.5px; font-weight: 700; color: var(--muted); }
.auth-tab.active { background: var(--accent); color: var(--accent-ink); }

.auth-error { display: none; color: #fca5a5; font-size: 13px; font-weight: 600; margin: 0 0 12px; line-height: 1.4; }
.auth-error.show { display: block; }

.auth-submit { width: 100%; padding: 13px; margin-top: 2px; }

.auth-foot { color: var(--muted); font-size: 12.5px; line-height: 1.5; margin: 16px 0 0; }

.auth-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }

.account-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
}

.account-card .meta { color: var(--muted); font-size: 12.5px; margin: 2px 0 0; }

.account-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  font-size: 13.5px;
  color: var(--muted);
}

.linkbtn {
  padding: 0;
  background: none;
  border: 0;
  color: var(--accent);
  font-size: inherit;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.guest-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  max-width: 1120px;
  margin: 14px auto 0;
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.35);
  font-size: 13.5px;
}

.chip-guest { background: rgba(255, 255, 255, 0.22); }

/* ---------- responsive ---------- */

@media (max-width: 760px) {
  .hero { grid-template-columns: 1fr; padding-top: 22px; }
  .hero-art { max-height: 260px; aspect-ratio: 16 / 11; order: -1; }
  .avatar-page { grid-template-columns: 1fr; }
  .avatar-stage { position: relative; top: 0; max-height: 320px; aspect-ratio: 4 / 3; }
  .topbar {
    flex-wrap: wrap;
    gap: 8px 10px;
    padding: calc(env(safe-area-inset-top) + 10px) 14px 8px;
  }
  .brand-name { font-size: 17px; }
  .nav {
    order: 3;
    width: 100%;
    margin-left: 0;
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { padding: 7px 11px; font-size: 13px; white-space: nowrap; }
  .userchip { max-width: 45vw; }
  .search { width: 44vw; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .auth { grid-template-columns: 1fr; padding-top: 18px; }
  .auth-art { position: relative; top: 0; order: -1; max-height: 230px; aspect-ratio: 16 / 11; }
  .auth-panel { padding: 18px; }
  .guest-banner { margin: 12px 14px 0; font-size: 13px; text-align: center; }
}
