:root {
  --ink: #111;
  --paper: #fafaf8;
  --muted: #777;
  --line: #ddd;
  --accent: #c8321e;
  --ok: #2e7d4f;
  --kanji-font: "Yuji Syuku", "Noto Sans JP", serif;
  --body-font: "Noto Sans JP", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  font-family: var(--body-font);
  color: var(--ink);
  background: var(--paper);
  font-size: clamp(1.05rem, 1rem + .4vw, 1.25rem);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.card {
  width: 100%;
  max-width: 44rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: fade .35s ease-out;
}

@keyframes fade {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

[hidden] { display: none !important; }

/* Card stays invisible until the first kanji and its font slices are ready. */
body.loading .card { visibility: hidden; }

.index {
  flex: 1;
  width: 100%;
  max-width: 64rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
  animation: fade .35s ease-out;
}

.mastered {
  flex: 1;
  width: 100%;
  max-width: 40rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  animation: fade .35s ease-out;
}

.mastered-glyph {
  margin: 0;
  font-size: clamp(120px, 30vmin, 240px);
  line-height: 1.2;
}

.mastered h2 {
  margin: 0 0 .25rem;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  letter-spacing: .04em;
  text-transform: uppercase;
}

.mastered p { margin: 0 0 .5rem; }

.mastered-hint {
  margin-top: 1.5rem !important;
  color: var(--muted);
  font-size: .9rem;
}

.about {
  flex: 1;
  width: 100%;
  max-width: 40rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
  animation: fade .35s ease-out;
}

.about h3 {
  margin: 1.75rem 0 .5rem;
  font-size: .8rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted);
}

.about p { margin: 0 0 .75rem; }

.index-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.index-head h2 {
  margin: 0;
  font-size: .9rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--accent);
}

.index-progress {
  margin: -.75rem 0 1.25rem;
  font-size: .85rem;
  color: var(--muted);
}

.index-progress .link { font-size: inherit; padding: 0; }

.index-progress .learned,
.index-progress .ok { color: var(--ok); }
.index-progress .miss { color: var(--accent); }

.index-close {
  font: inherit;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--ink);
  background: none;
  border: 0;
  padding: .25rem .5rem;
  cursor: pointer;
}

.index-close:hover,
.index-close:focus-visible { color: var(--accent); }

.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr));
  gap: .5rem;
}

.grid button {
  width: 100%;
  padding: .75rem .25rem;
  font-family: var(--kanji-font);
  font-size: 2.6rem;
  line-height: 1;
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 2px;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.grid button:hover,
.grid button:focus-visible { background: var(--ink); color: #fff; outline: none; }

.kanji {
  margin: 0;
  font-family: var(--kanji-font);
  font-weight: 400;
  font-size: clamp(160px, 50vmin, 420px);
  line-height: 1.1;
  transition: font-size .3s ease-out;
}

/* Once revealed the kanji is reference, not the quiz: make room for the details. */
.card.revealed .kanji { font-size: clamp(110px, 28vmin, 240px); }

.actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 1.25rem 3rem;
}

/* Desktop: buttons flow under the card, footer bar sticks on its own. */
.dock { display: contents; }

.quiz {
  margin-top: 2.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
}

.reveal {
  margin: 0;
  font: inherit;
  font-size: 1rem;
  letter-spacing: .15em;
  text-transform: uppercase;
  color: var(--ink);
  background: none;
  border: 1px solid var(--ink);
  border-radius: 2px;
  padding: .6rem 1.6rem;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}

.reveal:hover,
.reveal:focus-visible { background: var(--accent); border-color: var(--accent); color: #fff; outline: none; }

.details {
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: fade .35s ease-out;
}

.meaning {
  margin: .25rem 0 1.5rem;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.readings {
  margin: 0 0 1.5rem;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .25rem 1rem;
  text-align: left;
}

.reading { display: contents; }

.readings dt {
  color: var(--muted);
  font-size: .85rem;
  letter-spacing: .15em;
  text-transform: uppercase;
  align-self: center;
}

.readings dd {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: .25rem 1rem;
  font-size: 1.35rem;
}

.readings .romaji {
  color: var(--muted);
  font-size: 1rem;
  margin-left: .35rem;
}

.readings .none { color: var(--muted); }

.section-label {
  margin: 0 0 .5rem;
  color: var(--muted);
  font-size: .85rem;
  letter-spacing: .15em;
  text-transform: uppercase;
}

.components {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .5rem;
}

.components li {
  display: flex;
  align-items: center;
  gap: .5rem;
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: .35rem .8rem;
  font-size: 1.05rem;
  background: #fff;
}

.components .glyph {
  font-family: var(--kanji-font);
  font-size: 2rem;
  line-height: 1;
}

.section-label-mnemonic {
  width: 100%;
  max-width: 36rem;
  border-top: 1px solid var(--line);
  padding-top: 1.25rem;
}

.mnemonic {
  margin: 0;
  max-width: 36rem;
  font-size: 1.2rem;
  color: #333;
}

.mnemonic strong { font-weight: 700; color: var(--ink); }

.mnemonic .glyph { font-family: var(--kanji-font); }

.section-label-examples {
  margin-top: 1.5rem;
}

.examples {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: auto auto auto 1fr;
  gap: .35rem 1rem;
  text-align: left;
  max-width: 36rem;
  font-size: 1.05rem;
}

.examples li { display: contents; }

.examples .word { font-size: 1.3rem; }

.examples .romaji, .examples .gloss { color: var(--muted); }

@media (max-width: 560px) {
  .examples { grid-template-columns: auto auto 1fr; }
  .examples .romaji { display: none; }
}

.bar {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: .6rem 1.25rem;
  padding-bottom: calc(.6rem + env(safe-area-inset-bottom));
  font-size: .8rem;
  color: var(--muted);
  background: var(--paper);
  border-top: 1px solid var(--line);
}

.bar-left,
.bar-right {
  flex: 1;
  display: flex;
  align-items: center;
  gap: .9rem;
  white-space: nowrap;
}

.bar-right { justify-content: flex-end; }

.brand {
  color: var(--ink);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: .02em;
  text-decoration: none;
  white-space: nowrap;
}

.brand:hover { color: var(--accent); }

.brand-wrap {
  display: flex;
  align-items: center;
  gap: .4rem;
  line-height: 1;
}

.info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1em;
  height: 1.1em;
  font-size: 1.25rem; /* same as .brand so the icon scales with the title */
  color: var(--muted);
  background: none;
  border: 0;
  padding: 0;
  margin-top: .05em; /* optical: emoji sits a hair high */
  cursor: pointer;
  transition: color .15s;
}

.info svg { width: 100%; height: 100%; display: block; }

.info-text { display: none; }

.info:hover,
.info:focus-visible { color: var(--accent); outline: none; }

.level {
  position: relative;
  letter-spacing: .1em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
}

.level::after { content: " ▾"; }

/* Native select kept for the dropdown, visually replaced by the label text. */
.level select {
  position: absolute;
  inset: 0;
  width: 100%;
  opacity: 0;
  cursor: pointer;
}

.level:hover,
.level:focus-within { color: var(--accent); }

a.link { color: var(--ink); }

.link {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: .25rem 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: .25em;
  text-decoration-color: var(--line);
}

.link:hover,
.link:focus-visible { color: var(--accent); outline: none; text-decoration-color: currentColor; }

.rate {
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
}

.rate-q {
  margin: 0;
  color: var(--muted);
  font-size: .85rem;
  letter-spacing: .15em;
  text-transform: uppercase;
}

.rate-btns {
  display: flex;
  gap: .75rem;
}


.rate-btn {
  font: inherit;
  font-size: 1rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--ink);
  border-radius: 2px;
  padding: .6rem 1.6rem;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}

.rate-btn.miss { background: var(--accent); border-color: var(--accent); color: #fff; }
.rate-btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }

.rate-btn:hover,
.rate-btn:focus-visible { filter: brightness(1.15); outline: none; }

.grid button { position: relative; }

.grid .mark {
  position: absolute;
  right: .3rem;
  bottom: .15rem;
  font-family: var(--body-font);
  font-size: .7rem;
  line-height: 1;
  letter-spacing: .1em;
  color: var(--ok);
}

.grid button.learned .mark,
.grid button:hover .mark,
.grid button:focus-visible .mark { color: #fff; }

.grid button.unseen { border-color: var(--line); }
.grid button.ok { border-color: var(--ok); }
.grid button.learned { border-color: var(--ok); background: var(--ok); color: #fff; }
.grid button.miss { border-color: var(--accent); }

.grid button.ok:hover,
.grid button.ok:focus-visible { background: var(--ok); color: #fff; }
.grid button.miss:hover,
.grid button.miss:focus-visible { background: var(--accent); color: #fff; }

.cta {
  display: inline-block;
  margin: 2.5rem 0 0;
  text-decoration: none;
  background: var(--ink);
  color: #fff;
}

.cta:hover,
.cta:focus-visible { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Mobile: buttons dock above the footer at a fixed height so the thumb never moves. */
@media (max-width: 560px) {
  .dock {
    display: block;
    position: sticky;
    bottom: 0;
    margin-top: auto;
    background: var(--paper);
  }
  .card { padding-bottom: 1.5rem; }
  /* Same strip for Reveal and Yes/No so the thumb never moves. */
  .actions {
    padding: .75rem 1.25rem;
    border-top: 1px solid var(--line);
  }
  .quiz, .rate, .cta { margin: 0; }
  .bar { position: static; margin-top: 0; padding-top: .4rem; padding-bottom: calc(.4rem + env(safe-area-inset-bottom)); }
  .bar-right { display: none; } /* credit lives in the about page on small screens */
  .brand, .info svg { display: none; }
  .info { width: auto; height: auto; font: inherit; line-height: inherit; }
  .info-text { display: inline; }
}

.about-credit {
  margin-top: 2rem;
  color: var(--muted);
  font-size: .85rem;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}



/* Static reference pages generated by tools/build.py */
.crumb {
  margin: 0 0 .5rem;
  font-size: .8rem;
  letter-spacing: .2em;
  text-transform: uppercase;
}

.crumb a { color: var(--accent); text-decoration: none; }
.crumb a:hover { text-decoration: underline; }

.static .examples { margin-bottom: 0; }

.static .index-head h1 {
  margin: 0;
  font-size: .9rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--accent);
}

.grid-static a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .25rem;
  padding: .6rem .25rem .5rem;
  font-family: var(--kanji-font);
  font-size: 2.6rem;
  line-height: 1;
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 2px;
  text-decoration: none;
  transition: background .15s, color .15s;
}

.grid-static a span {
  font-family: var(--body-font);
  font-size: .75rem;
  line-height: 1.2;
  color: var(--muted);
}

.grid-static a:hover,
.grid-static a:focus-visible { background: var(--ink); color: #fff; outline: none; }
.grid-static a:hover span { color: #fff; }
