:root {
  --gold: #d4af37;
  --gold-bright: #ffd966;
  --purple: #4a1942;
  --bg-1: #0a0612;
  --bg-3: #2a0a3a;
  --ok: #58e2a8;
  --ng: #ff5e7e;
  --text: #f4ecd6;
  --text-dim: #c9b894;
  --glass-bg: rgba(255, 235, 200, 0.05);
  --glass-border: rgba(212, 175, 55, 0.25);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; min-height: 100vh; min-height: 100dvh; }
body {
  font-family: "Noto Serif JP", "Hiragino Mincho ProN", "Yu Mincho", serif;
  color: var(--text);
  background:
    radial-gradient(ellipse at top, var(--bg-3) 0%, var(--bg-1) 60%),
    radial-gradient(ellipse at bottom right, var(--purple) 0%, transparent 50%),
    var(--bg-1);
  background-attachment: fixed;
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

#bg-stars {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    radial-gradient(2px 2px at 20% 30%, var(--gold-bright), transparent),
    radial-gradient(1px 1px at 80% 20%, var(--gold), transparent),
    radial-gradient(1.5px 1.5px at 40% 70%, var(--gold-bright), transparent),
    radial-gradient(1px 1px at 60% 50%, var(--gold), transparent),
    radial-gradient(2px 2px at 90% 80%, var(--gold-bright), transparent);
  opacity: 0.35;
  animation: twinkle 4s ease-in-out infinite;
}
@keyframes twinkle { 0%, 100% { opacity: 0.3; } 50% { opacity: 0.55; } }

#app {
  position: relative;
  z-index: 1;
  max-width: 720px;
  margin: 0 auto;
  padding: calc(8px + var(--safe-top)) 12px calc(12px + var(--safe-bottom));
  min-height: 100vh;
  min-height: 100dvh;
}

.screen { display: none; animation: fadeIn 0.3s ease; }
.screen.active { display: flex; flex-direction: column; min-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 20px); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* ========== START ========== */
#screen-start { position: relative; overflow: hidden; }
#screen-start.active { justify-content: center; }
.hero {
  text-align: center;
  padding: 24px 8px;
  position: relative;
  z-index: 2;
}

/* radial light burst */
.intro-flash {
  position: absolute;
  top: 36%; left: 50%;
  width: 480px; height: 480px;
  margin: -240px 0 0 -240px;
  background: radial-gradient(circle, rgba(255,217,102,0.85) 0%, rgba(212,175,55,0.35) 25%, transparent 65%);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  z-index: 1;
  animation: flashBurst 1.3s ease-out forwards;
  mix-blend-mode: screen;
}
@keyframes flashBurst {
  0%   { opacity: 0; transform: scale(0.1); }
  20%  { opacity: 1; }
  45%  { opacity: 0.9; transform: scale(2.4); }
  100% { opacity: 0; transform: scale(4); }
}

/* gold floating particles */
.particles {
  position: absolute; inset: 0;
  pointer-events: none; z-index: 1;
  overflow: hidden;
}
.particles i {
  position: absolute;
  left: var(--x);
  bottom: -8px;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,217,102,0.95), rgba(212,175,55,0.3) 60%, transparent 80%);
  box-shadow: 0 0 6px rgba(255,217,102,0.6);
  opacity: 0;
  animation: floatUp var(--d) infinite linear;
  animation-delay: var(--del);
}
@keyframes floatUp {
  0%   { opacity: 0; transform: translate(0, 0); }
  10%  { opacity: 1; }
  90%  { opacity: 1; }
  100% { opacity: 0; transform: translate(24px, -110vh); }
}

/* chrysanthemum crest */
.crest-anim {
  width: 96px; height: 96px;
  margin: 0 auto 18px;
  position: relative;
  z-index: 2;
  animation: crestGlow 3.5s 2s infinite ease-in-out;
}
@keyframes crestGlow {
  0%, 100% { filter: drop-shadow(0 0 10px rgba(255,217,102,0.4)); }
  50%      { filter: drop-shadow(0 0 22px rgba(255,217,102,0.75)); }
}
.crest-svg { width: 100%; height: 100%; overflow: visible; display: block; }
.crest-svg .p {
  fill: url(#petalGrad);
  opacity: 0;
  transform-origin: 0 0;
  animation: petalIn 0.55s cubic-bezier(.25,1.4,.55,1) forwards;
  animation-delay: calc(0.45s + var(--i) * 0.05s);
}
@keyframes petalIn {
  0%   { opacity: 0; transform: rotate(calc(var(--i) * 22.5deg)) translateY(-44px) scale(0.35); }
  100% { opacity: 1; transform: rotate(calc(var(--i) * 22.5deg)) translateY(0) scale(1); }
}
.crest-svg .crest-center {
  opacity: 0;
  transform-origin: center;
  animation: centerPop 0.5s 1.35s cubic-bezier(.34,1.56,.64,1) forwards;
}
@keyframes centerPop {
  0%   { opacity: 0; transform: scale(0); }
  100% { opacity: 1; transform: scale(1); }
}

/* brush-stroke title */
.brush-title {
  position: relative;
  display: inline-block;
  font-size: 28px;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
  line-height: 1.3;
  font-weight: bold;
}
.brush-text {
  background: linear-gradient(90deg, #d4af37 0%, #ffd966 30%, #fff8c8 50%, #ffd966 70%, #d4af37 100%);
  background-size: 250% 100%;
  background-position: 100% 0;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  clip-path: inset(0 100% 0 0);
  filter: drop-shadow(0 0 12px rgba(255,217,102,0.35));
  animation:
    brushReveal 1.1s 1.4s cubic-bezier(.45,.05,.3,1) forwards,
    shimmer 5s 3s infinite linear;
}
@keyframes brushReveal {
  0%   { clip-path: inset(0 100% 0 0); }
  100% { clip-path: inset(0 0 0 0); }
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -100% 0; }
}
.brush-stroke {
  position: absolute;
  left: -4px; top: -6px; bottom: -6px;
  width: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,217,102,0.55) 50%, rgba(255,217,102,0.85) 95%, transparent 100%);
  filter: blur(10px);
  pointer-events: none;
  animation: brushStroke 1.1s 1.4s ease-out forwards;
}
@keyframes brushStroke {
  0%   { width: 0; opacity: 0; }
  15%  { opacity: 1; }
  85%  { opacity: 1; }
  100% { width: 105%; opacity: 0; }
}

/* delayed reveal for subtitle / rules / button */
.delayed { opacity: 0; animation: gentleIn 0.7s ease-out forwards; }
.subtitle.delayed { animation-delay: 2.5s; }
.rules.delayed { animation-delay: 2.7s; }
#btn-start.delayed { animation-delay: 2.9s; }
.meta.delayed { animation-delay: 3.1s; }
@keyframes gentleIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.subtitle { color: var(--text-dim); margin-bottom: 22px; font-size: 13px; padding: 0 8px; }
.rules { margin: 0 0 24px; padding: 16px; text-align: left; }
.rule {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 0; font-size: 13px; line-height: 1.5;
}
.rule:not(:last-child) { border-bottom: 1px solid rgba(212, 175, 55, 0.1); }
.rule .num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; flex-shrink: 0;
  border-radius: 50%; background: var(--gold); color: var(--bg-1);
  font-weight: bold; font-size: 12px;
}
.rule b { color: var(--gold-bright); }

.primary {
  font-family: inherit;
  font-size: 16px;
  letter-spacing: 0.12em;
  width: 100%;
  max-width: 320px;
  padding: 14px 24px;
  background: linear-gradient(135deg, var(--gold-bright), var(--gold));
  color: var(--bg-1);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-weight: bold;
  box-shadow: 0 6px 20px rgba(212, 175, 55, 0.4), inset 0 1px 0 rgba(255,255,255,0.4);
  transition: transform 0.15s, box-shadow 0.2s;
  min-height: 48px;
  touch-action: manipulation;
  margin: 0 auto;
  display: block;
}
.primary:active { transform: scale(0.97); }

.secondary {
  font-family: inherit;
  font-size: 14px;
  padding: 11px 22px;
  background: transparent;
  color: var(--gold-bright);
  border: 1px solid var(--gold);
  border-radius: 999px;
  cursor: pointer;
  min-height: 42px;
  touch-action: manipulation;
}
.secondary:active { background: rgba(212, 175, 55, 0.15); }

.meta { margin-top: 16px; color: var(--text-dim); font-size: 10px; opacity: 0.55; }

/* ========== QUIZ — ONE SCREEN ========== */
#screen-quiz.active { gap: 8px; padding-bottom: 0; }

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 6px 4px 8px;
  font-family: "Georgia", serif;
}
.t-q { color: var(--gold-bright); font-size: 15px; font-weight: bold; min-width: 44px; }
.t-q .t-slash { color: var(--text-dim); margin: 0 2px; font-weight: normal; }
#qIdx { font-size: 18px; }
#qTotal { font-size: 13px; color: var(--text-dim); }
.t-score { color: var(--gold-bright); font-size: 15px; font-weight: bold; }
.t-score small { color: var(--text-dim); font-size: 11px; margin-left: 1px; font-weight: normal; }
.t-combo { color: #ff9a3c; font-size: 14px; font-weight: bold; min-width: 36px; text-align: right; }
.progress {
  height: 6px;
  background: rgba(0,0,0,0.45);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--glass-border);
}
#bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
  box-shadow: 0 0 10px var(--gold-bright);
  transition: width 0.4s ease;
}

.cards {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 14px;
}
.card {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: transparent;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.18s, border-color 0.2s, box-shadow 0.2s;
  padding: 0;
  font-family: inherit;
  touch-action: manipulation;
  display: block;
  width: 100%;
  text-align: left;
}
.card:active { transform: scale(0.99); }
.card.picked { border-color: var(--gold-bright); box-shadow: 0 0 0 2px var(--gold-bright); }
.card.correct { border-color: var(--ok); box-shadow: 0 0 0 2px var(--ok), 0 6px 20px rgba(88, 226, 168, 0.4); }
.card.wrong { border-color: var(--ng); box-shadow: 0 0 0 2px var(--ng), 0 6px 20px rgba(255, 94, 126, 0.4); }
.card.disabled { pointer-events: none; }

.thumb-wrap {
  position: relative;
  width: min(100%, calc(26dvh * 16 / 9));
  aspect-ratio: 16/9;
  margin: 0 auto;
  background: #000;
  overflow: hidden;
  border-radius: 10px;
}
@supports not (height: 1dvh) {
  .thumb-wrap { width: min(100%, calc(26vh * 16 / 9)); }
}
.thumb { width: 100%; height: 100%; object-fit: cover; display: block; }

.card-title {
  padding: 6px 8px 0;
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--text);
  letter-spacing: 0.01em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
  min-height: 30px;
}
.card-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 0;
  min-height: 22px;
}
.date {
  color: var(--text-dim);
  font-size: 13px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  flex-shrink: 0;
}
.date::before { content: "📅 "; margin-right: 2px; }
.views {
  font-size: 17px;
  color: var(--gold-bright);
  font-weight: bold;
  font-family: "Georgia", serif;
  line-height: 1;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.4s, transform 0.4s;
  text-shadow: 0 0 14px rgba(255, 217, 102, 0.4);
  white-space: nowrap;
  text-align: right;
}
.card.revealed .views { opacity: 1; transform: none; }
.views::after { content: " 回"; font-size: 11px; color: var(--text-dim); font-weight: normal; }

.bottom-area {
  display: none;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 4px 0;
  flex-wrap: wrap;
}
.bottom-area.show { display: flex; animation: bottomIn 0.3s ease; }
@keyframes bottomIn { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.result-chip {
  font-size: 13px;
  letter-spacing: 0.04em;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--glass-border);
  font-weight: bold;
  white-space: nowrap;
}
.result-chip.ok { color: var(--ok); border-color: rgba(88, 226, 168, 0.5); }
.result-chip.ng { color: var(--ng); border-color: rgba(255, 94, 126, 0.5); }

.next-btn {
  font-family: inherit;
  font-size: 15px;
  letter-spacing: 0.12em;
  font-weight: bold;
  padding: 10px 26px;
  min-height: 42px;
  background: linear-gradient(135deg, var(--gold-bright), var(--gold));
  color: var(--bg-1);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(212, 175, 55, 0.45), inset 0 1px 0 rgba(255,255,255,0.4);
  touch-action: manipulation;
  transition: transform 0.15s;
  white-space: nowrap;
}
.next-btn:active { transform: scale(0.96); }

/* ========== RESULT ========== */
#screen-result.active { justify-content: center; }
.result-wrap {
  text-align: center;
  padding: 28px 20px;
  margin: 12px 0;
}
.rank-circle {
  display: inline-flex; flex-direction: column;
  align-items: center; justify-content: center;
  width: 140px; height: 140px;
  border: 3px solid var(--gold);
  border-radius: 50%;
  margin-bottom: 18px;
  background: radial-gradient(circle, rgba(212,175,55,0.2), transparent);
  box-shadow: 0 0 60px rgba(212, 175, 55, 0.5), inset 0 0 40px rgba(212, 175, 55, 0.2);
  animation: rankIn 0.8s cubic-bezier(.34,1.56,.64,1);
}
@keyframes rankIn { from { transform: scale(0); opacity: 0; } to { transform: none; opacity: 1; } }
.rank-letter {
  font-size: 70px;
  color: var(--gold-bright);
  font-weight: bold;
  font-family: "Georgia", serif;
  line-height: 1;
  text-shadow: 0 0 24px var(--gold-bright);
}
.rank-sub { font-size: 10px; color: var(--text-dim); letter-spacing: 0.2em; margin-top: 6px; }
.result-wrap h2 { font-size: 18px; color: var(--gold-bright); margin-bottom: 18px; letter-spacing: 0.08em; }
.result-stats { display: grid; grid-template-columns: 1fr; gap: 8px; margin-bottom: 20px; }
.result-stats > div {
  padding: 12px 16px;
  background: rgba(0,0,0,0.25);
  border-radius: 10px;
  display: flex; justify-content: space-between; align-items: center;
}
.result-stats .label { font-size: 11px; color: var(--text-dim); letter-spacing: 0.12em; }
.result-stats .big { font-size: 22px; color: var(--gold-bright); font-family: "Georgia", serif; font-weight: bold; }
.comment { color: var(--text); font-size: 13px; margin-bottom: 22px; line-height: 1.7; padding: 0 4px; }
.result-actions { display: flex; flex-direction: column; gap: 10px; align-items: center; }

/* ========== REVIEW ========== */
.review-title { text-align: center; color: var(--gold-bright); margin-bottom: 16px; letter-spacing: 0.08em; font-size: 17px; }
.review-list { display: grid; gap: 10px; margin-bottom: 18px; }
.review-item {
  display: grid; grid-template-columns: 1fr;
  gap: 8px; padding: 10px;
  border-radius: 10px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
}
.review-item .ri-card { position: relative; }
.review-item img { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px; display: block; }
.review-item .ri-info { font-size: 11px; margin-top: 5px; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.review-item .ri-views { color: var(--gold-bright); font-weight: bold; font-size: 13px; font-family: "Georgia", serif; }
.review-item .ri-ch { color: var(--text-dim); font-size: 10px; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.review-item .pick-mark {
  position: absolute; top: 5px; right: 5px;
  width: 26px; height: 26px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: bold;
}
.review-item .ri-card.user-correct .pick-mark { background: var(--ok); color: #001; }
.review-item .ri-card.user-wrong .pick-mark { background: var(--ng); color: #fff; }
.review-item .ri-card.winner { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 6px; }

#btn-back { display: block; margin: 0 auto 24px; }

/* ========== between-question transition — split & pass-through ========== */
.card.transitioning {
  opacity: 0 !important;
  pointer-events: none;
}

.card.leave-up,
.ghost-card.leave-up {
  animation: leaveUp 360ms cubic-bezier(.5,0,.6,.4) forwards;
}
.card.leave-down,
.ghost-card.leave-down {
  animation: leaveDown 360ms cubic-bezier(.5,0,.6,.4) forwards;
}
@keyframes leaveUp {
  0%   { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-130%); opacity: 0; }
}
@keyframes leaveDown {
  0%   { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(130%); opacity: 0; }
}

.card.enter-from-below {
  animation: enterFromBelow 380ms cubic-bezier(.2,.7,.25,1) backwards;
}
.card.enter-from-above {
  animation: enterFromAbove 380ms cubic-bezier(.2,.7,.25,1) backwards;
}
@keyframes enterFromBelow {
  0%   { transform: translateY(85%); opacity: 0; }
  60%  { opacity: 1; }
  100% { transform: translateY(0); opacity: 1; }
}
@keyframes enterFromAbove {
  0%   { transform: translateY(-85%); opacity: 0; }
  60%  { opacity: 1; }
  100% { transform: translateY(0); opacity: 1; }
}

.ghost-card {
  border-radius: 14px;
  overflow: hidden;
  z-index: 80;
  pointer-events: none;
}

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 100; }
.confetti-piece {
  position: absolute; width: 8px; height: 12px;
  top: -20px; opacity: 0;
  animation: fall 2s ease-out forwards;
}
@keyframes fall {
  0% { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(120vh) rotate(720deg); opacity: 0; }
}

/* ========== TABLET (≥600px) ========== */
@media (min-width: 600px) {
  #app { padding: calc(16px + var(--safe-top)) 20px calc(16px + var(--safe-bottom)); }
  .hero { padding: 40px 16px; }
  .hero h1.brush-title { font-size: 34px; }
  .subtitle { font-size: 15px; }
  .views { font-size: 20px; }
  .review-item { grid-template-columns: 1fr 1fr; }
  .result-stats { grid-template-columns: repeat(3, 1fr); }
  .result-stats > div { flex-direction: column; gap: 4px; }
}

/* ========== DESKTOP (≥1024px) ========== */
@media (min-width: 1024px) {
  #app { max-width: 1000px; }
  .hero h1.brush-title { font-size: 44px; }
  .cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }
  .views { font-size: 24px; }
  .result-actions { flex-direction: row; }
}
