:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --text: #1d1c1a;
  --muted: #6b6862;
  --border: #e2dfd8;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-soft: #e8e7fc;
  --good: #0f8a5f;
  --warn: #b45309;
  --danger: #c2410c;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.06);
  --radius: 14px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1e1d1b;
    --surface-2: #2a2926;
    --text: #f1efe9;
    --muted: #a19d94;
    --border: #34322e;
    --accent: #8b85ff;
    --accent-text: #12111a;
    --accent-soft: #2b2948;
    --good: #34d399;
    --warn: #fbbf24;
    --danger: #fb923c;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button { font: inherit; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---- top bar ---------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar .wrap { display: flex; align-items: center; gap: 16px; min-height: 60px; flex-wrap: wrap; padding-block: 8px; }
.brand { font-weight: 700; font-size: 17px; text-decoration: none; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 26px; height: 26px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: var(--accent-text); font-size: 14px; }
.spacer { flex: 1; }

.session { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 14px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
}
.pill.live { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.pill.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.dots { display: inline-flex; gap: 4px; }
.dot { display: inline-block; flex: none; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--accent); }
.dot.used { background: var(--accent); }
.who { color: var(--muted); font-size: 13px; }
.who button { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; font-size: 13px; }

/* ---- buttons ---------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 600; font-size: 14px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform .08s, background .15s, border-color .15s;
}
.btn:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { padding: 12px 20px; font-size: 16px; border-radius: 12px; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }

/* ---- vote control ----------------------------------------------------- */
.vote { display: inline-flex; align-items: center; gap: 6px; }
.vote .count { min-width: 20px; text-align: center; font-weight: 700; }
.vote .btn { padding: 5px 10px; }
.vote .btn.minus { padding: 5px 9px; }

/* ---- home ------------------------------------------------------------- */
.hero { padding: 40px 0 24px; }
.hero h1 { font-size: clamp(28px, 4vw, 40px); line-height: 1.15; margin: 0 0 8px; letter-spacing: -.02em; }
.hero p { margin: 0; color: var(--muted); max-width: 640px; font-size: 16px; }

.notice {
  margin: 0 0 20px; padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
}
.notice.warn { border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); }
.notice strong { font-weight: 650; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; padding-bottom: 48px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s;
}
.card:hover { transform: translateY(-2px); }
.card-link { color: inherit; text-decoration: none; display: flex; flex-direction: column; flex: 1; }
.thumb { aspect-ratio: 16 / 9; position: relative; overflow: hidden; background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .gen { position: absolute; inset: 0; display: grid; place-items: center; font-size: 44px; font-weight: 800; color: #fff; letter-spacing: -.03em; }
.card-body { padding: 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card h3 { margin: 0; font-size: 18px; }
.card p { margin: 0; color: var(--muted); }
.meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 13px; color: var(--muted); }
.tag { padding: 2px 8px; border-radius: 999px; background: var(--surface-2); font-size: 12px; color: var(--muted); }
.status { padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; }
.card-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); border: 2px dashed var(--border); border-radius: var(--radius); }
.empty code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }

/* results */
.results { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 24px; box-shadow: var(--shadow); }
.results h2 { margin: 0 0 4px; font-size: 18px; }
.results .sub { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.bar-row { display: grid; grid-template-columns: 28px minmax(120px, 220px) 1fr 40px; gap: 10px; align-items: center; padding: 6px 0; }
.bar-row .rank { font-weight: 700; color: var(--muted); }
.bar-row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .name a { color: inherit; text-decoration: none; }
.bar-track { height: 12px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.bar-row.winner .bar-fill { background: var(--good); }
.bar-row .n { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---- detail ----------------------------------------------------------- */
.back { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); text-decoration: none; font-size: 14px; margin: 24px 0 8px; }
.back:hover { color: var(--text); }
.detail { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 32px; padding-bottom: 60px; align-items: start; }
.detail h1 { font-size: clamp(26px, 4vw, 38px); margin: 6px 0 8px; letter-spacing: -.02em; line-height: 1.15; }
.detail .lede { font-size: 17px; color: var(--muted); margin: 0 0 16px; }
.actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin: 20px 0; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-top: 20px; }
.panel h2 { font-size: 15px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.try { margin: 0; padding-left: 20px; }
.try li { margin: 4px 0; }
.preview {
  position: sticky; top: 84px;
  border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border);
  background: var(--surface); box-shadow: var(--shadow);
}
.preview-chrome { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.preview-chrome i { width: 10px; height: 10px; border-radius: 50%; background: var(--border); display: inline-block; }
.preview-frame { position: relative; aspect-ratio: 4 / 3; overflow: hidden; display: block; }
.preview-frame iframe { position: absolute; top: 0; left: 0; width: 200%; height: 200%; border: 0; transform: scale(.5); transform-origin: 0 0; pointer-events: none; background: #fff; }
.preview-frame .overlay { position: absolute; inset: 0; display: grid; place-items: center; background: transparent; transition: background .2s; text-decoration: none; }
.preview-frame .overlay span { opacity: 0; transition: opacity .2s; }
.preview-frame:hover .overlay { background: rgba(0,0,0,.35); }
.preview-frame:hover .overlay span { opacity: 1; }

.prose { line-height: 1.65; }
.prose > :first-child { margin-top: 0; }
.prose h1, .prose h2, .prose h3 { line-height: 1.25; margin: 1.4em 0 .5em; text-transform: none; letter-spacing: 0; color: var(--text); }
.prose h1 { font-size: 22px; } .prose h2 { font-size: 19px; } .prose h3 { font-size: 16px; }
.prose code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: .92em; }
.prose pre { background: var(--surface-2); padding: 12px 14px; border-radius: 10px; overflow-x: auto; }
.prose pre code { background: none; padding: 0; }
.prose img { max-width: 100%; border-radius: 10px; }
.prose blockquote { margin: 0; padding-left: 14px; border-left: 3px solid var(--border); color: var(--muted); }

/* ---- play ------------------------------------------------------------- */
body.play { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.playbar .wrap { max-width: none; }
.playbar .title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage { flex: 1; position: relative; background: var(--surface-2); }
.stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; }
.device-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.device-toggle button { background: var(--surface); border: 0; padding: 6px 10px; cursor: pointer; color: var(--muted); font-size: 13px; }
.device-toggle button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.stage.phone iframe, .stage.tablet iframe {
  left: 50%; top: 24px; transform: translateX(-50%); height: calc(100% - 48px);
  border-radius: 24px; box-shadow: var(--shadow); border: 8px solid #222;
}
.stage.phone iframe { width: 390px; }
.stage.tablet iframe { width: 820px; max-width: calc(100% - 32px); }

/* ---- dialog + toast --------------------------------------------------- */
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 24px; width: min(400px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h2 { margin: 0 0 6px; font-size: 19px; }
dialog p { margin: 0 0 16px; color: var(--muted); }
dialog input { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit; margin-bottom: 16px; }
dialog input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
dialog .row { display: flex; gap: 10px; justify-content: flex-end; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; opacity: 0; transition: opacity .2s, transform .2s; z-index: 100; pointer-events: none;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 820px) {
  .detail { grid-template-columns: 1fr; }
  .preview { position: static; order: -1; }
  .bar-row { grid-template-columns: 24px minmax(80px, 1fr) 1fr 32px; }
  .playbar .hide-sm { display: none; }
}
.playbar .who { display: none; }
