:root {
  --night: #0d0820;
  --ink: #f7eef3;
  --muted: #c9b6c6;
  --sakura: #ffb7cf;
  --sakura-deep: #ff7aa8;
  --torii: #e0463a;
  --gold: #f3d9a4;
  --glass: rgba(28, 16, 44, 0.55);
  --line: rgba(255, 183, 207, 0.22);
  --ok: #7fdcb0;
  --bad: #ff8a8a;
  --serif: "Noto Serif JP", serif;
  --sans: "Noto Sans KR", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: linear-gradient(180deg, #0b0719 0%, #1b0f30 45%, #2b1438 75%, #3b1a3e 100%) fixed;
  background-color: var(--night);
  overflow-x: hidden;
  line-height: 1.7;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }

#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 0; display: block; }
.vignette {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(8, 4, 18, 0.75) 100%);
}
main, .footer, .nav { position: relative; z-index: 2; }

/* Loader */
#loader {
  position: fixed; inset: 0; z-index: 100; display: grid; place-content: center; justify-items: center; gap: 12px;
  background: var(--night); color: var(--sakura); transition: opacity .8s ease, visibility .8s;
}
#loader.done { opacity: 0; visibility: hidden; }
.loader-mark { font-family: var(--serif); font-size: 64px; font-weight: 900; animation: pulse 1.4s ease-in-out infinite; }
#loader p { font-family: var(--serif); letter-spacing: .3em; color: var(--muted); font-size: 14px; }
@keyframes pulse { 50% { transform: scale(1.15) rotate(8deg); opacity: .6; } }

/* Nav */
.nav {
  position: fixed; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center;
  padding: 18px clamp(16px, 4vw, 48px);
  background: linear-gradient(180deg, rgba(11, 7, 25, .7), transparent);
}
.logo { font-family: var(--serif); font-weight: 900; font-size: 20px; letter-spacing: .04em; }
.logo-3 { color: var(--torii); }
.nav-links { display: flex; gap: clamp(12px, 2.5vw, 28px); font-size: 14px; color: var(--muted); }
.nav-links a { position: relative; transition: color .2s; }
.nav-links a::after { content: ""; position: absolute; left: 0; bottom: -4px; height: 1px; width: 100%; background: var(--sakura); transform: scaleX(0); transform-origin: left; transition: transform .3s; }
.nav-links a:hover { color: var(--ink); }
.nav-links a:hover::after { transform: scaleX(1); }

section { min-height: 100vh; padding: 120px clamp(16px, 5vw, 64px); display: flex; flex-direction: column; justify-content: center; align-items: center; }

.kicker { font-family: var(--serif); color: var(--sakura); letter-spacing: .18em; font-size: 13px; margin-bottom: 14px; }
h2 { font-family: var(--serif); font-weight: 900; font-size: clamp(28px, 4.5vw, 46px); line-height: 1.35; margin-bottom: 18px; }

/* Hero */
.hero { text-align: center; position: relative; }
.eyebrow { letter-spacing: .5em; font-size: 12px; color: var(--gold); margin-bottom: 18px; }
.hero-title {
  font-family: var(--serif); font-weight: 900; font-size: clamp(64px, 15vw, 190px); line-height: 1;
  display: flex; justify-content: center; perspective: 800px;
  text-shadow: 0 0 40px rgba(255, 122, 168, .45), 0 6px 30px rgba(0, 0, 0, .5);
}
.hero-title .ch { display: inline-block; transform-origin: 50% 100%; }
.hero-title .ch:nth-child(1) { color: var(--torii); }
.hero-title .ch:nth-child(2) { color: var(--sakura); }
.hero-title .gap { width: .25em; }
.hero-sub { margin-top: 24px; color: #eadbe6; font-size: clamp(15px, 2vw, 18px); text-shadow: 0 2px 12px rgba(8, 4, 18, .9), 0 0 2px rgba(8, 4, 18, .9); }
.hero-cta { margin-top: 36px; display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.scroll-hint { position: absolute; bottom: 36px; left: 50%; transform: translateX(-50%); display: grid; justify-items: center; gap: 10px; font-size: 12px; color: var(--muted); letter-spacing: .1em; }
.scroll-hint i { width: 1px; height: 46px; background: linear-gradient(var(--sakura), transparent); animation: drip 1.8s ease-in-out infinite; transform-origin: top; }
@keyframes drip { 0% { transform: scaleY(0); } 50% { transform: scaleY(1); } 100% { transform: scaleY(1); opacity: 0; } }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 14px 26px; border-radius: 999px; font-weight: 700; font-size: 15px; transition: background .25s, box-shadow .25s, border-color .25s; will-change: transform; }
.btn-primary { background: linear-gradient(135deg, var(--sakura-deep), var(--torii)); color: #fff; box-shadow: 0 10px 30px rgba(224, 70, 58, .35); }
.btn-primary:hover { box-shadow: 0 14px 40px rgba(255, 122, 168, .55); }
.btn-ghost { border: 1px solid var(--line); background: rgba(255, 255, 255, .04); backdrop-filter: blur(6px); }
.btn-ghost:hover { border-color: var(--sakura); }

/* Glass */
.glass {
  background: var(--glass); border: 1px solid var(--line); border-radius: 28px;
  backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .06);
}

/* Intro */
.intro-box { max-width: 760px; padding: clamp(28px, 5vw, 56px); }
.intro-box > p:not(.kicker) { color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 32px; }
.stats div { text-align: center; padding: 18px 8px; border-radius: 18px; background: rgba(255, 255, 255, .04); border: 1px solid var(--line); }
.stats b { display: block; font-family: var(--serif); font-size: clamp(30px, 5vw, 44px); color: var(--sakura); line-height: 1.2; }
.stats span { font-size: 13px; color: var(--muted); }

/* Cards */
.cards-section { justify-content: flex-start; }
.section-head { text-align: center; max-width: 720px; margin-bottom: 40px; }
.section-head > p:not(.kicker) { color: var(--muted); }
.tabs { display: inline-flex; margin-top: 24px; padding: 5px; border-radius: 999px; background: rgba(255, 255, 255, .05); border: 1px solid var(--line); }
.tab { padding: 9px 22px; border-radius: 999px; font-family: var(--serif); font-weight: 700; color: var(--muted); transition: background .3s, color .3s; }
.tab.active { background: var(--sakura); color: #3a1028; }

.card-grid { width: 100%; max-width: 720px; display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
.section-head h2, .section-head p { text-shadow: 0 2px 14px rgba(8, 4, 18, .95), 0 0 3px rgba(8, 4, 18, .9); }
.section-head > p:not(.kicker) { color: #e2d2df; }
.cell { perspective: 900px; }
.card { aspect-ratio: 3 / 4; cursor: pointer; transform: rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)); transition: transform .2s ease-out; transform-style: preserve-3d; }
.card.empty { visibility: hidden; pointer-events: none; }
.card-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .75s cubic-bezier(.2, .8, .2, 1); }
.card.flipped .card-inner { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; border-radius: 18px; backface-visibility: hidden; -webkit-backface-visibility: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; border: 1px solid var(--line); overflow: hidden; }
.front { background: linear-gradient(160deg, rgba(58, 34, 78, .92), rgba(36, 20, 52, .92)); }
.front::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at var(--mx, 50%) var(--my, 30%), rgba(255, 183, 207, .28), transparent 60%); opacity: 0; transition: opacity .3s; }
.card:hover .front::before { opacity: 1; }
.front .kana { font-family: var(--serif); font-size: clamp(44px, 6vw, 58px); font-weight: 700; position: relative; }
.front .roma-hint { position: absolute; bottom: 10px; font-size: 11px; color: var(--muted); letter-spacing: .1em; opacity: .7; }
.back { transform: rotateY(180deg); background: linear-gradient(160deg, #ff8fb4, #d8362f); color: #fff; gap: 2px; padding: 10px; text-align: center; }
.back .roma { font-size: 26px; font-weight: 700; letter-spacing: .05em; line-height: 1.2; }
.back .ex { font-family: var(--serif); font-size: 15px; font-weight: 700; margin-top: 6px; }
.back .ex-ko { font-size: 12px; opacity: .9; }
.back .say { margin-top: 8px; width: 34px; height: 34px; border-radius: 50%; background: rgba(255, 255, 255, .22); font-size: 15px; display: grid; place-items: center; }
.back .say:hover { background: rgba(255, 255, 255, .38); }

/* Word */
.word-box { max-width: 680px; width: 100%; padding: clamp(28px, 5vw, 56px); text-align: center; }
.word-reading { font-family: var(--serif); color: var(--gold); font-size: 20px; letter-spacing: .3em; min-height: 1.6em; }
.word-kanji { font-family: var(--serif); font-weight: 900; font-size: clamp(80px, 16vw, 150px); line-height: 1.15; display: flex; justify-content: center; perspective: 600px; text-shadow: 0 0 50px rgba(255, 122, 168, .5); }
.word-kanji span { display: inline-block; }
.word-meaning { font-size: 22px; font-weight: 700; margin-top: 4px; }
.word-example { margin: 24px auto 30px; padding: 18px 22px; border-radius: 18px; background: rgba(255, 255, 255, .05); border-left: 3px solid var(--torii); text-align: left; max-width: 480px; }
.word-example .ja { font-family: var(--serif); font-size: 18px; }
.word-example .ko { color: var(--muted); font-size: 14px; }
.word-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* Quiz */
.quiz-box { max-width: 620px; width: 100%; padding: clamp(24px, 5vw, 48px); text-align: center; }
.quiz-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.quiz-top .kicker { margin: 0; }
.quiz-meta { display: flex; gap: 16px; font-size: 14px; color: var(--muted); }
.quiz-meta b { color: var(--sakura); font-size: 16px; }
.quiz-bar { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .08); margin: 16px 0 28px; overflow: hidden; }
.quiz-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--sakura), var(--torii)); transition: width .5s ease; }
.quiz-q-label { color: var(--muted); font-size: 14px; }
.quiz-kana { font-family: var(--serif); font-size: clamp(96px, 20vw, 140px); font-weight: 900; line-height: 1.25; margin: 6px 0 22px; text-shadow: 0 0 40px rgba(255, 183, 207, .4); }
.quiz-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.opt { padding: 16px; border-radius: 16px; border: 1px solid var(--line); background: rgba(255, 255, 255, .05); font-size: 20px; font-weight: 700; letter-spacing: .06em; transition: background .2s, border-color .2s, transform .2s; }
.opt:hover:not(:disabled) { border-color: var(--sakura); background: rgba(255, 183, 207, .12); transform: translateY(-2px); }
.opt.ok { background: rgba(127, 220, 176, .25); border-color: var(--ok); }
.opt.bad { background: rgba(255, 138, 138, .22); border-color: var(--bad); }
.opt:disabled { cursor: default; }
.quiz-end { padding: 10px 0; }
.quiz-final { font-family: var(--serif); font-weight: 900; font-size: clamp(64px, 14vw, 110px); color: var(--sakura); line-height: 1.2; }
.quiz-end p { color: var(--muted); margin: 8px 0 24px; font-size: 17px; }

/* Study */
.study-box { max-width: 760px; width: 100%; padding: clamp(28px, 5vw, 56px); }
.study-box > p:not(.kicker) { color: var(--muted); }
.steps { list-style: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 28px 0 32px; }
.steps li { padding: 18px; border-radius: 18px; background: rgba(255, 255, 255, .04); border: 1px solid var(--line); display: grid; gap: 4px; }
.steps b { font-family: var(--serif); color: var(--torii); font-size: 22px; }
.steps span { font-size: 14px; }

.footer { text-align: center; padding: 60px 16px 48px; color: var(--muted); font-size: 13px; }
.footer-ja { font-family: var(--serif); font-size: 22px; color: var(--ink); margin-bottom: 6px; }

/* Burst petals */
.burst { position: fixed; width: 12px; height: 14px; z-index: 50; pointer-events: none; background: var(--sakura); border-radius: 80% 0 80% 0; }

@media (max-width: 640px) {
  .nav-links { display: none; }
  section { padding: 96px 16px; }
  .card-grid { gap: 7px; }
  .front .kana { font-size: 36px; }
  .front .roma-hint { display: none; }
  .back { padding: 4px; line-height: 1.25; gap: 0; }
  .back .roma { font-size: 17px; }
  .back .ex { font-size: 11px; margin-top: 3px; word-break: keep-all; }
  .back .ex-ko { font-size: 10px; }
  .back .say { width: 24px; height: 24px; font-size: 11px; margin-top: 4px; }
  .face { border-radius: 12px; }
  .steps { grid-template-columns: 1fr; }
  .stats span { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  .scroll-hint i, .loader-mark { animation: none; }
  .card-inner { transition-duration: .01s; }
}
