/* ===========================================================================
   components.css — header banner, nav, unit selector, quiz engine, toasts,
   audio player, KanjiVG, level-up modal.
   =========================================================================== */

.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 var(--gutter); }

/* ============================================================ header */
#header { position: relative; }

.banner {
  position: relative;
  width: 100%;
  height: clamp(150px, 26vw, 200px);
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: radial-gradient(90% 140% at 72% 20%, rgba(255, 43, 43, .12), transparent 62%);
}
.wave-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.wave use { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.wave-a use { stroke: var(--cyan); stroke-width: 1.7; opacity: .95; }
.wave-b use { stroke: var(--blue); stroke-width: 1.5; opacity: .8; }
.wave-c use { stroke: var(--magenta); stroke-width: 1.2; opacity: .55; }

@keyframes drift { from { transform: translateX(0); } to { transform: translateX(-1200px); } }
.wave-a { animation: drift 28s linear infinite; }
.wave-b { animation: drift 36s linear infinite; }
.wave-c { animation: drift 44s linear infinite; }
@media (prefers-reduced-motion: reduce) { .wave-a, .wave-b, .wave-c { animation: none; } }

.sun-disc { filter: drop-shadow(0 0 22px rgba(255, 43, 43, .75)); opacity: .92; }
.sun-glow { opacity: .9; }

.banner-text {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 0 var(--gutter) clamp(10px, 2.4vw, 20px);
  max-width: var(--maxw);
  margin: 0 auto;
  pointer-events: none;
}
.banner-text h1 {
  margin: 0;
  font-size: clamp(2rem, 7.5vw, 3.2rem);
  letter-spacing: .04em;
  text-shadow: 0 0 20px rgba(0, 240, 255, .35), 0 2px 18px rgba(0, 0, 0, .9);
}
.banner-text h1 .lat {
  font-family: var(--lat);
  font-weight: 300;
  letter-spacing: .3em;
  font-size: .5em;
  vertical-align: .22em;
  color: var(--cyan);
}
.banner-text .sub {
  margin: .15rem 0 0;
  font-size: clamp(.74rem, 2.6vw, .9rem);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--dim);
  text-shadow: 0 2px 10px rgba(0, 0, 0, .9);
}

.chips {
  display: flex;
  gap: .4rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding: .5rem var(--gutter);
  max-width: var(--maxw);
  margin: 0 auto;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: .3em;
  flex: 0 0 auto;
  font-size: .76rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .28em .7em;
  background: var(--card);
  white-space: nowrap;
}
.chip b { font-weight: 600; font-size: .92rem; }
.chip .chip-k { color: var(--dim); font-size: .66rem; letter-spacing: .12em; }
.chip.hot { border-color: rgba(255, 43, 43, .5); box-shadow: 0 0 14px rgba(255, 43, 43, .18); }
.chip-lvl .chip-bar {
  display: inline-block; width: 42px; height: 4px; border-radius: 999px;
  background: rgba(255, 255, 255, .1); overflow: hidden;
}
.chip-lvl .chip-bar > i {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
  transition: width .4s ease;
}

/* ============================================================= nav */
#nav {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(5, 5, 7, .92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.nav-inner {
  display: flex;
  gap: .15rem;
  overflow-x: auto;
  scrollbar-width: none;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 calc(var(--gutter) - 6px);
}
.nav-inner::-webkit-scrollbar { display: none; }
#nav a {
  flex: 0 0 auto;
  padding: .72rem .8rem;
  font-size: .85rem;
  color: var(--dim);
  border-bottom: 2px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  transition: color .15s ease, border-color .15s ease, text-shadow .15s ease;
}
#nav a:hover { color: var(--ink); text-decoration: none; }
#nav a.on {
  color: var(--cyan);
  border-bottom-color: var(--cyan);
  text-shadow: 0 0 14px rgba(0, 240, 255, .6);
}

/* ==================================================== unit selector */
#units { max-width: var(--maxw); margin: 0 auto; padding: .6rem var(--gutter) 0; }
.units {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.units-head {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .8rem;
}
.units-sum { flex: 1 1 auto; font-size: .85rem; color: var(--ink); }
.units-body { display: none; padding: 0 .8rem .8rem; border-top: 1px solid var(--line); }
.units.open .units-body { display: block; animation: riseIn .22s ease; }

.ubook { margin-top: .7rem; }
.ubook-h {
  font-size: .68rem; letter-spacing: .18em; text-transform: uppercase;
  color: var(--dim); margin-bottom: .4rem;
}
.ugrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: .35rem; }
.ucell {
  display: flex; flex-direction: column; align-items: center; gap: .18rem;
  border: 1px solid var(--line); border-radius: 9px;
  padding: .32rem .2rem .28rem;
  cursor: pointer; user-select: none;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.ucell input { position: absolute; opacity: 0; width: 0; height: 0; }
.ucell .ul { font-size: .82rem; font-weight: 600; color: var(--dim); }
.ucell:hover:not(.off) { border-color: rgba(0, 240, 255, .55); box-shadow: var(--glow); }
.ucell.on { background: rgba(0, 240, 255, .1); border-color: var(--cyan); }
.ucell.on .ul { color: var(--cyan); }
.ucell.off { opacity: .32; cursor: not-allowed; }
.umast { display: block; width: 100%; height: 3px; border-radius: 999px; background: rgba(255, 255, 255, .09); overflow: hidden; }
.umast > i { display: block; height: 100%; background: linear-gradient(90deg, var(--cyan), var(--magenta)); }

.upresets { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-top: .9rem; }
.upreset-row { display: inline-flex; gap: .25rem; align-items: center; }
.uinput { width: 3.6rem; padding: .28em .4em; font-size: .8rem; }

/* ================================================================ view */
#view { max-width: var(--maxw); margin: 0 auto; padding: 1rem var(--gutter) 5rem; }
#view > section + section { margin-top: 1rem; }

.grid { display: grid; gap: .8rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* ========================================================= quiz engine */
.quiz, .flash, .reveal { animation: riseIn .22s ease; }
.quiz-head { display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; }
.quiz-head .eyebrow { margin: 0; flex: 1 1 auto; }
.meter { font-size: .82rem; color: var(--dim); }
.meter b { color: var(--ink); }

.combo-chip {
  display: none;
  font-size: .82rem;
  font-weight: 600;
  color: var(--sun);
  border: 1px solid rgba(255, 43, 43, .45);
  border-radius: 999px;
  padding: .12em .6em;
  background: rgba(255, 43, 43, .1);
}
.combo-chip.show { display: inline-block; }
.combo-chip.hot { font-size: .95rem; box-shadow: 0 0 20px rgba(255, 43, 43, .35); }
.combo-chip .cx { color: var(--cyan); }

.qbox {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(14px, 3.2vw, 22px);
}
.qnum { font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--dim); margin-bottom: .5rem; }
.qtext { margin: .2rem 0 .5rem; word-break: normal; overflow-wrap: anywhere; }
.qsub { color: var(--dim); font-family: var(--jp); margin-bottom: .6rem; }
.qaudio { margin: .3rem 0 .8rem; }

.opts { display: grid; gap: .5rem; margin: .9rem 0; }
.opt {
  display: flex; align-items: flex-start; gap: .65rem;
  text-align: left;
  width: 100%;
  font-family: var(--jp);
  font-size: 1.02rem;
  color: var(--ink);
  background: rgba(255, 255, 255, .03);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .7rem .85rem;
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease, transform .1s ease;
}
.opt:hover:not(:disabled) { border-color: rgba(0, 240, 255, .6); box-shadow: var(--glow); }
.opt:active:not(:disabled) { transform: translateY(1px); }
.opt:disabled { cursor: default; opacity: .75; }
.opt .k {
  flex: 0 0 auto;
  font-family: var(--lat);
  font-size: .7rem;
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 6px;
  width: 1.5em; height: 1.5em;
  display: grid; place-items: center;
  margin-top: .2em;
}
.opt .tx { flex: 1 1 auto; }
.opt.right { border-color: var(--cyan); background: rgba(0, 240, 255, .11); opacity: 1; box-shadow: var(--glow); }
.opt.right .k { color: var(--cyan); border-color: var(--cyan); }
.opt.wrong { border-color: var(--magenta); background: rgba(255, 47, 208, .1); animation: shake .38s ease; }
.opt.wrong .k { color: var(--magenta); border-color: var(--magenta); }

.verdict {
  border-left: 2px solid var(--cyan);
  padding: .5rem .8rem;
  margin: .6rem 0 1rem;
  font-size: .9rem;
  background: rgba(0, 240, 255, .05);
  border-radius: 0 8px 8px 0;
  animation: riseIn .2s ease;
}
.verdict.no { border-left-color: var(--magenta); background: rgba(255, 47, 208, .05); }
.verdict .lbl { display: block; font-size: .7rem; letter-spacing: .14em; text-transform: uppercase; color: var(--cyan); margin-bottom: .15rem; }
.verdict.no .lbl { color: var(--magenta); }

.quiz-foot { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }
.answer-box {
  font-family: var(--jp);
  font-size: 1.4rem;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: .7rem .9rem;
  margin: .6rem 0 1rem;
  background: rgba(0, 240, 255, .05);
}

.finish { text-align: center; padding: 1rem 0 .4rem; animation: riseIn .25s ease; }
.finish .score { font-family: var(--jp-serif); font-size: clamp(3rem, 14vw, 4.5rem); line-height: 1; }
.finish .score.good { color: var(--cyan); text-shadow: 0 0 30px rgba(0, 240, 255, .5); }
.finish .score.ok { color: var(--ink); }
.finish .score.low { color: var(--magenta); }
.finish .score-sub { color: var(--dim); margin-bottom: 1rem; }
.fstats { display: flex; gap: 1.4rem; justify-content: center; flex-wrap: wrap; margin-bottom: 1.2rem; }
.fstat { display: flex; flex-direction: column; }
.fstat b { font-size: 1.2rem; }
.fstat span { font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; color: var(--dim); }
.finish-btns { display: flex; gap: .5rem; justify-content: center; flex-wrap: wrap; }

/* ========================================================= flashcards */
.card-flip { perspective: 1200px; cursor: pointer; outline: none; }
.cf-inner {
  position: relative;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.4, .1, .2, 1);
  min-height: clamp(180px, 40vw, 260px);
}
.card-flip.flipped .cf-inner { transform: rotateY(180deg); }
.cf-face {
  position: absolute; inset: 0;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .5rem;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  background: rgba(255, 255, 255, .03);
}
.cf-back { transform: rotateY(180deg); background: rgba(0, 240, 255, .06); border-color: rgba(0, 240, 255, .4); }
.cf-body { font-family: var(--jp); overflow-wrap: anywhere; }
.cf-back .cf-body { font-size: 1.25rem; }
.cf-hint { position: absolute; bottom: .7rem; left: 0; right: 0; }
.card-flip:focus-visible .cf-face { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* ======================================================= audio player */
.audio-btn {
  display: inline-flex; align-items: center; gap: .35em;
  font-family: var(--lat); font-size: .78rem;
  color: var(--cyan);
  background: rgba(0, 240, 255, .07);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .25em .7em;
  cursor: pointer;
  transition: box-shadow .15s ease, border-color .15s ease;
}
.audio-btn:hover:not(:disabled) { border-color: var(--cyan); box-shadow: var(--glow); }
.audio-btn.dead { color: var(--dim); opacity: .5; cursor: not-allowed; }
.audio-btn .ai { font-size: .9em; }

.aplayer {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .35rem .6rem;
  background: var(--card);
}
.aplayer.dead { opacity: .5; }
.ap-btn {
  background: none; border: 1px solid var(--line); color: var(--cyan);
  border-radius: 50%; width: 2rem; height: 2rem; cursor: pointer;
  display: grid; place-items: center; font-size: .9rem;
}
.ap-btn:hover:not(:disabled) { box-shadow: var(--glow); border-color: var(--cyan); }
.ap-btn.ap-rate { width: auto; border-radius: 999px; padding: 0 .6em; font-size: .75rem; }
.ap-meter { font-size: .78rem; color: var(--ink); display: flex; align-items: center; gap: .45rem; }
.ap-dots { display: flex; gap: 3px; }
.ap-dot { width: 6px; height: 6px; border-radius: 50%; background: rgba(255, 255, 255, .16); }
.ap-dot.on { background: var(--cyan); box-shadow: 0 0 8px rgba(0, 240, 255, .8); }

/* ============================================================ KanjiVG */
.kvg { display: inline-flex; flex-direction: column; align-items: center; gap: .5rem; }
.kvg-stage { position: relative; width: var(--kvg-size, 160px); height: var(--kvg-size, 160px); }
.kvg-cell { position: absolute; inset: 0; }
.kvg-art { position: absolute; inset: 0; display: grid; place-items: center; }
.kvg-svg { display: block; }
.kvg-glyph { font-family: var(--jp-serif); color: var(--ink); line-height: 1; opacity: .92; }
.kvg-tools { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; justify-content: center; }

/* genkouyoushi single cell — also used by the writing sheets (see print.css) */
.genko-cell {
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 4px;
  background-image:
    linear-gradient(to right, transparent calc(50% - .5px), rgba(255, 255, 255, .13) calc(50% - .5px), rgba(255, 255, 255, .13) calc(50% + .5px), transparent calc(50% + .5px)),
    linear-gradient(to bottom, transparent calc(50% - .5px), rgba(255, 255, 255, .13) calc(50% - .5px), rgba(255, 255, 255, .13) calc(50% + .5px), transparent calc(50% + .5px));
}

.genkouyoushi {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  page-break-inside: avoid;
  break-inside: avoid;
}
.genkouyoushi .cell {
  aspect-ratio: 1 / 1;
  display: grid; place-items: center;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 4px;
  background-image:
    linear-gradient(to right, transparent calc(50% - .5px), rgba(255, 255, 255, .13) calc(50% - .5px), rgba(255, 255, 255, .13) calc(50% + .5px), transparent calc(50% + .5px)),
    linear-gradient(to bottom, transparent calc(50% - .5px), rgba(255, 255, 255, .13) calc(50% - .5px), rgba(255, 255, 255, .13) calc(50% + .5px), transparent calc(50% + .5px));
  font-family: var(--jp-serif);
  font-size: clamp(1.6rem, 7vw, 2.6rem);
}
.genkouyoushi .cell.ghost { color: rgba(238, 242, 246, .25); }

/* ============================================================== toasts */
.toast-host {
  position: fixed;
  right: 12px; bottom: 12px;
  z-index: 200;
  display: flex; flex-direction: column; gap: .4rem;
  align-items: flex-end;
  pointer-events: none;
  max-width: min(360px, calc(100vw - 24px));
}
.toast {
  pointer-events: auto;
  display: flex; gap: .5rem; align-items: flex-start;
  font-size: .84rem;
  background: rgba(10, 10, 14, .96);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .6rem .8rem;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .6);
  opacity: 0;
  transform: translateY(12px) scale(.96);
  transition: opacity .28s ease, transform .28s cubic-bezier(.2, .9, .3, 1.2);
  cursor: pointer;
}
.toast.in { opacity: 1; transform: none; }
.toast.out { opacity: 0; transform: translateY(8px) scale(.97); }
.toast-success { border-color: rgba(0, 240, 255, .5); box-shadow: 0 0 22px rgba(0, 240, 255, .16), 0 8px 30px rgba(0, 0, 0, .6); }
.toast-badge { border-color: rgba(255, 43, 43, .5); box-shadow: 0 0 22px rgba(255, 43, 43, .2), 0 8px 30px rgba(0, 0, 0, .6); }
.toast .t-emoji { font-size: 1.4rem; line-height: 1.1; }

.confetti-canvas { position: fixed; inset: 0; z-index: 300; pointer-events: none; }

/* =========================================================== level-up */
.levelup-overlay {
  position: fixed; inset: 0; z-index: 250;
  display: grid; place-items: center;
  background: rgba(3, 3, 6, .82);
  backdrop-filter: blur(6px);
  animation: riseIn .2s ease;
}
.levelup-overlay.out { opacity: 0; transition: opacity .3s ease; }
.levelup-card {
  position: relative;
  text-align: center;
  padding: clamp(24px, 6vw, 44px) clamp(28px, 8vw, 60px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(10, 10, 16, .92);
  box-shadow: var(--glow-strong);
  overflow: hidden;
  max-width: min(420px, calc(100vw - 32px));
}
.levelup-sun {
  position: absolute; top: -90px; left: 50%; transform: translateX(-50%);
  width: 220px; height: 220px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 43, 43, .5), transparent 62%);
  pointer-events: none;
}
.levelup-kicker { position: relative; font-family: var(--jp-serif); color: var(--sun); letter-spacing: .3em; font-size: .8rem; }
.levelup-n {
  position: relative;
  font-family: var(--jp-serif);
  font-size: clamp(2.4rem, 11vw, 3.6rem);
  color: var(--cyan);
  text-shadow: 0 0 34px rgba(0, 240, 255, .6);
  margin: .3rem 0;
}
.levelup-sub { position: relative; color: var(--dim); margin-bottom: 1rem; font-family: var(--jp); }
.levelup-ok { position: relative; }

/* ============================================================== phone */
@media (max-width: 420px) {
  .fstats { gap: 1rem; }
  .opt { font-size: .98rem; padding: .62rem .7rem; }
  .ugrid { grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); }
  .toast-host { left: 12px; right: 12px; max-width: none; align-items: stretch; }
}
