/* ============================================================
   Kanji Quizlet — 藍 (indigo) + 朱 (vermillion) on washi paper
   ============================================================ */

:root {
  --paper:      #f7f4ee;
  --paper-2:    #fffdfa;
  --surface:    #ffffff;
  --ink:        #1b1d24;
  --ink-2:      #4a4f5e;
  --ink-3:      #838a9c;
  --line:       #e4dfd5;

  --indigo:     #2e3f72;
  --indigo-2:   #485d9e;
  --indigo-soft:#eaeef8;
  --vermillion: #c2513c;
  --vermillion-soft: #fbeae6;
  --green:      #2f7a5a;
  --green-soft: #e6f3ec;
  --gold:       #b8863b;

  --r-sm: 8px;
  --r:    14px;
  --r-lg: 22px;

  --shadow-sm: 0 1px 2px rgba(27,29,36,.05), 0 1px 3px rgba(27,29,36,.04);
  --shadow:    0 2px 4px rgba(27,29,36,.04), 0 8px 24px rgba(27,29,36,.07);
  --shadow-lg: 0 8px 20px rgba(27,29,36,.08), 0 24px 56px rgba(27,29,36,.12);

  --sans:  'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Noto Serif JP', ui-serif, Georgia, 'Yu Mincho', serif;

  --ease: cubic-bezier(.22,.68,.36,1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:   #14161c;
    --paper-2: #191c24;
    --surface: #1d212a;
    --ink:     #f0eee9;
    --ink-2:   #b7bdcb;
    --ink-3:   #7e8598;
    --line:    #2b303c;

    --indigo:      #8aa2e0;
    --indigo-2:    #a5b8ea;
    --indigo-soft: #222a3f;
    --vermillion:  #e8836c;
    --vermillion-soft: #362320;
    --green:       #6cc79b;
    --green-soft:  #1b2f27;
    --gold:        #d6a860;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
    --shadow:    0 2px 4px rgba(0,0,0,.25), 0 8px 24px rgba(0,0,0,.35);
    --shadow-lg: 0 8px 20px rgba(0,0,0,.35), 0 24px 56px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Stop iOS inflating text when a phone is turned to landscape. */
  -webkit-text-size-adjust: 100%;
}

/* No rubber-banding mid-review — a bounce reads as a broken swipe. */
body.is-studying {
  overscroll-behavior: none;
}

/* Subtle paper grain, kept far behind everything. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: .5;
  background:
    radial-gradient(ellipse 80% 55% at 12% -8%, var(--indigo-soft), transparent 60%),
    radial-gradient(ellipse 65% 45% at 92% 4%, var(--vermillion-soft), transparent 62%);
}

h1, h2, h3 { line-height: 1.2; letter-spacing: -.018em; margin: 0; }

button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

button {
  /* Kills the 300ms double-tap-zoom delay and the grey flash on tap. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
/* Labels on controls shouldn't select when a tap is held or a swipe starts. */
.btn, .tab, .chip, .choice, .iconbtn, .flash__inner, .botnav {
  -webkit-user-select: none;
  user-select: none;
}

::selection { background: var(--indigo); color: #fff; }

:focus-visible {
  outline: 2.5px solid var(--indigo-2);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ------------------------------ buttons ------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .72rem 1.25rem;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-weight: 600;
  font-size: .95rem;
  letter-spacing: -.01em;
  cursor: pointer;
  transition: transform .14s var(--ease), background .18s, box-shadow .18s, border-color .18s;
  background: none;
}
.btn:active { transform: translateY(1px) scale(.99); }

.btn--primary {
  background: var(--indigo);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn--primary:hover { background: var(--indigo-2); box-shadow: var(--shadow); }
@media (prefers-color-scheme: dark) { .btn--primary { color: #12141a; } }

.btn--ghost {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink-2);
}
.btn--ghost:hover { border-color: var(--ink-3); color: var(--ink); }

.btn--block { width: 100%; }
.btn--lg { min-height: 54px; font-size: 1.02rem; }

.btn--again {
  flex: 1;
  background: var(--vermillion-soft);
  color: var(--vermillion);
  border-color: transparent;
}
.btn--again:hover { background: var(--vermillion); color: #fff; }

.btn--got {
  flex: 1;
  background: var(--green-soft);
  color: var(--green);
}
.btn--got:hover { background: var(--green); color: #fff; }

.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--indigo);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1.5px;
}
.link:hover { color: var(--vermillion); }

.iconbtn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  font-size: 1.05rem;
  transition: background .16s, color .16s;
}
.iconbtn:hover { background: var(--line); color: var(--ink); }

/* ------------------------------ cards -------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 1.6rem;
  box-shadow: var(--shadow-sm);
}
.card__title { font-size: 1.1rem; font-weight: 700; }
.card__sub {
  margin: .4rem 0 1.1rem;
  color: var(--ink-3);
  font-size: .88rem;
  line-height: 1.5;
  max-width: 62ch;
}

.alert {
  margin: 0;
  padding: .7rem .9rem;
  border-radius: var(--r-sm);
  font-size: .88rem;
  font-weight: 500;
}
.alert--error { background: var(--vermillion-soft); color: var(--vermillion); }

/* ============================== AUTH ================================= */

.auth {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1.05fr .95fr;
}

.auth__art {
  position: relative;
  display: grid;
  place-content: center;
  gap: 1.5rem;
  padding: 3rem;
  overflow: hidden;
  background:
    radial-gradient(circle at 30% 25%, rgba(255,255,255,.14), transparent 55%),
    linear-gradient(150deg, var(--indigo) 0%, #1d2a50 55%, #16203d 100%);
  color: #fff;
}
.auth__art::after {
  content: '';
  position: absolute;
  width: 58vmin; height: 58vmin;
  right: -16vmin; bottom: -22vmin;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(194,81,60,.5), transparent 68%);
  filter: blur(8px);
}
.auth__glyph {
  position: relative;
  font-family: var(--serif);
  font-size: clamp(9rem, 22vmin, 17rem);
  font-weight: 500;
  line-height: .9;
  text-align: center;
  color: rgba(255,255,255,.97);
  text-shadow: 0 8px 40px rgba(0,0,0,.3);
}
.auth__tag {
  position: relative;
  margin: 0;
  font-size: 1.12rem;
  line-height: 1.6;
  color: rgba(255,255,255,.85);
  text-align: center;
  max-width: 24ch;
  justify-self: center;
}

.auth__panel {
  display: grid;
  place-items: center;
  padding: 2rem 1.5rem;
  background: var(--paper);
}
.auth__card {
  width: min(400px, 100%);
  padding: 2.2rem;
  box-shadow: var(--shadow);
  animation: rise .5s var(--ease) both;
}
.auth__title { font-size: 1.7rem; font-weight: 700; }
.auth__sub { margin: .5rem 0 1.7rem; color: var(--ink-3); font-size: .93rem; }
.auth__switch { margin: 1.1rem 0 0; text-align: center; font-size: .9rem; color: var(--ink-3); }
.auth__fine { margin: .7rem 0 0; text-align: center; font-size: .78rem; color: var(--ink-3); }

.auth__or {
  display: flex;
  align-items: center;
  gap: .9rem;
  margin: 1.4rem 0 1.1rem;
  color: var(--ink-3);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .1em;
}
.auth__or::before, .auth__or::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

.field { display: block; margin-bottom: 1.05rem; }
.field__label {
  display: block;
  margin-bottom: .4rem;
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink-2);
}
.field input {
  width: 100%;
  padding: .78rem .95rem;
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--paper-2);
  transition: border-color .16s, box-shadow .16s;
}
.field input:focus {
  outline: none;
  border-color: var(--indigo-2);
  box-shadow: 0 0 0 3.5px var(--indigo-soft);
}
.field input::placeholder { color: var(--ink-3); opacity: .65; }
.field__hint { display: block; margin-top: .4rem; color: var(--ink-3); font-size: .78rem; }

@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; }
  .auth__art { padding: 2.5rem 1.5rem 2rem; }
  .auth__glyph { font-size: 7rem; }
  .auth__tag { font-size: 1rem; }
}

/* ============================== SHELL ================================ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .7rem clamp(1rem, 4vw, 2.5rem);
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  text-decoration: none;
  color: var(--ink);
  font-weight: 700;
  letter-spacing: -.02em;
}
.brand__glyph {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--indigo);
  color: #fff;
  font-family: var(--serif);
  font-size: 1.15rem;
  line-height: 1;
}
@media (prefers-color-scheme: dark) { .brand__glyph { color: #12141a; } }

.tabs { display: flex; gap: .2rem; margin-left: auto; }
.tab {
  padding: .5rem .95rem;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--ink-3);
  font-weight: 600;
  font-size: .92rem;
  cursor: pointer;
  transition: background .16s, color .16s;
}
.tab:hover { color: var(--ink); background: var(--line); }
.tab[aria-current='true'] { background: var(--indigo); color: #fff; }
@media (prefers-color-scheme: dark) { .tab[aria-current='true'] { color: #12141a; } }

.topbar__end { display: flex; align-items: center; gap: .6rem; margin-left: .4rem; }

.streak {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .32rem .7rem;
  border-radius: 999px;
  background: var(--vermillion-soft);
  color: var(--vermillion);
  font-size: .82rem;
  font-weight: 700;
  white-space: nowrap;
}

.usermenu { position: relative; }
.avatar {
  width: 36px; height: 36px;
  border: 0; border-radius: 50%;
  background: var(--indigo);
  color: #fff;
  font-weight: 700;
  font-size: .88rem;
  cursor: pointer;
  transition: transform .15s var(--ease);
}
.avatar:hover { transform: scale(1.06); }
@media (prefers-color-scheme: dark) { .avatar { color: #12141a; } }

.menu {
  position: absolute;
  right: 0; top: calc(100% + .55rem);
  min-width: 230px;
  padding: .4rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  animation: pop .16s var(--ease) both;
}
.menu__who {
  margin: 0;
  padding: .6rem .75rem;
  font-size: .82rem;
  color: var(--ink-3);
  border-bottom: 1px solid var(--line);
}
.menu__item {
  display: block;
  width: 100%;
  padding: .62rem .75rem;
  border: 0; border-radius: var(--r-sm);
  background: none;
  text-align: left;
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
}
.menu__item:hover { background: var(--paper); }
.menu__item--danger { color: var(--vermillion); }

.guestbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  padding: .6rem 1rem;
  background: var(--gold);
  color: #2a1e08;
  font-size: .87rem;
  font-weight: 500;
}
.guestbar .link { color: #2a1e08; }

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: clamp(1.5rem, 4vw, 2.75rem) clamp(1rem, 4vw, 2rem) 5rem;
}

.view { animation: rise .32s var(--ease) both; }
.view__title { font-size: clamp(1.7rem, 4vw, 2.2rem); font-weight: 700; }
.view__sub { margin: .5rem 0 1.8rem; color: var(--ink-3); max-width: 64ch; }
.view > .card + .card { margin-top: 1.1rem; }

/* ============================== HOME ================================= */

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 1.6rem;
}
.hero__title { font-size: clamp(1.7rem, 4.5vw, 2.4rem); font-weight: 700; }
.hero__sub { margin: .55rem 0 0; color: var(--ink-3); max-width: 46ch; }

.hero__ring { position: relative; flex: none; width: 128px; height: 128px; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 9; stroke-linecap: round; }
.ring__track { stroke: var(--line); }
.ring__fill {
  stroke: var(--indigo);
  stroke-dasharray: 326.7;
  stroke-dashoffset: 326.7;
  transition: stroke-dashoffset .9s var(--ease);
}
.ring__label {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  line-height: 1.15;
}
.ring__label strong { font-size: 1.5rem; font-weight: 700; }
.ring__label span { font-size: .72rem; color: var(--ink-3); }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .8rem;
  margin-bottom: 1.6rem;
}
.stat {
  padding: 1.05rem 1.15rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
}
.stat__val { font-size: 1.65rem; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
.stat__label { font-size: .79rem; color: var(--ink-3); font-weight: 500; }
.stat--due .stat__val { color: var(--vermillion); }
.stat--mastered .stat__val { color: var(--green); }

/* ---- skill strip (home) ---- */

.section__title { font-size: 1.05rem; font-weight: 700; margin-bottom: .2rem; }
.section__sub { margin: 0 0 .9rem; color: var(--ink-3); font-size: .85rem; }

.skillstrip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .7rem;
  margin-bottom: 1.6rem;
}

.skill {
  display: flex;
  flex-direction: column;
  gap: .45rem;
  padding: .95rem 1rem;
  border: 1.5px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  text-align: left;
  cursor: pointer;
  transition: border-color .16s var(--ease), transform .16s var(--ease), box-shadow .16s;
}
.skill:hover { border-color: var(--indigo-2); transform: translateY(-2px); box-shadow: var(--shadow); }
.skill--active { border-color: var(--indigo); background: var(--indigo-soft); }

.skill__head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.skill__name { font-size: .88rem; font-weight: 700; letter-spacing: -.01em; }
.skill__due {
  padding: .08rem .42rem;
  border-radius: 99px;
  background: var(--vermillion);
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
}
.skill__pct {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.skill__pct small { font-size: .8rem; font-weight: 600; color: var(--ink-3); margin-left: 1px; }
.skill__track { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.skill__track i {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: var(--green);
  transition: width .7s var(--ease);
}
.skill__meta { font-size: .72rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.setup__title { font-size: 1.15rem; font-weight: 700; margin-bottom: 1.3rem; }
.setup__note {
  margin: -.5rem 0 1.1rem;
  padding-left: 72px;
  font-size: .8rem;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.setup__row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .7rem;
  margin-bottom: 1.1rem;
}
.setup__label {
  flex: none;
  width: 72px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink-2);
}

.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip {
  padding: .46rem .9rem;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink-2);
  font-size: .87rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .16s var(--ease);
}
.chip:hover { border-color: var(--indigo-2); color: var(--ink); }
.chip[aria-pressed='true'] {
  background: var(--indigo);
  border-color: var(--indigo);
  color: #fff;
}
@media (prefers-color-scheme: dark) { .chip[aria-pressed='true'] { color: #12141a; } }
.chip__n { opacity: .6; font-weight: 500; margin-left: .25rem; }

.toggle {
  display: flex;
  align-items: center;
  gap: .55rem;
  margin: 1.4rem 0;
  font-size: .89rem;
  color: var(--ink-2);
  cursor: pointer;
}
.toggle input { width: 17px; height: 17px; accent-color: var(--indigo); cursor: pointer; }
.info {
  width: 19px; height: 19px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--line);
  color: var(--ink-2);
  font-size: .72rem;
  font-weight: 700;
  cursor: pointer;
}
.info:hover { background: var(--indigo); color: #fff; }

/* ============================== STUDY ================================ */

.view--study { max-width: 620px; margin: 0 auto; }

.session__bar {
  display: flex;
  align-items: center;
  gap: .9rem;
  margin-bottom: 1.8rem;
}
.progressbar {
  flex: 1;
  height: 7px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}
.progressbar__fill {
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--indigo), var(--indigo-2));
  transition: width .4s var(--ease);
}
.session__count {
  flex: none;
  font-size: .85rem;
  font-weight: 600;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

/* --- flashcard --- */
.flash { perspective: 1600px; }
.flash__inner {
  position: relative;
  display: block;
  width: 100%;
  min-height: 340px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform .62s var(--ease);
}
.flash__inner.is-flipped { transform: rotateY(180deg); }

.flash__face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .8rem;
  padding: 2rem 1.6rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  backface-visibility: hidden;
  text-align: center;
}
.flash__face--back { transform: rotateY(180deg); }

.flash__badge {
  position: absolute;
  top: 1.1rem; left: 1.1rem;
  padding: .22rem .6rem;
  border-radius: 999px;
  background: var(--indigo-soft);
  color: var(--indigo);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
}
.flash__kanji {
  font-family: var(--serif);
  font-size: clamp(6rem, 26vw, 10rem);
  font-weight: 500;
  line-height: 1;
  color: var(--ink);
}
.flash__hint { font-size: .8rem; color: var(--ink-3); }
.flash__meaning {
  font-size: clamp(1.4rem, 5vw, 1.9rem);
  font-weight: 700;
  letter-spacing: -.02em;
  max-width: 22ch;
}
.flash__example {
  margin: 0;
  font-family: var(--serif);
  font-size: 1rem;
  color: var(--ink-2);
}

.readings {
  display: grid;
  grid-template-columns: auto auto;
  gap: .3rem .9rem;
  margin: 0;
  font-size: .95rem;
}
.readings dt {
  color: var(--ink-3);
  font-size: .76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  text-align: right;
  align-self: center;
}
.readings dd { margin: 0; text-align: left; font-weight: 500; }

.grade { margin-top: 1.2rem; animation: rise .26s var(--ease) both; }
.grade__row { display: flex; gap: .7rem; }
.grade__swipe {
  display: none;               /* touch only — see the coarse-pointer block */
  margin: .7rem 0 0;
  text-align: center;
  font-size: .76rem;
  color: var(--ink-3);
}

.hint--touch { display: none; }

/* --- multiple choice --- */
.quiz {
  position: relative;
  padding: 2rem 1.6rem 1.6rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  text-align: center;
}
.quiz__prompt {
  margin: .4rem 0 1rem;
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.quiz__subject {
  font-family: var(--serif);
  font-weight: 500;
  line-height: 1.15;
  margin-bottom: 1.8rem;
  word-break: break-word;
}
.quiz__subject.is-kanji { font-size: clamp(5rem, 22vw, 8rem); }
.quiz__subject.is-text {
  font-family: var(--sans);
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 700;
  letter-spacing: -.02em;
}

.choices { display: grid; gap: .6rem; }
.choice {
  display: flex;
  align-items: center;
  gap: .85rem;
  width: 100%;
  padding: .85rem 1.05rem;
  border: 1.5px solid var(--line);
  border-radius: var(--r);
  background: var(--paper-2);
  text-align: left;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s var(--ease);
}
.choice:hover:not(:disabled) { border-color: var(--indigo-2); transform: translateX(3px); }
.choice:disabled { cursor: default; }
.choice__key {
  flex: none;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border-radius: 6px;
  background: var(--line);
  color: var(--ink-3);
  font-size: .74rem;
  font-weight: 700;
}
.choice--kanji .choice__text { font-family: var(--serif); font-size: 1.85rem; line-height: 1.1; }
.choice.is-right {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green);
}
.choice.is-right .choice__key { background: var(--green); color: #fff; }
.choice.is-wrong {
  border-color: var(--vermillion);
  background: var(--vermillion-soft);
  color: var(--vermillion);
  animation: shake .36s var(--ease);
}
.choice.is-wrong .choice__key { background: var(--vermillion); color: #fff; }

.reveal {
  margin-top: 1.3rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
  animation: rise .26s var(--ease) both;
}
.reveal__text { margin: 0 0 1rem; font-size: .95rem; color: var(--ink-2); }
.reveal__text strong { font-family: var(--serif); font-size: 1.15rem; }

/* --- summary --- */
.summary { text-align: center; padding: 2.5rem 1.8rem; animation: rise .4s var(--ease) both; }
.summary__glyph {
  display: grid;
  place-items: center;
  width: 62px; height: 62px;
  margin: 0 auto 1.1rem;
  border-radius: 50%;
  background: var(--green-soft);
  color: var(--green);
  font-size: 1.7rem;
  font-family: var(--serif);
}
.summary__line { margin: .6rem 0 1.5rem; color: var(--ink-3); }
.summary__stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .8rem;
  margin-bottom: 1.8rem;
  padding: 1.1rem 0;
  border-block: 1px solid var(--line);
}
.summary__stats div span { display: block; font-size: .76rem; color: var(--ink-3); }
.summary__stats div strong { font-size: 1.35rem; font-weight: 700; }
.summary__actions { display: flex; gap: .7rem; justify-content: center; flex-wrap: wrap; }

/* ============================ PROGRESS =============================== */

.levelrow { margin-bottom: 1.4rem; }
.levelrow:last-child { margin-bottom: 0; }
.levelrow__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .45rem;
}
.levelrow__name { font-weight: 700; font-size: .95rem; }
.levelrow__meta { font-size: .82rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.levelrow__track {
  position: relative;
  height: 11px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}
.levelrow__seen, .levelrow__mastered {
  position: absolute;
  inset-block: 0; left: 0;
  border-radius: 99px;
  transition: width .8s var(--ease);
}
.levelrow__seen { background: var(--indigo-soft); }
.levelrow__mastered { background: var(--green); }
@media (prefers-color-scheme: dark) { .levelrow__seen { background: var(--indigo); opacity: .45; } }

.boxes { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: .6rem; }
.box {
  padding: .9rem .7rem;
  border: 1px solid var(--line);
  border-radius: var(--r);
  text-align: center;
  background: var(--paper-2);
}
.box__n { font-size: 1.35rem; font-weight: 700; line-height: 1.2; }
.box__label { font-size: .73rem; color: var(--ink-3); font-weight: 600; }
.box__when { font-size: .68rem; color: var(--ink-3); opacity: .8; }
.box--mastered { background: var(--green-soft); border-color: transparent; }
.box--mastered .box__n, .box--mastered .box__label { color: var(--green); }

/* ---- skill board (progress) ---- */

.skillrow { padding: 1.1rem 0; border-top: 1px solid var(--line); }
.skillrow:first-child { padding-top: 0; border-top: 0; }
.skillrow:last-child { padding-bottom: 0; }

.skillrow__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .6rem;
}
.skillrow__name { font-size: 1rem; font-weight: 700; }
.skillrow__blurb { font-size: .8rem; color: var(--ink-3); margin-top: .1rem; }
.skillrow__pct {
  flex: none;
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.skillrow__pct small { font-size: .85rem; font-weight: 600; color: var(--ink-3); }

.skillrow__meta {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem .95rem;
  margin-top: .6rem;
  font-size: .8rem;
  color: var(--ink-3);
}
.skillrow__meta b { color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }
.skillrow__meta .is-due, .skillrow__meta .is-due b { color: var(--vermillion); }

.skillrow__go {
  margin-top: .85rem;
  padding: .45rem .9rem;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink-2);
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .16s var(--ease);
}
.skillrow__go:hover { border-color: var(--indigo); background: var(--indigo); color: #fff; }
@media (prefers-color-scheme: dark) { .skillrow__go:hover { color: #12141a; } }

/* ---- skill pips ---- */

.pip {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 2.5px;
  background: var(--line);
  flex: none;
}
.pip--none   { background: var(--line); }
.pip--weak   { background: var(--vermillion); }
.pip--mid    { background: var(--gold); }
.pip--strong { background: var(--green); }

.gaplegend {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem 1rem;
  margin-bottom: 1rem;
  font-size: .74rem;
  color: var(--ink-3);
}
.gaplegend span { display: inline-flex; align-items: center; gap: .35rem; }

.gaplist { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .5rem; }
.gapitem {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .6rem .8rem;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--paper-2);
}
.gapitem__k { font-family: var(--serif); font-size: 1.75rem; line-height: 1; flex: none; }
.gapitem__body { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.gapitem__m {
  font-size: .82rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gapitem__note { font-size: .7rem; color: var(--ink-3); }
.gapitem__pips { display: flex; gap: 3px; flex: none; }

.tile__pips {
  position: absolute;
  top: .55rem; right: .55rem;
  display: flex;
  gap: 2.5px;
}
.tile__pips .pip { width: 6px; height: 6px; border-radius: 2px; }

.weaklist { display: flex; flex-wrap: wrap; gap: .5rem; }
.weakitem {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .5rem .8rem;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--paper-2);
}
.weakitem__k { font-family: var(--serif); font-size: 1.5rem; line-height: 1; }
.weakitem__m { font-size: .78rem; color: var(--ink-3); max-width: 15ch; }
.weakitem__n {
  font-size: .72rem;
  font-weight: 700;
  color: var(--vermillion);
  background: var(--vermillion-soft);
  padding: .15rem .45rem;
  border-radius: 99px;
}

/* ============================= BROWSE ================================ */

.browse__controls {
  display: flex;
  flex-wrap: wrap;
  gap: .8rem;
  align-items: center;
  margin-bottom: 1.4rem;
}
.search {
  flex: 1 1 260px;
  padding: .72rem 1rem;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  transition: border-color .16s, box-shadow .16s;
}
.search:focus {
  outline: none;
  border-color: var(--indigo-2);
  box-shadow: 0 0 0 3.5px var(--indigo-soft);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(146px, 1fr));
  gap: .7rem;
}
.tile {
  position: relative;
  padding: 1rem .8rem .85rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  text-align: center;
  transition: transform .16s var(--ease), box-shadow .16s, border-color .16s;
}
.tile:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: var(--indigo-2);
}
.tile__k {
  font-family: var(--serif);
  font-size: 2.7rem;
  line-height: 1.1;
  display: block;
  margin-bottom: .35rem;
}
.tile__m {
  font-size: .8rem;
  color: var(--ink-2);
  font-weight: 500;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tile__r { font-size: .72rem; color: var(--ink-3); margin-top: .2rem; }
.tile__lv {
  position: absolute;
  top: .5rem; left: .55rem;
  font-size: .64rem;
  font-weight: 700;
  color: var(--ink-3);
  letter-spacing: .04em;
}
.tile__dot {
  position: absolute;
  top: .6rem; right: .6rem;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--line);
}
.tile__dot--seen { background: var(--indigo); }
.tile__dot--mastered { background: var(--green); }
.tile__flag {
  position: absolute;
  bottom: .45rem; right: .55rem;
  font-size: .62rem;
  font-weight: 700;
  color: var(--gold);
  cursor: help;
}

.empty { text-align: center; color: var(--ink-3); padding: 3rem 1rem; }

/* ============================== MODAL ================================ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: rgba(20,22,28,.5);
  backdrop-filter: blur(3px);
  animation: fade .2s var(--ease) both;
}
.modal__box {
  width: min(460px, 100%);
  box-shadow: var(--shadow-lg);
  animation: pop .24s var(--ease) both;
}
.modal__box p { color: var(--ink-2); font-size: .92rem; line-height: 1.6; }
.modal__actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1.4rem; }

.toast {
  position: fixed;
  left: 50%; bottom: 2rem;
  z-index: 95;
  transform: translateX(-50%);
  padding: .75rem 1.3rem;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: .89rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: rise .28s var(--ease) both;
}

/* ============================ animation ============================== */

@keyframes rise  { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pop   { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: none; } }
@keyframes fade  { from { opacity: 0; } to { opacity: 1; } }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  30%, 70% { transform: translateX(4px); }
  50%      { transform: translateX(-4px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .flash__inner { transition: none; }
}

/* =========================================================================
   TOUCH + MOBILE
   ========================================================================= */

/* ---- hover is a lie on touch: don't let these states stick after a tap --- */
@media (hover: none) {
  .tile:hover {
    transform: none;
    box-shadow: var(--shadow-sm);
    border-color: var(--line);
  }
  .choice:hover:not(:disabled) { transform: none; border-color: var(--line); }
  .btn--primary:hover { background: var(--indigo); box-shadow: var(--shadow-sm); }
  .btn--ghost:hover { border-color: var(--line); color: var(--ink-2); }
  .btn--again:hover { background: var(--vermillion-soft); color: var(--vermillion); }
  .btn--got:hover { background: var(--green-soft); color: var(--green); }
  .tab:hover { background: none; color: var(--ink-3); }
  .chip:hover { border-color: var(--line); color: var(--ink-2); }
  .link:hover { color: var(--indigo); }
  .iconbtn:hover { background: transparent; color: var(--ink-3); }
  .avatar:hover { transform: none; }
  .info:hover { background: var(--line); color: var(--ink-2); }
  .menu__item:hover { background: none; }

  /* Press feedback replaces hover feedback. */
  .choice:active:not(:disabled) { border-color: var(--indigo-2); background: var(--indigo-soft); }
  .tile:active { transform: scale(.97); }
  .chip:active { border-color: var(--indigo-2); }
}

/* ---- coarse pointers: bigger targets, touch-appropriate copy ------------ */
@media (pointer: coarse) {
  /* WCAG 2.5.5 asks for 44px; these were 36–38px. */
  .chip { padding: .62rem 1.05rem; min-height: 44px; }
  .iconbtn { width: 44px; height: 44px; }
  .info { width: 26px; height: 26px; font-size: .8rem; }
  .toggle { padding: .4rem 0; min-height: 44px; }
  .toggle input { width: 22px; height: 22px; }
  .menu__item { padding: .8rem .75rem; }
  .link { padding: .2rem 0; }

  .hint--touch { display: inline; }
  .hint--mouse { display: none; }
  .grade__swipe { display: block; }

  /* The flip card is dragged horizontally; let vertical scroll through. */
  .flash { touch-action: pan-y; }
}

/* ---- bottom navigation (small screens only) ---------------------------- */
.botnav { display: none; }

@media (max-width: 720px) {
  .topbar .tabs { display: none; }
  .brand__text { display: inline; }
  /* .tabs carried the `margin-left:auto` that pushed the avatar right. */
  .topbar__end { margin-left: auto; }

  .botnav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 50;
    display: flex;
    justify-content: space-around;
    gap: .25rem;
    padding: .4rem .5rem calc(.4rem + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--paper) 92%, transparent);
    backdrop-filter: saturate(180%) blur(16px);
    border-top: 1px solid var(--line);
  }

  .botnav__tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .18rem;
    min-height: 52px;
    padding: .35rem .2rem;
    border-radius: var(--r);
    background: none;
    color: var(--ink-3);
    font-size: .7rem;
    font-weight: 600;
    letter-spacing: -.01em;
    transition: color .16s, background .16s;
  }
  .botnav__tab svg {
    width: 22px; height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  .botnav__tab[aria-current='true'] {
    background: var(--indigo-soft);
    color: var(--indigo);
  }
  .botnav__tab:active { background: var(--line); }

  /* Room for the bar, plus the home indicator below it. */
  main { padding-bottom: calc(5.5rem + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(5rem + env(safe-area-inset-bottom)); }

  /* An open session owns the screen — no stray taps into another tab. */
  body.is-studying .botnav { display: none; }
  /* Only flashcard mode pins a bar to the bottom; don't reserve space otherwise. */
  body.is-studying.has-gradebar main { padding-bottom: calc(8.5rem + env(safe-area-inset-bottom)); }
  body.is-studying:not(.has-gradebar) main { padding-bottom: calc(2rem + env(safe-area-inset-bottom)); }
}

/* ---- notch / rounded-corner safe areas --------------------------------- */
@supports (padding: max(0px)) {
  .topbar {
    padding-left: max(clamp(1rem, 4vw, 2.5rem), env(safe-area-inset-left));
    padding-right: max(clamp(1rem, 4vw, 2.5rem), env(safe-area-inset-right));
  }
  main {
    padding-left: max(clamp(1rem, 4vw, 2rem), env(safe-area-inset-left));
    padding-right: max(clamp(1rem, 4vw, 2rem), env(safe-area-inset-right));
  }
}

/* ---- phone layout ------------------------------------------------------ */
@media (max-width: 640px) {
  .topbar { padding-block: .55rem; gap: .6rem; }
  .brand__text { font-size: .95rem; }

  main { padding-top: 1.25rem; }
  .view__title { font-size: 1.55rem; }
  .view__sub { margin-bottom: 1.3rem; font-size: .9rem; }
  .card { padding: 1.25rem; border-radius: var(--r); }

  .hero {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.3rem;
  }
  .hero__title { font-size: 1.5rem; }
  .hero__sub { font-size: .89rem; }
  .hero__ring { width: 84px; height: 84px; }
  .ring circle { stroke-width: 10; }
  .ring__label strong { font-size: 1.1rem; }
  .ring__label span { font-size: .6rem; }

  /* Two up beats one tall column of stat cards. */
  .stats { grid-template-columns: 1fr 1fr; gap: .6rem; }
  .stat { padding: .85rem .9rem; }
  .stat__val { font-size: 1.4rem; }

  .setup__row { gap: .5rem; margin-bottom: 1.3rem; }
  .setup__label { width: 100%; margin-bottom: -.15rem; }
  .setup__note { padding-left: 0; margin-top: -.75rem; }

  .skillstrip { grid-template-columns: 1fr 1fr; gap: .55rem; }
  .skill { padding: .8rem .85rem; }
  .skill__pct { font-size: 1.3rem; }
  .skill__meta { font-size: .68rem; }

  .skillrow__pct { font-size: 1.4rem; }
  .skillrow__blurb { font-size: .75rem; }
  .gaplist { grid-template-columns: 1fr; }

  .summary { padding: 2rem 1.25rem; }
  .summary__stats { grid-template-columns: repeat(3, 1fr); gap: .4rem; }
  .summary__stats div strong { font-size: 1.15rem; }
  .summary__actions .btn { flex: 1; }

  .boxes { grid-template-columns: repeat(3, 1fr); gap: .45rem; }
  .box { padding: .7rem .4rem; }
  .box__n { font-size: 1.15rem; }
  .box__label { font-size: .66rem; }
  .box__when { font-size: .6rem; }

  .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: .5rem; }
  .tile { padding: .8rem .5rem .7rem; }
  .tile__k { font-size: 2.2rem; }
  .tile__m { font-size: .72rem; }
  .tile__r { font-size: .64rem; }
  .tile__flag { font-size: .55rem; }

  .browse__controls { gap: .6rem; }

  /* Bottom-sheet modal: closer to the thumb than a centred dialog. */
  .modal { padding: 0; align-items: end; }
  .modal__box {
    width: 100%;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding-bottom: calc(1.6rem + env(safe-area-inset-bottom));
    animation: sheet .28s var(--ease) both;
  }
  .modal__actions .btn { flex: 1; }

  .guestbar { font-size: .8rem; padding: .5rem .8rem; }

  /* Auth: shrink the banner so the form is above the fold on a phone. */
  .auth__art { padding: 1.75rem 1.25rem 1.5rem; gap: .75rem; }
  .auth__glyph { font-size: 4.75rem; }
  .auth__tag { font-size: .92rem; max-width: 30ch; }
  .auth__panel { padding: 1.25rem 1rem calc(1.5rem + env(safe-area-inset-bottom)); }
  .auth__card { padding: 1.5rem 1.25rem; }
  .auth__title { font-size: 1.45rem; }
  .auth__sub { margin-bottom: 1.35rem; font-size: .88rem; }
  .auth__or { margin: 1.15rem 0 .95rem; }
  .field { margin-bottom: .9rem; }
  .field input { padding: .85rem .95rem; }
}

/* ---- the study screen on a phone --------------------------------------- */
@media (max-width: 720px) {
  .view--study { max-width: none; }
  .session__bar { margin-bottom: 1.1rem; }

  /* Size the card to the viewport so grading never needs a scroll. */
  .flash__inner {
    height: clamp(260px, 46dvh, 420px);
    min-height: 0;
  }
  .flash__face { padding: 1.5rem 1.1rem; gap: .6rem; }
  .flash__kanji { font-size: clamp(5.5rem, 34vw, 9rem); }
  .flash__meaning { font-size: 1.35rem; }
  .readings { font-size: .9rem; }
  .flash__example { font-size: .92rem; }

  /* Grade buttons pinned in thumb reach, not wherever the card ends. */
  .grade {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 45;
    margin: 0;
    padding: .8rem max(1rem, env(safe-area-inset-left))
             calc(.8rem + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-right));
    background: color-mix(in srgb, var(--paper) 94%, transparent);
    backdrop-filter: saturate(180%) blur(16px);
    border-top: 1px solid var(--line);
    animation: rise .22s var(--ease) both;
  }
  .grade .btn { min-height: 52px; font-size: 1rem; }
  .grade__swipe { margin-top: .5rem; }

  .quiz { padding: 1.5rem 1.1rem 1.3rem; }
  .quiz__prompt { margin-bottom: .7rem; font-size: .75rem; }
  .quiz__subject { margin-bottom: 1.2rem; }
  .quiz__subject.is-kanji { font-size: clamp(4.5rem, 28vw, 7rem); }
  .quiz__subject.is-text { font-size: 1.35rem; }
  .choice { padding: .95rem 1rem; min-height: 54px; }
  .choice--kanji .choice__text { font-size: 2rem; }
  .reveal { margin-top: 1rem; padding-top: 1rem; }
  .reveal__text { font-size: .88rem; }
  .reveal .btn { width: 100%; min-height: 50px; }
}

/* ---- phone held sideways: vertical space is the scarce resource -------- */
@media (max-height: 520px) and (orientation: landscape) {
  .topbar { position: static; }
  .flash__inner { height: clamp(180px, 58dvh, 300px); }
  .flash__kanji { font-size: clamp(4rem, 17vh, 7rem); }
  .quiz__subject.is-kanji { font-size: clamp(3rem, 15vh, 5rem); }
  .quiz__subject { margin-bottom: .8rem; }
  .choices { grid-template-columns: 1fr 1fr; }
  .choice { min-height: 46px; padding: .6rem .8rem; }
  .auth { min-height: 0; }
  .auth__art { display: none; }
}

/* Very narrow phones (iPhone SE and similar). */
@media (max-width: 360px) {
  .stats { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
  .botnav__tab span { font-size: .65rem; }
  .summary__stats div strong { font-size: 1rem; }
}

@keyframes sheet { from { transform: translateY(100%); } to { transform: none; } }
