/* Layout: kanji index strip on top, then one "study sheet" per kanji on manuscript-grid paper, quiz below the sheet */
:root{
  --paper:#f7f8f6; --sheet:#ffffff; --ink:#1d2433; --muted:#5d6577; --line:#dde2e8;
  --on:#2f4a8a; --on-soft:#e6ebf6; --kun:#3f6b45; --kun-soft:#e5efe5;
  --accent:#b8452f; --good:#2f7a46; --bad:#b03a2e;
  --f-kanji:"Zen Old Mincho","Hiragino Mincho ProN","Yu Mincho",serif;
  --f-body:"Zen Kaku Gothic New","Hiragino Sans","Yu Gothic",system-ui,sans-serif;
  --f-mono:"IBM Plex Mono",ui-monospace,Menlo,monospace;
}
@media (prefers-color-scheme: dark){:root:not([data-theme="light"]){
  --paper:#14171d; --sheet:#1b1f27; --ink:#e7e9ee; --muted:#9aa2b2; --line:#2c323d;
  --on:#93abe6; --on-soft:#232c42; --kun:#8fc497; --kun-soft:#1f3123;
  --accent:#e2836c; --good:#6fc58a; --bad:#ec7d70; color-scheme:dark}}
:root[data-theme="dark"]{
  --paper:#14171d; --sheet:#1b1f27; --ink:#e7e9ee; --muted:#9aa2b2; --line:#2c323d;
  --on:#93abe6; --on-soft:#232c42; --kun:#8fc497; --kun-soft:#1f3123;
  --accent:#e2836c; --good:#6fc58a; --bad:#ec7d70; color-scheme:dark}
*{box-sizing:border-box}
body{background:var(--paper);color:var(--ink);font-family:var(--f-body);font-size:16px;line-height:1.6}
.wrap{max-width:980px;margin:0 auto;padding-block:28px 64px;
  padding-left:max(16px,env(safe-area-inset-left,0px));padding-right:max(16px,env(safe-area-inset-right,0px));
  display:flex;flex-direction:column;gap:28px}
header{display:flex;flex-wrap:wrap;align-items:baseline;justify-content:space-between;gap:8px 24px}
.brand{font-family:var(--f-kanji);font-size:1.6rem;font-weight:700;letter-spacing:.02em;margin:0}
.brand span{color:var(--accent)}
.tag{margin:0;color:var(--muted);font-size:.95rem;max-width:52ch}
.index{display:grid;grid-template-columns:repeat(auto-fill,minmax(64px,1fr));gap:8px}
.index a{font-family:var(--f-kanji);font-size:1.9rem;line-height:1;padding:12px 0 8px;
  background:var(--sheet);color:var(--ink);border:1px solid var(--line);border-radius:6px;cursor:pointer;
  display:flex;flex-direction:column;align-items:center;gap:6px;text-decoration:none}
.index a small{font-family:var(--f-mono);font-size:.68rem;color:var(--muted)}
.index a[aria-current="true"]{border-color:var(--accent);box-shadow:inset 0 -3px 0 var(--accent)}
.index a:focus-visible,.opts button:focus-visible,.modes button:focus-visible,.next:focus-visible{outline:2px solid var(--accent);outline-offset:2px}

.sheet{background:var(--sheet);border:1px solid var(--line);border-radius:8px;padding:24px;
  display:grid;grid-template-columns:auto 1fr;gap:28px}
.big{width:168px;height:168px;position:relative;font-family:var(--f-kanji);font-size:128px;line-height:168px;text-align:center;
  border:1.5px solid var(--accent);
  background-image:linear-gradient(var(--line),var(--line)),linear-gradient(var(--line),var(--line));
  background-size:1px 100%,100% 1px;background-position:center;background-repeat:no-repeat}
.big-cap{margin-top:10px;font-size:.85rem;color:var(--muted);text-align:center;max-width:168px}
.info{min-width:0;display:flex;flex-direction:column;gap:18px}
.sheet-title{margin:0;font-size:1.5rem;font-weight:700;text-wrap:balance}
.info p.lede{margin:0;color:var(--muted);max-width:62ch}
.rd{display:flex;flex-direction:column;gap:8px}
.rd-row{display:flex;gap:10px;align-items:flex-start;flex-wrap:wrap}
.rd-label{font-size:.72rem;letter-spacing:.08em;text-transform:uppercase;font-weight:700;width:86px;padding-top:6px}
.rd-row.on .rd-label{color:var(--on)} .rd-row.kun .rd-label{color:var(--kun)}
.chips{display:flex;flex-wrap:wrap;gap:6px;flex:1;min-width:0}
.chip{border-radius:999px;padding:3px 12px;font-size:1rem;display:inline-flex;gap:8px;align-items:baseline}
.chip i{font-style:normal;font-family:var(--f-mono);font-size:.75rem;opacity:.8}
.on .chip{background:var(--on-soft);color:var(--on)} .kun .chip{background:var(--kun-soft);color:var(--kun)}
.tbl-wrap{overflow-x:auto}
table{border-collapse:collapse;width:100%;font-size:.95rem}
th{text-align:left;font-size:.72rem;letter-spacing:.08em;text-transform:uppercase;color:var(--muted);font-weight:700;padding:6px 10px;border-bottom:1px solid var(--line)}
td{padding:8px 10px;border-bottom:1px solid var(--line);vertical-align:baseline}
td.w{font-family:var(--f-kanji);font-size:1.25rem;white-space:nowrap}
td.w b{color:var(--accent);font-weight:700}
td.r{white-space:nowrap} td.r i{display:block;font-style:normal;font-family:var(--f-mono);font-size:.75rem;color:var(--muted)}
.pill{font-size:.7rem;font-weight:700;letter-spacing:.06em;text-transform:uppercase;padding:2px 8px;border-radius:4px;white-space:nowrap}
.pill.on{background:var(--on-soft);color:var(--on)} .pill.kun{background:var(--kun-soft);color:var(--kun)}
.pill.sp{background:transparent;color:var(--accent);border:1px solid var(--accent)}
.note{font-size:.85rem;color:var(--muted);margin:0}

.quiz{display:flex;flex-direction:column;gap:16px}
.quiz-head{display:flex;flex-wrap:wrap;justify-content:space-between;align-items:center;gap:12px}
.quiz-head h2{margin:0;font-size:1.2rem}
.modes{display:flex;gap:4px;background:var(--sheet);border:1px solid var(--line);border-radius:8px;padding:4px;flex-wrap:wrap}
.modes button{border:0;background:transparent;color:var(--muted);font:inherit;font-size:.85rem;padding:6px 12px;border-radius:5px;cursor:pointer}
.modes button[aria-pressed="true"]{background:var(--ink);color:var(--sheet)}
.card{background:var(--sheet);border:1px solid var(--line);border-radius:8px;padding:24px;display:flex;flex-direction:column;gap:18px}
.meta{display:flex;justify-content:space-between;font-family:var(--f-mono);font-size:.8rem;color:var(--muted);font-variant-numeric:tabular-nums}
.bar{height:3px;background:var(--line);border-radius:2px;overflow:hidden}
.bar div{height:100%;background:var(--accent);transition:width .3s}
.prompt{text-align:center;display:flex;flex-direction:column;gap:6px}
.prompt .q{font-size:.9rem;color:var(--muted)}
.prompt .word{font-family:var(--f-kanji);font-size:3.2rem;line-height:1.2}
.prompt .word b{color:var(--accent);text-decoration:underline;text-decoration-thickness:2px;text-underline-offset:8px}
.prompt .hint{font-size:.9rem;color:var(--muted)}
.opts{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
.opts button{font:inherit;font-size:1.25rem;padding:14px 10px;border-radius:6px;border:1px solid var(--line);
  background:var(--paper);color:var(--ink);cursor:pointer;display:flex;flex-direction:column;align-items:center;gap:2px}
.opts button i{font-style:normal;font-family:var(--f-mono);font-size:.75rem;color:var(--muted)}
.opts button:hover:not(:disabled){border-color:var(--ink)}
.opts button.right{border-color:var(--good);background:color-mix(in srgb,var(--good) 12%,var(--sheet))}
.opts button.wrong{border-color:var(--bad);background:color-mix(in srgb,var(--bad) 12%,var(--sheet))}
.opts button:disabled{cursor:default}
.opts button:last-child:nth-child(odd){grid-column:1/-1}
.fb{min-height:3.2em;text-align:center;font-size:.95rem}
.fb strong.ok{color:var(--good)} .fb strong.ng{color:var(--bad)}
.fb .ans{font-family:var(--f-kanji);font-size:1.1rem}
.next{align-self:center;font:inherit;font-weight:700;padding:10px 28px;border-radius:6px;border:0;background:var(--ink);color:var(--sheet);cursor:pointer}
.result{text-align:center;display:flex;flex-direction:column;gap:12px;align-items:center}
.result .score{font-family:var(--f-kanji);font-size:3rem;line-height:1}
.missed{list-style:none;padding:0;margin:0;display:flex;flex-wrap:wrap;gap:8px;justify-content:center}
.missed li{border:1px solid var(--line);border-radius:6px;padding:4px 10px;font-size:.9rem}
.missed li span{font-family:var(--f-kanji);font-size:1.05rem;margin-right:6px}
.sec-label{font-size:.72rem;letter-spacing:.08em;text-transform:uppercase;font-weight:700;color:var(--muted);margin:0 0 -16px}
/* challenge */
.chal{background:var(--sheet);border:1px solid var(--line);border-radius:8px;padding:24px;display:flex;flex-direction:column;gap:18px}
.chal-head{display:flex;flex-wrap:wrap;justify-content:space-between;align-items:center;gap:10px 16px}
.chal-head h2{margin:0;font-size:1.35rem;text-wrap:balance}
.chal-head p{margin:2px 0 0;color:var(--muted);font-size:.9rem}
.sent{font-family:var(--f-kanji);font-size:1.75rem;line-height:2.5;text-align:center;margin:0;text-wrap:balance}
.slot{padding:0 2px;border-bottom:2px dotted var(--muted)}
.slot.cur{color:var(--accent);border-bottom:2px solid var(--accent)}
ruby.slot{border-bottom:0}
rt{font-family:var(--f-body);font-size:.42em;color:var(--muted)}
.slot.ok rt{color:var(--good)} .slot.ng rt{color:var(--bad)}
.sent-en{font-size:.9rem;color:var(--muted);text-align:center;margin:-8px 0 0}
.last{text-align:center;font-size:.9rem;min-height:1.6em;margin:0}
.last .ok{color:var(--good);font-weight:700} .last .ng{color:var(--bad);font-weight:700}
.share{display:flex;flex-wrap:wrap;gap:8px;justify-content:center}
.share a,.share button{font:inherit;font-size:.9rem;font-weight:700;padding:9px 18px;border-radius:6px;border:1px solid var(--ink);background:transparent;color:var(--ink);text-decoration:none;cursor:pointer}
.share a.primary{background:var(--ink);color:var(--sheet)}
.share a:focus-visible,.share button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.breakdown{list-style:none;margin:0;padding:0;display:flex;flex-wrap:wrap;gap:8px;justify-content:center}
.breakdown li{border:1px solid var(--line);border-radius:6px;padding:4px 10px;font-size:.9rem}
.breakdown li span{font-family:var(--f-kanji);font-size:1.05rem;margin-right:6px}
.breakdown li.ng{border-color:var(--bad)}
/* tips inside the sheet */
.tips{border-top:1px solid var(--line);padding-top:16px;display:flex;flex-direction:column;gap:8px}
.tips h2{margin:0;font-size:1.05rem}
.tips ul{margin:0;padding-left:1.2em;display:flex;flex-direction:column;gap:6px;max-width:66ch}
.seen{margin:0;font-size:.92rem;padding:10px 14px;background:var(--paper);border-radius:6px;max-width:66ch}
.seen b{font-size:.72rem;letter-spacing:.08em;text-transform:uppercase;color:var(--accent);margin-right:8px}
/* explainer */
.explain{display:flex;flex-direction:column;gap:12px}
.explain h2{margin:0;font-size:1.2rem}
.explain p{margin:0;max-width:66ch}
.explain td.k{font-family:var(--f-kanji);font-size:1.4rem}
.explain td span{display:block;font-size:.8rem;color:var(--muted)}
.results-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:10px;text-align:left;width:100%;max-width:640px}
.results-list li{border-left:3px solid var(--good);padding:4px 0 4px 12px;display:flex;flex-direction:column;gap:2px}
.results-list li.ng{border-left-color:var(--bad)}
.rs{font-family:var(--f-kanji);font-size:1.25rem;line-height:2.1}
.re{font-size:.85rem;color:var(--muted)}
.explain-line{display:block;margin-top:6px;font-size:.88rem;color:var(--ink);background:var(--paper);border-radius:6px;padding:6px 10px;text-align:left}
.explain-line b{color:var(--accent)}
#chalTabs{align-self:flex-start}
footer{font-size:.8rem;color:var(--muted);border-top:1px solid var(--line);padding-top:16px}
@media (max-width:640px){
  .sheet{grid-template-columns:1fr;padding:18px}
  .big{margin:0 auto} .big-cap{margin-inline:auto}
  .rd-label{width:100%;padding-top:0}
  .prompt .word{font-size:2.6rem}
  .chal{padding:18px}
  .sent{font-size:1.35rem}
  .sheet th:nth-child(3),.sheet td:nth-child(3){display:none}
  .sheet th,.sheet td{padding-left:6px;padding-right:6px}
  .sheet td.w{font-size:1.1rem;padding-left:10px}
  .sheet td.r{white-space:normal}
  .sheet tr.t-on td.w{box-shadow:inset 3px 0 0 var(--on)}
  .sheet tr.t-kun td.w{box-shadow:inset 3px 0 0 var(--kun)}
  .sheet tr.t-sp td.w{box-shadow:inset 3px 0 0 var(--accent)}
}
@media (prefers-reduced-motion:reduce){.bar div{transition:none}}
.brand a{color:inherit;text-decoration:none}
footer a{color:var(--muted)}
footer .links{display:flex;flex-wrap:wrap;gap:6px 18px;margin:0 0 10px}
.page-text{max-width:66ch;display:flex;flex-direction:column;gap:12px}
.page-text h1,.page-text h2{margin:0}
.page-text a{color:var(--on)}
