:root {
  --bg: #f7f5f2;
  --paper: #fffdfa;
  --text: #2d2a26;
  --muted: #8a8580;
  --line: #e8e1d6;
  --gold: #c9a96e;
  --gold-dark: #9f7b3e;
  --ink: #191816;
  --soft: #fbf4e8;
  --blue: #506f9f;
  --green: #5c8d72;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Noto Sans SC", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea { font: inherit; }

.spark-v2-shell {
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  background: radial-gradient(circle at 50% 0%, #fffaf0 0, var(--bg) 310px);
}

.spark-v2-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 12px;
  background: rgba(247,245,242,.94);
  border-bottom: 1px solid rgba(232,225,214,.72);
  backdrop-filter: blur(12px);
}

.spark-v2-title {
  text-align: center;
  font-size: 17px;
  font-weight: 800;
}

.spark-v2-subtitle {
  margin-top: 2px;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
}

.icon-link {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: var(--text);
  text-decoration: none;
  border-radius: 50%;
  background: rgba(255,255,255,.62);
  border: 1px solid rgba(232,225,214,.8);
}

.spark-v2-main {
  padding: 18px 16px 32px;
}

.ritual {
  padding: 18px 0 10px;
}

.ritual-kicker {
  font-size: 12px;
  color: var(--gold-dark);
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.ritual h1 {
  margin-top: 8px;
  font-size: 28px;
  line-height: 1.18;
  letter-spacing: 0;
}

.ritual p {
  margin-top: 12px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
}

.stage-panel {
  margin-top: 18px;
  padding: 18px;
  border-radius: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: 0 12px 30px rgba(45,42,38,.06);
}

.stage-topline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.stage-count {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

.stage-title {
  font-size: 21px;
  line-height: 1.35;
  font-weight: 850;
  letter-spacing: 0;
}

.stage-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
}

.question-card {
  position: sticky;
  top: 78px;
  z-index: 8;
  margin: 16px 0 12px;
  padding: 13px 14px;
  border-radius: 8px;
  background: #fff8ea;
  border: 1px solid #ead8b5;
  box-shadow: 0 10px 24px rgba(45,42,38,.08);
}

.question-kicker {
  color: var(--gold-dark);
  font-size: 12px;
  font-weight: 850;
}

.question-text {
  margin-top: 3px;
  color: var(--text);
  font-size: 17px;
  line-height: 1.4;
  font-weight: 850;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.choice-btn,
.word-chip,
.emoji-chip {
  min-height: 48px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-weight: 750;
}

.choice-btn.active,
.word-chip.active,
.emoji-chip.active {
  border-color: var(--gold);
  background: #fff8ea;
  box-shadow: 0 0 0 3px rgba(201,169,110,.14);
}

.word-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.word-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 10px;
  font-size: 15px;
}

.custom-row {
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 10px;
  margin-top: 14px;
}

.text-input,
.text-area {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.text-input {
  height: 48px;
  padding: 0 13px;
}

.text-area {
  min-height: 132px;
  padding: 13px;
  line-height: 1.7;
  resize: vertical;
}

.text-input:focus,
.text-area:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201,169,110,.14);
}

.emoji-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.emoji-chip {
  min-width: 44px;
  min-height: 42px;
  font-size: 20px;
}

.spark-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  padding: 12px;
  border-radius: 8px;
  background: var(--soft);
}

.spark-preview .big {
  font-size: 32px;
}

.spark-preview strong {
  display: block;
  font-size: 18px;
}

.moment-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 14px 0;
}

.moment-reference {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.moment-reference summary {
  padding: 11px 12px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.moment-reference .moment-list {
  margin: 0;
  padding: 0 12px 12px;
}

.moment-pill {
  padding: 11px 12px;
  border-radius: 8px;
  background: #fff8ea;
  border: 1px solid #ead8b5;
  font-size: 13px;
  line-height: 1.7;
}

.copy-mini-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
  padding: 8px 13px;
  border: none;
  border-radius: 999px;
  background: #2d2a26;
  color: #fff;
  font-size: 12px;
  font-weight: 850;
  cursor: pointer;
}

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

.actions.wrap { flex-wrap: wrap; }

.primary-btn,
.secondary-btn,
.ghost-btn {
  flex: 1;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
}

.primary-btn {
  border: none;
  background: var(--gold);
  color: #fff;
}

.secondary-btn {
  border: 1.5px solid var(--gold);
  background: transparent;
  color: var(--gold-dark);
}

.ghost-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
}

.primary-btn:disabled,
.secondary-btn:disabled {
  opacity: .55;
  cursor: not-allowed;
}

.result-stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.lantern-card,
.badge-wrap {
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--paper);
  box-shadow: 0 12px 30px rgba(45,42,38,.06);
  padding: 18px;
}

.section-label {
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 800;
}

.lantern-text {
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.9;
}

.spark-badge {
  position: relative;
  overflow: hidden;
  min-height: 620px;
  padding: 34px 28px 24px;
  border-radius: 24px;
  background: var(--badge-bg-a, #f8f5ee);
  border: 1px solid var(--badge-border, rgba(201,169,110,.4));
  text-align: center;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.78);
}

.badge-kicker {
  color: rgba(95,90,83,.62);
  font-size: 12px;
  line-height: 1.3;
  font-weight: 850;
  letter-spacing: 0;
}

.badge-title {
  margin-top: 10px;
  color: #2d2a26;
  font-size: 28px;
  line-height: 1.2;
  font-weight: 900;
}

.badge-emoji {
  margin: 30px auto 24px;
  width: 138px;
  height: 138px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255,255,255,.48);
  border: 3px solid rgba(255,255,255,.72);
  font-size: 78px;
  box-shadow: 0 18px 42px rgba(90,70,40,.07);
}

.badge-word {
  font-size: 50px;
  line-height: 1.05;
  font-weight: 900;
  letter-spacing: 0;
}

.badge-phrase {
  margin: 10px auto 0;
  max-width: 270px;
  color: var(--badge-accent, #9b8768);
  font-size: 14px;
  line-height: 1.5;
  font-weight: 800;
  letter-spacing: 0;
}

.badge-like {
  margin: 30px auto 0;
  max-width: 310px;
  padding: 14px 20px;
  border-radius: 999px;
  background: #2d2a26;
  color: #fffaf0;
  font-size: 15px;
  line-height: 1.6;
  font-weight: 850;
  box-shadow: 0 12px 24px rgba(45,42,38,.08);
}

.badge-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  align-items: end;
  gap: 14px;
  margin: 48px 0 0;
  padding: 18px 0 0;
  border-top: 1px solid var(--badge-border, rgba(201,169,110,.34));
}

.badge-frame-info {
  min-width: 0;
  text-align: left;
  padding-bottom: 2px;
}

.brand-line {
  text-align: left;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.65;
  font-weight: 700;
}

.player-line {
  margin-top: 5px;
  color: #2d2a26;
  font-size: 21px;
  line-height: 1.2;
  font-weight: 900;
}

.game-line {
  margin-top: 8px;
  color: #918b83;
  font-size: 11px;
  line-height: 1.45;
  font-weight: 780;
}

.qr-wrap {
  justify-self: end;
  display: grid;
  justify-items: center;
  gap: 4px;
}

.qr-box {
  width: 68px;
  height: 68px;
  aspect-ratio: 1 / 1;
  padding: 3px;
  border-radius: 4px;
  background: #fff;
  border: 1px solid var(--badge-border, rgba(201,169,110,.34));
  box-shadow: 0 8px 16px rgba(70,55,35,.06);
}

.qr-box img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.qr-label {
  color: #918b83;
  font-size: 10px;
  line-height: 1.2;
  font-weight: 700;
}

.badge-bottom-line {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid rgba(165,158,148,.22);
  color: #918b83;
  font-size: 11px;
  line-height: 1.7;
  font-weight: 720;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 1000;
  transform: translateX(-50%);
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(25,24,22,.92);
  color: #fff;
  font-size: 13px;
}

.history-tabs {
  display: flex;
  gap: 8px;
  margin: 16px 0;
}

.history-tabs button {
  flex: 1;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-weight: 800;
}

.history-tabs button.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.clear-test-btn {
  width: 100%;
  min-height: 38px;
  margin: -4px 0 14px;
  border: 1px dashed var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 780;
  cursor: pointer;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-item {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-radius: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  cursor: pointer;
}

.history-emoji {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--soft);
  font-size: 24px;
}

.history-word {
  font-weight: 850;
  margin-bottom: 4px;
}

.history-meta,
.history-mini {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

.star-field {
  position: relative;
  height: 520px;
  margin-top: 14px;
  overflow: hidden;
  border-radius: 14px;
  background:
    radial-gradient(circle at 20% 20%, rgba(255,255,255,.22), transparent 90px),
    linear-gradient(180deg, #171820 0%, #2d3040 55%, #434047 100%);
}

.spark-star {
  position: absolute;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.42);
  background: rgba(255,255,255,.12);
  color: #fff;
  font-size: 25px;
  box-shadow: 0 0 24px rgba(255,232,170,.3);
  cursor: pointer;
}

.empty-state {
  padding: 42px 20px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.54);
  text-align: center;
  color: var(--muted);
  line-height: 1.8;
}

.server-record-note {
  margin: 4px 0 16px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  text-align: center;
}

.detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: flex-end;
  background: rgba(0,0,0,.36);
}

.detail-panel {
  width: 100%;
  max-height: 82vh;
  overflow-y: auto;
  padding: 20px 18px max(24px, env(safe-area-inset-bottom));
  border-radius: 22px 22px 0 0;
  background: var(--paper);
}

.detail-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.detail-title strong {
  font-size: 20px;
}

.close-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
}

@media (max-width: 360px) {
  .spark-v2-main { padding: 14px 12px 28px; }
  .stage-panel, .lantern-card, .badge-wrap { padding: 15px; }
  .spark-badge { min-height: 590px; padding: 28px 20px 22px; }
  .badge-kicker { font-size: 10px; }
  .badge-title { font-size: 24px; }
  .badge-emoji { width: 124px; height: 124px; font-size: 70px; }
  .badge-word { font-size: 46px; }
  .badge-like { font-size: 14px; padding: 13px 16px; }
  .badge-footer { grid-template-columns: minmax(0, 1fr) 62px; }
  .brand-line, .game-line { font-size: 10px; }
  .player-line { font-size: 19px; }
  .qr-box { width: 60px; height: 60px; }
}
