/* One centered study column — squared-paper question card, four answer tiles, teacher's red-pen marking */
:root {
  --paper: #f3f5f8;
  --card: #ffffff;
  --ink: #1f2a44;
  --muted: #5d6781;
  --line: #d9dee8;
  --grid: #e7ebf2;
  --shu: #d2452f;
  --shu-soft: #fbe9e5;
  --ai-soft: #e6eaf4;
  --ok: #2f7d4f;
  --ok-soft: #e3f2e8;
  --font-word: "Klee One", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --font-body: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #12172a; --card: #1a2037; --ink: #e8ebf4; --muted: #9ba3bb;
    --line: #2e3654; --grid: #222a45; --shu: #ff6f57; --shu-soft: #3a2126; --ai-soft: #252d4a;
    --ok: #6fcf97; --ok-soft: #1c3328;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); font-family: var(--font-body); font-size: 16px; line-height: 1.6; }
.wrap { max-width: 640px; margin: 0 auto; padding-inline: 16px; padding-block: 20px 48px; display: flex; flex-direction: column; gap: 20px; }
[hidden] { display: none !important; }

/* Header + nav */
header.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { font-family: var(--font-word); font-weight: 600; font-size: 1.6rem; margin: 0; letter-spacing: .02em; }
.level-badge { font-size: .75rem; font-weight: 700; letter-spacing: .08em; color: var(--card); background: var(--ink); padding: 2px 8px; border-radius: 4px; }
nav.tabs { display: flex; gap: 4px; }
nav.tabs button { font: inherit; font-size: .9rem; padding: 6px 12px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); cursor: pointer; }
nav.tabs button[aria-current="page"] { color: var(--ink); border-bottom-color: var(--shu); font-weight: 700; }
.sub { color: var(--muted); font-size: .85rem; margin: 0; }
.demo-banner { font-size: .8rem; background: var(--ai-soft); border: 1px dashed var(--muted); border-radius: 8px; padding: 8px 12px; color: var(--ink); }

/* Panels */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 18px; }
.panel h2 { font-size: 1.05rem; margin: 0; text-wrap: balance; }
.panel h2 small { font-weight: 400; color: var(--muted); font-size: .8rem; margin-left: 6px; }
.panel.danger { border-color: var(--shu); }
.field { display: flex; flex-direction: column; gap: 8px; }
.field-label, label.lbl { font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { font: inherit; font-size: .9rem; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--card); border-color: var(--ink); }
.seg button:disabled { opacity: .45; cursor: not-allowed; }

/* Forms */
form { display: flex; flex-direction: column; gap: 14px; margin: 0; }
input[type="text"], input[type="email"], input[type="password"] {
  font: inherit; font-size: 1rem; width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
}
input:focus-visible { outline: 3px solid var(--shu); outline-offset: 1px; border-color: var(--ink); }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 64px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); font: inherit; font-size: .75rem; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 6px; }
.help { font-size: .75rem; color: var(--muted); margin: 0; }
.msg { font-size: .9rem; margin: 0; padding: 8px 12px; border-radius: 8px; }
.msg.error { background: var(--shu-soft); color: var(--shu); }
.msg.success { background: var(--ok-soft); color: var(--ok); }
.link { font: inherit; font-size: .85rem; background: none; border: 0; padding: 0; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .8rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.btn { font: inherit; font-weight: 700; font-size: 1rem; padding: 11px 22px; border-radius: 8px; border: 1px solid var(--ink); background: var(--ink); color: var(--card); cursor: pointer; }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.small { font-size: .85rem; padding: 7px 14px; }
.btn.danger { background: var(--shu); border-color: var(--shu); color: #fff; }
.btn.google { background: var(--card); color: var(--ink); border-color: var(--line); display: inline-flex; align-items: center; justify-content: center; gap: 10px; font-weight: 500; }
.btn:disabled { opacity: .55; cursor: wait; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.seg button:focus-visible, .btn:focus-visible, .choice:focus-visible, .link:focus-visible, nav.tabs button:focus-visible { outline: 3px solid var(--shu); outline-offset: 2px; }

/* Auth screen */
.auth-hero { text-align: left; display: flex; flex-direction: column; gap: 6px; }
.auth-hero .big { font-family: var(--font-word); font-size: clamp(2.2rem, 10vw, 3rem); font-weight: 600; line-height: 1.3; margin: 0; }
.auth-hero .big ruby rt { font-size: .3em; color: var(--muted); font-weight: 400; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line); margin: -4px 0 4px; }
.auth-tabs button { font: inherit; font-weight: 700; padding: 10px; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer; }
.auth-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--shu); }

/* Quiz */
.progress { display: flex; align-items: center; gap: 12px; font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { flex: 1; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ink); transition: width .25s ease; }
.qcard {
  background-color: var(--card);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px; background-position: center;
  border: 1px solid var(--line); border-radius: var(--radius);
  min-height: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 28px 16px; text-align: center;
}
.qprompt, .qtype { font-size: .8rem; color: var(--muted); background: var(--card); padding: 0 6px; }
.qword { font-family: var(--font-word); font-weight: 600; font-size: clamp(2.4rem, 11vw, 3.6rem); line-height: 1.5; background: var(--card); padding: 0 8px; overflow-wrap: anywhere; }
.qword rt { font-size: .32em; color: var(--muted); font-weight: 400; }
.qmeaning { font-size: clamp(1.5rem, 6vw, 2rem); font-weight: 700; background: var(--card); padding: 0 8px; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 460px) { .choices { grid-template-columns: 1fr; } }
.choice { position: relative; font: inherit; text-align: left; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 14px 52px 14px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; transition: border-color .15s, background .15s; }
.choice:hover:not(:disabled) { border-color: var(--ink); }
.choice:disabled { cursor: default; }
.choice .key { flex: none; width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center; font-size: .75rem; color: var(--muted); }
.choice .txt { min-width: 0; overflow-wrap: anywhere; font-size: 1.05rem; }
.choice .txt.jp { font-family: var(--font-word); font-weight: 600; font-size: 1.35rem; }
.choice .txt.jp small { display: block; font-family: var(--font-body); font-weight: 400; font-size: .75rem; color: var(--muted); }
.choice.correct { border-color: var(--shu); background: var(--shu-soft); }
.choice.wrong { background: var(--ai-soft); color: var(--muted); }
.mark { position: absolute; right: 10px; top: 50%; width: 38px; height: 38px; transform: translateY(-50%); pointer-events: none; }
.mark circle, .mark path { fill: none; stroke: var(--shu); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 120; stroke-dashoffset: 120; animation: draw .4s ease-out forwards; }
.mark.x path { stroke: var(--muted); }
@keyframes draw { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .mark circle, .mark path { animation: none; stroke-dashoffset: 0; } .bar i { transition: none; } }
.feedback { min-height: 3.2em; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.feedback p { margin: 0; font-size: .95rem; }
.feedback .ok { color: var(--shu); font-weight: 700; }
.hint-keys { font-size: .75rem; color: var(--muted); }

/* Results */
.score { display: flex; align-items: baseline; gap: 10px; }
.score strong { font-family: var(--font-word); font-size: 3.4rem; line-height: 1; color: var(--shu); font-variant-numeric: tabular-nums; }
.score span { color: var(--muted); font-variant-numeric: tabular-nums; }
.review { list-style: none; margin: 0; padding: 0; }
.review li { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.review .w { font-family: var(--font-word); font-weight: 600; font-size: 1.2rem; }
.review .w small, .review .m small { display: block; font-family: var(--font-body); font-weight: 400; font-size: .75rem; color: var(--muted); }
.saved-note { font-size: .8rem; color: var(--muted); margin: 0; }

/* Account */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 12px; border-radius: 8px; background: var(--paper); min-width: 0; }
.stat b { font-family: var(--font-word); font-size: 1.6rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { font-size: .72rem; color: var(--muted); }
.history { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.history th { text-align: left; font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--line); }
.history td { padding: 8px 8px 8px 0; border-bottom: 1px solid var(--line); }
.history td.num { text-align: right; }
.table-wrap { overflow-x: auto; }
.pill { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--shu-soft); color: var(--shu); }
.kv { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; align-items: center; }
.kv .v { overflow-wrap: anywhere; }
.empty { color: var(--muted); font-size: .9rem; margin: 0; }
.note { font-size: .8rem; color: var(--muted); margin: 0; }
.loading { color: var(--muted); text-align: center; padding: 48px 0; }

/* ---------- Admin additions ---------- */
.wrap.wide { max-width: 960px; }
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .88em; background: var(--ai-soft); padding: 1px 5px; border-radius: 4px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
.opt { font-weight: 400; text-transform: none; letter-spacing: 0; }
.issued { border: 1px solid var(--ok); background: var(--ok-soft); border-radius: 8px; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.issued-title { margin: 0; font-weight: 700; color: var(--ok); }
.issued pre { margin: 0; padding: 12px; background: var(--card); border-radius: 6px; border: 1px solid var(--line); font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .85rem; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink); }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.count { font-size: .8rem; font-weight: 400; color: var(--muted); font-variant-numeric: tabular-nums; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; }
.filters input { flex: 1 1 220px; }
input[type="search"], select { font: inherit; font-size: .95rem; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); min-width: 0; }
select { flex: 0 1 220px; }
.learners tbody tr { cursor: pointer; }
.learners tbody tr:hover td, .learners tbody tr:focus-visible td { background: var(--paper); }
.learners tbody tr:focus-visible { outline: 3px solid var(--shu); outline-offset: -3px; }
.learners td { white-space: nowrap; }
.learners td.name { white-space: normal; min-width: 140px; }
.learners td.name small { display: block; color: var(--muted); font-size: .75rem; }
.learners .low { color: var(--shu); font-weight: 700; }
.pill.off { background: var(--ai-soft); color: var(--muted); }
.kv-list { margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px 16px; }
.kv-list dt { font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.kv-list dd { margin: 0; overflow-wrap: anywhere; }
.weak { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.weak li { display: flex; align-items: baseline; gap: 8px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
.weak .w { font-family: var(--font-word); font-weight: 600; font-size: 1.15rem; }
.weak .m { font-size: .8rem; color: var(--muted); }
.weak .n { font-size: .75rem; font-weight: 700; color: var(--shu); font-variant-numeric: tabular-nums; }
.rule { border: 0; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }
.history th.num { text-align: right; }

/* ---------- Practice test (問題集) ---------- */
.qcard.exam { align-items: stretch; text-align: left; gap: 12px; background-image: none; min-height: 0; }
.exam-inst { display: flex; flex-direction: column; gap: 2px; }
.exam-inst .ja { font-weight: 700; font-size: .95rem; }
.exam-inst .tr { font-size: .8rem; color: var(--muted); }
.exam-tag { align-self: flex-start; font-size: .7rem; font-weight: 700; letter-spacing: .06em; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; }
.exam-q { font-family: var(--font-word); font-size: clamp(1.15rem, 4.6vw, 1.45rem); font-weight: 600; line-height: 2; white-space: pre-line; overflow-wrap: anywhere; padding: 12px 14px; border-radius: 8px; background: var(--paper); }
.exam-q u { text-decoration: none; border-bottom: 2px solid var(--ink); padding-bottom: 1px; }
.exam-q .blank { display: inline-block; min-width: 3.2em; border-bottom: 2px solid var(--muted); margin: 0 .15em; height: 1.1em; vertical-align: baseline; }
.exam-q .blank.star { color: var(--shu); text-align: center; border-bottom-color: var(--shu); line-height: 1.1em; font-size: .9em; }
.exam-q .yoho-word { font-size: 1.6em; }
.choice .txt.ex { font-family: var(--font-word); font-weight: 600; font-size: 1.05rem; line-height: 1.6; }
.choices.long { grid-template-columns: 1fr; }
.explain { margin: 0; padding: 12px 14px; border-radius: 8px; background: var(--ai-soft); display: flex; flex-direction: column; gap: 6px; font-size: .95rem; }
.explain .jp { font-family: var(--font-word); font-weight: 600; font-size: 1.05rem; }
.explain b { font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.review li.exam-rev { grid-template-columns: 1fr; gap: 4px; }
.review li.exam-rev .q { font-family: var(--font-word); font-weight: 600; white-space: pre-line; }
.review li.exam-rev .q u { text-decoration: none; border-bottom: 2px solid var(--ink); }
.review li.exam-rev .a { font-size: .9rem; }
.review li.exam-rev .a small { display: block; color: var(--muted); }
.reset-confirm { display: flex; flex-direction: column; gap: 10px; padding: 12px 14px; border-radius: 8px; border: 1px solid var(--shu); background: var(--shu-soft); }
.reset-confirm small { color: var(--muted); }

/* Admin: preview video URLs */
.vid-list { list-style: none; margin: 8px 0 12px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.vid-list li { display: grid; grid-template-columns: 2.2rem 1fr; gap: 4px 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.vid-list .vid-n { grid-row: span 2; font-weight: 700; text-align: center; }
.vid-list .vid-t { font-size: .92rem; }
.vid-list .vid-t small { color: var(--muted, #5D6781); margin-left: 6px; }
.vid-list .vid-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.vid-list input { flex: 1; min-width: 12rem; }
.vid-list .vid-test { color: var(--muted, #5D6781); font-size: .88rem; }

/* Teacher accounts: show only the fields that apply */
.teacher-only { display: none !important; }
.is-teacher .teacher-only { display: revert !important; }
.is-teacher .learner-only { display: none !important; }
.pill.teacher { background: #E6EAF4; color: #1F2A44; }

/* product name fits on one line on phones */
.brand h1 { white-space: nowrap; }
.level-badge { white-space: nowrap; }
@media (max-width: 480px) { .brand h1 { font-size: 1.3rem; } }
