:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1d2433;
  --muted: #667085;
  --line: #e1e5ee;
  --accent: #2f5bea;
  --accent-soft: #e8eefe;
  --ok: #138a52;
  --ok-soft: #e3f6ec;
  --ng: #d03b3b;
  --ng-soft: #fdeaea;
  --warn: #b7791f;
  --hero1: #2f5bea;
  --hero2: #6a3fd8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151d;
    --card: #1a202b;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --line: #2c3442;
    --accent: #7b9cff;
    --accent-soft: #232f4d;
    --ok: #4cc38a;
    --ok-soft: #173327;
    --ng: #f07070;
    --ng-soft: #3a1f22;
    --hero1: #2747b8;
    --hero2: #5130a8;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.75;
}
.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3, h4 { line-height: 1.4; margin: 0 0 .5em; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
h3 small, h2 small { font-weight: normal; color: var(--muted); font-size: .8rem; margin-left: .5em; }
a { color: var(--accent); }
table { border-collapse: collapse; margin: .6em 0; }
th, td { border: 1px solid var(--line); padding: .3em .8em; text-align: center; }
th { background: var(--accent-soft); }
.ov { text-decoration: overline; }
/* 否定が入れ子のとき（例 Q→P̄ 全体の否定）は外側の線を一段上に引いて重ならないようにする */
.ov:has(.ov) { text-decoration: none; border-top: 1px solid currentColor; padding-top: 3px; }
pre { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow-x: auto; font-size: .9rem; line-height: 1.6; }
.q-body table, .explain table { display: block; overflow-x: auto; max-width: 100%; }

/* ヘッダーとカウントダウン */
.site-header { padding: 20px 0 8px; }
.logo { font-size: 1.4rem; margin: 0; }
.tagline { margin: 0; color: var(--muted); font-size: .9rem; }

.countdown {
  margin-top: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 16px;
  background: linear-gradient(135deg, var(--hero1), var(--hero2));
  color: #fff;
  border-radius: 16px;
  padding: 20px 24px;
  max-width: 828px;
}
.cd-label { margin: 0; font-weight: bold; }
.cd-num { margin: 0; display: flex; align-items: baseline; gap: 6px; }
.cd-num b { font-size: 4rem; line-height: 1.1; letter-spacing: -.02em; }
.cd-num span { font-size: 1.1rem; font-weight: bold; }
.cd-note { margin: 4px 0 0; font-size: .85rem; opacity: .9; }
.cd-schedule { list-style: none; margin: 0; padding: 0; align-self: center; }
.cd-schedule li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, .25);
  font-size: .9rem;
}
.cd-schedule li:last-child { border-bottom: 0; }
.cd-schedule .ev { font-weight: bold; }
.cd-schedule .st {
  font-size: .75rem;
  padding: 1px 8px;
  border-radius: 99px;
  background: rgba(255, 255, 255, .2);
  white-space: nowrap;
}
.cd-schedule .now .st { background: #ffd84d; color: #3d2e00; font-weight: bold; }
.cd-schedule .past { opacity: .55; }

/* タブ */
.tabs {
  display: flex;
  gap: 4px;
  margin-top: 20px;
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding-top: 6px;
  padding-bottom: 6px;
}
.tabs a {
  flex: 1;
  text-align: center;
  padding: 10px 8px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--muted);
  font-weight: bold;
  background: var(--card);
  border: 1px solid var(--line);
}
.tabs a small { display: block; font-weight: normal; font-size: .7rem; line-height: 1.2; }
.tabs a[aria-selected="true"] { color: #fff; background: var(--accent); border-color: var(--accent); }

/* カード */
main { padding-top: 8px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.lead { color: var(--muted); margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0 18px; }
.stats div { background: var(--accent-soft); border-radius: 10px; padding: 8px; text-align: center; }
.stats b { display: block; font-size: 1.4rem; line-height: 1.3; }
.stats span { font-size: .75rem; color: var(--muted); }

.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.field span { display: block; font-size: .85rem; font-weight: bold; margin-bottom: 4px; }
select, textarea {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
textarea { resize: vertical; margin: 6px 0 10px; }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 18px; }
.actions.end { justify-content: flex-end; border-top: 1px solid var(--line); padding-top: 16px; }
.pool { color: var(--muted); font-size: .9rem; }

.btn {
  font: inherit;
  font-weight: bold;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.link {
  font: inherit;
  font-size: .9rem;
  background: none;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  padding: 4px 0;
}
.link.danger { color: var(--ng); margin-top: 14px; font-size: .8rem; }

/* 出題画面 */
.quiz-head { display: flex; justify-content: space-between; align-items: center; }
.progress { font-weight: bold; }
.bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 8px 0 14px; }
.bar i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.meta { font-size: .85rem; color: var(--muted); margin: 0 0 10px; }
.sep { margin: 0 .5em; opacity: .5; }
.badge {
  display: inline-block;
  font-size: .7rem;
  font-weight: bold;
  background: #fff1cc;
  color: #7a5200;
  border-radius: 4px;
  padding: 0 6px;
  margin-right: 6px;
  vertical-align: 1px;
}
.q-body p:first-child { margin-top: 0; }
.figure { max-width: 100%; height: auto; display: block; margin: 10px 0; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.pdf-link { display: inline-block; font-size: .85rem; margin: 2px 0 10px; }

.choices { display: grid; gap: 8px; margin-top: 12px; }
.choices.compact { grid-template-columns: repeat(4, 1fr); }
.choice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}
.choice:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.choice:disabled { cursor: default; }
.choice .kana {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: bold;
  background: var(--accent-soft);
  color: var(--accent);
}
.choices.compact .choice { justify-content: center; }
.choice.correct { border-color: var(--ok); background: var(--ok-soft); }
.choice.correct .kana { background: var(--ok); color: #fff; }
.choice.wrong { border-color: var(--ng); background: var(--ng-soft); }
.choice.wrong .kana { background: var(--ng); color: #fff; }

.feedback { margin-top: 18px; }
.verdict { font-size: 1.2rem; font-weight: bold; margin: 0 0 10px; }
.verdict.ok { color: var(--ok); }
.verdict.ng { color: var(--ng); }
.explain {
  background: var(--bg);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 12px 16px;
}
.explain h3 { font-size: .95rem; color: var(--accent); }
.explain ul { padding-left: 1.3em; }
.tip { background: var(--accent-soft); border-radius: 6px; padding: 6px 10px; font-size: .9rem; }

/* 結果 */
.score { font-size: 1.2rem; margin: 0; }
.score b { font-size: 2.6rem; color: var(--accent); }
.score span { color: var(--muted); font-size: 1rem; margin-left: .3em; }
.review { border-top: 1px solid var(--line); }
.review summary {
  display: grid;
  grid-template-columns: 24px auto 1fr;
  gap: 10px;
  padding: 10px 0;
  cursor: pointer;
  align-items: baseline;
  list-style: none;
}
.review summary::-webkit-details-marker { display: none; }
.review .mark { font-weight: bold; }
.review.ok .mark { color: var(--ok); }
.review.ng .mark { color: var(--ng); }
.review .src { font-size: .85rem; font-weight: bold; white-space: nowrap; }
.review .snip { font-size: .85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.review-body { padding: 0 0 16px 34px; }

/* 午後 */
.pm-list { list-style: none; margin: 0; padding: 0; }
.pm-list li { border-top: 1px solid var(--line); }
.pm-list li.empty { color: var(--muted); padding: 12px 0; }
.pm-list button {
  width: 100%;
  font: inherit;
  color: inherit;
  text-align: left;
  background: none;
  border: 0;
  padding: 12px 4px;
  cursor: pointer;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "src tags" "ttl tags";
  column-gap: 12px;
}
.pm-list button:hover { background: var(--accent-soft); }
.pm-list .src { grid-area: src; font-size: .8rem; color: var(--muted); }
.pm-list .ttl { grid-area: ttl; font-weight: bold; }
.pm-list .tags { grid-area: tags; align-self: center; display: flex; gap: 8px; align-items: center; }
.tag { font-size: .75rem; background: var(--accent-soft); color: var(--accent); border-radius: 99px; padding: 1px 10px; white-space: nowrap; }
.marks { font-size: .8rem; letter-spacing: .1em; color: var(--muted); }
.pm-title { margin-bottom: 4px; }
.pm-intro { border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 8px; }
.pm-pages { margin: 4px 0 16px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.pm-pages summary { cursor: pointer; padding: 10px 14px; font-weight: bold; background: var(--accent-soft); }
.pm-pages summary small { font-weight: normal; color: var(--muted); margin-left: .8em; font-size: .75rem; }
.pm-pages img { display: block; width: 100%; height: auto; background: #fff; border-top: 1px solid var(--line); }
.part { padding: 14px 0; border-top: 1px dashed var(--line); }
.part:first-of-type { border-top: 0; }
.answer h4 { font-size: .9rem; color: var(--accent); margin: 12px 0 4px; }
.model { background: var(--ok-soft); border-radius: 8px; padding: 8px 14px; font-weight: bold; }
.model p { margin: 0; }
.self { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: .9rem; color: var(--muted); }
.grade {
  font: inherit;
  width: 40px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}
.grade.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* PDF */
.pdf-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.pdf-grid .card { margin: 0; }
.exam-card .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.exam-card h4 { font-size: .85rem; color: var(--muted); margin: 0 0 6px; }
.file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  margin-bottom: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  font-size: .85rem;
}
.file:hover { border-color: var(--accent); background: var(--accent-soft); }
.file .ico { font-size: .6rem; font-weight: bold; background: var(--ng); color: #fff; border-radius: 3px; padding: 1px 4px; }
.empty-state { text-align: center; padding: 40px 20px; }

/* ヘッダーの利用者名 */
.header-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.user-chip { flex: none; margin-top: 4px; font-size: .85rem; font-weight: bold; }
.user-chip a { display: inline-block; padding: 4px 12px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); text-decoration: none; }

/* 入力欄 */
input[type=text], input:not([type]) {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
.stack { display: grid; gap: 12px; }
.note { font-size: .8rem; color: var(--muted); background: var(--bg); border-radius: 8px; padding: 8px 12px; margin: 0; }
.form-error { color: var(--ng); font-size: .85rem; font-weight: bold; margin: 0; }

/* 初回登録 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(15, 20, 30, .55);
  display: grid;
  place-items: center;
  padding: 16px;
  overflow-y: auto;
}
.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--card);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.modal-card .actions { margin-top: 4px; }
.restore { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; font-size: .9rem; }
.restore summary { cursor: pointer; color: var(--accent); }
.restore form { margin-top: 12px; }

/* 学習記録のグラフ */
:root { --bar-ok: var(--accent); --bar-ng: #b9c7f4; }
@media (prefers-color-scheme: dark) { :root { --bar-ok: #7b9cff; --bar-ng: #3a4c86; } }
.chart-title { margin: 20px 0 4px; }
.legend { display: flex; gap: 16px; font-size: .8rem; color: var(--muted); margin-bottom: 4px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.sw.ok { background: var(--bar-ok); }
.sw.ng { background: var(--bar-ng); }
.chart-box { position: relative; }
.chart { display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--muted); stroke-width: 1; opacity: .5; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar-ok { fill: var(--bar-ok); }
.chart .bar-ng { fill: var(--bar-ng); }
.chart .hit { fill: transparent; }
.chart .hit.on { fill: var(--accent-soft); }
.chart-tip {
  position: absolute;
  transform: translate(-50%, -100%);
  pointer-events: none;
  background: var(--text);
  color: var(--card);
  font-size: .78rem;
  line-height: 1.5;
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
}
.chart-tip b, .chart-tip span { display: block; }
.cats { display: grid; gap: 8px; }
.cat-row { display: grid; grid-template-columns: 9.5em minmax(0, 1fr) 6.5em; align-items: center; gap: 10px; font-size: .85rem; }
.cat-track { height: 10px; background: var(--accent-soft); border-radius: 99px; overflow: hidden; }
.cat-track i { display: block; height: 100%; background: var(--bar-ok); border-radius: 99px; }
.cat-val { font-weight: bold; font-variant-numeric: tabular-nums; }
.cat-val small { font-weight: normal; color: var(--muted); margin-left: 6px; }
.rec-table { margin-top: 16px; font-size: .85rem; }
.rec-table summary { cursor: pointer; color: var(--accent); }
.rec-table table { width: 100%; font-variant-numeric: tabular-nums; }

/* ほかの人の記録 */
.friend-list { list-style: none; margin: 0; padding: 0; }
.friend-list > li { border-top: 1px solid var(--line); padding: 12px 0; }
.friend-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.friend-name { font-weight: bold; }
.unlock { margin-top: 10px; display: grid; gap: 8px; }
.unlock .actions { margin-top: 0; }
.friend-stats:not(:empty) { margin-top: 8px; }

/* 登録情報 */
.account h3 { margin-top: 16px; }
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; min-width: 0; font-family: ui-monospace, Consolas, monospace; font-size: .8rem; }

.site-footer { color: var(--muted); font-size: .78rem; padding-top: 12px; padding-bottom: 40px; }
.site-footer p { margin: 4px 0; }

@media (max-width: 640px) {
  .countdown { grid-template-columns: minmax(0, 1fr); padding: 18px; margin-left: 16px; margin-right: 16px; }
  .cd-num b { font-size: 3.2rem; }
  .cd-schedule li { grid-template-columns: 1fr auto; row-gap: 0; }
  .cd-schedule .ev { grid-column: 1 / -1; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .form { grid-template-columns: minmax(0, 1fr); }
  .pdf-grid { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 16px; }
  .review-body { padding-left: 0; }
  .review summary { grid-template-columns: 24px 1fr; }
  .review .snip { grid-column: 2; }
  .pm-list button { grid-template-columns: minmax(0, 1fr); grid-template-areas: "src" "ttl" "tags"; }
  .tabs a { padding: 8px 4px; font-size: .9rem; }
  .cat-row { grid-template-columns: minmax(0, 1fr) 6.5em; }
  .cat-label { grid-column: 1 / -1; }
  .code-row { flex-wrap: wrap; }
}
