/* Lemma — サイト全体のスタイル。色・書体・形は tokens.css の変数だけを使う。 */
@import url("tokens.css");

/* ---------- 基本 ---------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 76px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 16.5px;
  line-height: 1.85;
  overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "palt" 0;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 0.2em; }
img, svg { vertical-align: middle; }
button { font: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: 6px; }
[hidden] { display: none !important; }
::selection { background: color-mix(in srgb, var(--primary) 22%, transparent); }

.wrap { max-width: 72rem; margin: 0 auto; padding: 0 20px; }
.wrap.narrow { max-width: 46rem; }
.skip-link { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--bg-elev); padding: 0.4rem 0.8rem; border-radius: var(--radius-2); }
.skip-link:focus { left: 8px; }
.icon { flex: none; }

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  margin: 0 0 0.5rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--fg-3);
}
.lv-dot { width: 0.6em; height: 0.6em; border-radius: 50%; background: var(--lvc, var(--primary)); }
.display { font-family: var(--font-serif); font-weight: 700; letter-spacing: 0.01em; line-height: 1.25; }
.lead { font-size: 1.08rem; color: var(--fg-2); line-height: 1.9; }

/* ステージ 1 算数・2 中学・3 高校・4 大学の基礎・5 学部専門・6 大学院・7 総合演習 */
.lv1 { --lvc: var(--lv0); }
.lv2 { --lvc: var(--lv5); }
.lv3 { --lvc: var(--lv6); }
.lv4 { --lvc: var(--lv1); }
.lv5 { --lvc: var(--lv2); }
.lv6 { --lvc: var(--lv3); }
.lv7 { --lvc: var(--lv4); }

/* ---------- ボタン ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: var(--bg-elev);
  color: var(--fg);
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.3;
  cursor: pointer;
  text-decoration: none !important;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.12s var(--ease), box-shadow 0.15s var(--ease);
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); box-shadow: 0 6px 18px color-mix(in srgb, var(--primary) 28%, transparent); }
.btn-primary:hover { background: var(--primary-2); border-color: var(--primary-2); }
.btn-lg { padding: 0.8rem 1.5rem; font-size: 1.02rem; }
.btn-sm { padding: 0.38rem 0.85rem; font-size: 0.85rem; }
.btn-quiet { background: transparent; border-color: transparent; color: var(--fg-2); }
.btn-quiet:hover { background: var(--bg-hover); color: var(--fg); }
.btn-danger-quiet { background: transparent; border-color: transparent; color: var(--bad); }
.btn-danger-quiet:hover { background: var(--bad-soft); }
.btn[aria-pressed="true"].btn-complete, .btn-complete.is-done { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 40%, transparent); color: var(--good); box-shadow: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1rem; }
.cta-row { display: flex; flex-wrap: wrap; gap: 0.7rem; margin-top: 1.6rem; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 0;
  background: transparent;
  color: var(--fg-2);
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--fg); }

/* ---------- ヘッダー ---------- */

.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { display: flex; align-items: center; gap: 0.75rem; height: 60px; max-width: 90rem; margin: 0 auto; padding: 0 16px; }
.brand { display: inline-flex; align-items: center; gap: 0.5rem; color: var(--fg); text-decoration: none !important; flex: none; }
.brand-mark { color: var(--primary); }
.brand-name { font-family: var(--font-display); font-size: 1.35rem; font-weight: 600; letter-spacing: 0.01em; }
.brand-sub { font-size: 0.74rem; color: var(--fg-3); font-weight: 600; letter-spacing: 0.04em; padding-left: 0.6rem; border-left: 1px solid var(--line-2); }
.topnav { display: flex; gap: 0.15rem; margin-left: 1rem; }
.topnav a {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  color: var(--fg-2);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none !important;
}
.topnav a:hover { background: var(--bg-hover); color: var(--fg); }
.topnav a[aria-current="page"] { color: var(--primary); background: var(--primary-soft); }
.topnav a.nav-pro .icon { color: var(--accent); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 0.35rem; }
.search-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  height: 38px;
  padding: 0 0.6rem 0 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--fg-3);
  font-size: 0.88rem;
  cursor: pointer;
  min-width: 11rem;
}
.search-btn:hover { border-color: var(--line-2); color: var(--fg-2); }
.search-btn kbd { margin-left: auto; font-family: var(--font-mono); font-size: 0.75rem; padding: 0 0.4rem; border: 1px solid var(--line); border-radius: 5px; color: var(--fg-3); }
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: block; }
  :root:not([data-theme="light"]) .icon-moon { display: none; }
}
.streak-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25em;
  height: 32px;
  padding: 0 0.7rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  font-size: 0.88rem;
  text-decoration: none !important;
  font-variant-numeric: tabular-nums;
}
.menu-btn { display: none; }
.readbar { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; }
.readbar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--accent)); transition: width 0.1s linear; }

.tabbar { display: none; }

@media (max-width: 1080px) {
  .brand-sub { display: none; }
  .search-btn { min-width: 0; }
  .search-btn .search-label, .search-btn kbd { display: none; }
  .search-btn { width: 38px; padding: 0; justify-content: center; border-color: transparent; background: transparent; }
}
@media (max-width: 760px) {
  .topnav { display: none; }
  .topbar-inner { height: 54px; gap: 0.4rem; padding: 0 10px; }
  .tabbar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a { display: grid; justify-items: center; gap: 1px; padding: 0.45rem 0 0.4rem; font-size: 0.68rem; font-weight: 700; color: var(--fg-3); text-decoration: none !important; }
  .tabbar a[aria-current="page"] { color: var(--primary); }
  body { padding-bottom: calc(58px + env(safe-area-inset-bottom)); }
}

/* ---------- セクション共通 ---------- */

.section { padding: 4.5rem 0; }
.section + .section { padding-top: 1.5rem; }
.section-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 1.6rem; }
.section-head h2 { font-family: var(--font-serif); font-size: clamp(1.6rem, 3vw, 2.1rem); margin: 0; line-height: 1.3; }
.section-lead { margin: 0.5rem 0 0; color: var(--fg-2); max-width: 44rem; }
.page-hero { padding: 3rem 0 1.5rem; }
.page-hero h1 { font-family: var(--font-serif); font-size: clamp(1.9rem, 4vw, 2.6rem); margin: 0 0 0.5rem; line-height: 1.25; }
.page-hero .lead { margin: 0; max-width: 42rem; }

.panel {
  min-width: 0;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-4);
  padding: 1.25rem 1.4rem;
  box-shadow: var(--shadow-1);
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 0.9rem; }
.panel-head h2 { font-size: 1.05rem; margin: 0; }
.panel-head h3 { font-size: 0.95rem; margin: 0; color: var(--fg-2); }
.panel-head.sub { margin-top: 1.4rem; }
.panel-head a { font-size: 0.85rem; font-weight: 700; display: inline-flex; align-items: center; gap: 0.2em; }
.panel-note { font-size: 0.8rem; color: var(--fg-3); }
.panel-text { color: var(--fg-2); font-size: 0.93rem; margin: 0 0 0.8rem; }

.stat { display: grid; gap: 0.1rem; }
.stat-value { font-family: var(--font-display); font-size: 2rem; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 0.78rem; color: var(--fg-3); font-weight: 700; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); gap: 1rem 1.5rem; }

/* ---------- ホーム：ヒーロー ---------- */

.hero { padding: 4.5rem 0 3rem; position: relative; overflow: hidden; }
.hero::before {
  content: "";
  position: absolute;
  inset: -20% -10% auto auto;
  width: 60rem;
  height: 40rem;
  background:
    radial-gradient(closest-side, color-mix(in srgb, var(--primary) 12%, transparent), transparent 70%),
    radial-gradient(closest-side at 70% 60%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 70%);
  pointer-events: none;
}
.hero-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 3rem; align-items: center; position: relative; }
.hero h1.display { font-size: clamp(2.4rem, 5vw, 4.1rem); margin: 0.3rem 0 1.1rem; letter-spacing: 0.02em; white-space: nowrap; }
.hero .hl { position: relative; white-space: nowrap; }
.hero .hl::after { content: ""; position: absolute; left: -0.04em; right: -0.04em; bottom: 0.1em; height: 0.22em; background: color-mix(in srgb, var(--accent) 38%, transparent); z-index: -1; border-radius: 2px; }
.hero .lead { max-width: 34rem; }
.hero .lead strong { color: var(--fg); }
/* 7 つのステージの階段（OG 画像と同じ図） */
.hero-stairs { position: relative; }
.hero-stairs svg { display: block; width: 100%; max-width: 34rem; height: auto; margin-left: auto; overflow: visible; }
.stair-path { fill: none; stroke: color-mix(in srgb, var(--fg-3) 55%, transparent); stroke-width: 2.5; stroke-dasharray: 2 7; stroke-linecap: round; }
.stair { cursor: pointer; text-decoration: none; }
.stair-halo { fill: color-mix(in srgb, var(--lvc) 13%, transparent); transition: r 0.2s ease; }
.stair-dot { fill: var(--bg-elev); stroke: var(--lvc); stroke-width: 3.5; transition: fill 0.2s ease; }
.stair-glyph { fill: var(--lvc); font-family: var(--font-display); font-size: 25px; font-weight: 600; text-anchor: middle; transition: fill 0.2s ease; }
.stair-glyph.is-italic { font-style: italic; }
.stair-label { fill: var(--fg-2); font-size: 15px; font-weight: 700; text-anchor: middle; }
.stair:hover .stair-dot, .stair:focus-visible .stair-dot { fill: var(--lvc); }
.stair:hover .stair-glyph, .stair:focus-visible .stair-glyph { fill: var(--bg-elev); }
.stair:hover .stair-halo { r: 38px; }
.stair:focus-visible { outline: none; }
.stair:focus-visible .stair-halo { stroke: var(--lvc); stroke-width: 2; }
.stair { animation: stair-in 0.5s cubic-bezier(.2,.7,.3,1) both; animation-delay: calc(var(--i) * 70ms + 120ms); }
@keyframes stair-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

@media (max-width: 900px) {
  .hero { padding-top: 2.5rem; }
  .hero-grid { grid-template-columns: 1fr; gap: 1.5rem; }
  .hero-stairs svg { max-width: 24rem; margin: 0 auto; }
}

/* どこから始める？ */
.start-finder { position: relative; margin-top: 3rem; }
.start-finder h2 { font-size: 1.05rem; margin: 0 0 0.8rem; }
.start-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.7rem; }
@media (max-width: 1000px) { .start-options { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 620px) { .start-options { grid-template-columns: 1fr; } }
.start-option {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-3);
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--fg);
  text-decoration: none !important;
  transition: border-color 0.15s, transform 0.15s var(--ease), box-shadow 0.15s;
}
.start-option:hover { border-color: var(--lvc); transform: translateY(-1px); box-shadow: var(--shadow-2); }
.start-option .glyph { display: grid; place-items: center; flex: none; width: 2.4rem; height: 2.4rem; border-radius: 12px; background: color-mix(in srgb, var(--lvc) 13%, transparent); color: var(--lvc); font-family: var(--font-math); font-size: 1.1rem; }
.start-option b { display: block; font-size: 0.93rem; line-height: 1.45; }
.start-option small { display: block; color: var(--fg-3); font-size: 0.78rem; line-height: 1.5; }
.start-option .icon { margin-left: auto; color: var(--fg-3); }
.start-note { margin: 0.8rem 0 0; font-size: 0.82rem; color: var(--fg-3); }

/* ---------- ホーム：おかえり（学習中の人向け） ---------- */

.welcome { padding: 2.5rem 0 1rem; }
.welcome-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.welcome-title { font-family: var(--font-serif); font-size: clamp(1.7rem, 4vw, 2.3rem); margin: 0; line-height: 1.3; }
.today-stats { display: flex; gap: 1.8rem; flex-wrap: wrap; }
.today-stats .stat-value { font-size: 1.7rem; }
.welcome-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; }
.continue-card {
  display: grid;
  align-content: start;
  gap: 0.35rem;
  padding: 1.4rem 1.5rem;
  border-radius: var(--radius-4);
  color: var(--on-primary);
  background: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--primary) 70%, var(--lv3)));
  box-shadow: 0 14px 34px color-mix(in srgb, var(--primary) 30%, transparent);
  text-decoration: none !important;
  min-height: 11rem;
  position: relative;
  overflow: hidden;
}
.continue-card::after { content: "∎"; position: absolute; right: 1.2rem; bottom: -0.6rem; font-size: 7rem; line-height: 1; opacity: 0.12; font-family: var(--font-math); }
.continue-label { display: inline-flex; align-items: center; gap: 0.4em; font-size: 0.8rem; font-weight: 800; letter-spacing: 0.06em; opacity: 0.9; }
.continue-subject { font-size: 0.85rem; opacity: 0.85; font-weight: 600; }
.continue-title { font-family: var(--font-serif); font-size: 1.4rem; font-weight: 700; line-height: 1.4; }
.continue-bar { margin-top: auto; height: 6px; border-radius: 999px; background: rgb(255 255 255 / 0.25); overflow: hidden; }
.continue-bar span { display: block; height: 100%; width: 0; background: #fff; border-radius: inherit; }
.next-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.next-list a { display: flex; align-items: center; gap: 0.7rem; padding: 0.55rem 0.7rem; border-radius: var(--radius-2); border: 1px solid var(--line); color: var(--fg); text-decoration: none !important; font-size: 0.9rem; font-weight: 600; line-height: 1.4; }
.next-list a:hover { background: var(--bg-hover); }
.next-list .glyph { display: grid; place-items: center; width: 2rem; height: 2rem; border-radius: 50%; flex: none; font-family: var(--font-math); background: color-mix(in srgb, var(--lvc) 14%, transparent); color: var(--lvc); font-size: 0.95rem; }
.next-list small { display: block; color: var(--fg-3); font-weight: 600; font-size: 0.75rem; }
@media (max-width: 960px) { .welcome-grid { grid-template-columns: 1fr 1fr; } .continue-card { grid-column: 1 / -1; } }
@media (max-width: 600px) { .welcome-grid { grid-template-columns: minmax(0, 1fr); } .today-stats { gap: 1.1rem; } }

/* 学習カレンダー（ヒートマップ） */
.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 3px; overflow-x: auto; padding-bottom: 4px; justify-content: start; }
.heatmap i { display: block; width: 12px; height: 12px; border-radius: 3px; background: var(--bg-sunken); outline: 1px solid color-mix(in srgb, var(--fg) 5%, transparent); outline-offset: -1px; }
.heatmap i[data-l="1"] { background: color-mix(in srgb, var(--primary) 30%, var(--bg-sunken)); }
.heatmap i[data-l="2"] { background: color-mix(in srgb, var(--primary) 55%, var(--bg-sunken)); }
.heatmap i[data-l="3"] { background: color-mix(in srgb, var(--primary) 80%, var(--bg-sunken)); }
.heatmap i[data-l="4"] { background: var(--primary); }
.heatmap i[data-today] { box-shadow: 0 0 0 2px var(--accent); }
.heatmap-mini i { width: 14px; height: 14px; }

/* ---------- ロードマップ ---------- */

.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; list-style: none; margin: 0; padding: 0; font-size: 0.82rem; color: var(--fg-2); font-weight: 600; }
.legend li { display: inline-flex; align-items: center; gap: 0.4em; }
.legend li::before { content: ""; width: 0.75em; height: 0.75em; border-radius: 50%; background: var(--lvc); }
.roadmap { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-4); box-shadow: var(--shadow-1); position: relative; }
.roadmap-scroll { overflow-x: auto; overscroll-behavior-x: contain; }
.roadmap-svg { display: block; width: 100%; min-width: 880px; height: auto; margin: 0 auto; }
.roadmap-compact .roadmap-svg { min-width: 760px; }
.roadmap-hint { display: none; justify-content: center; align-items: center; gap: 0.3rem; font-size: 0.78rem; color: var(--fg-3); margin: 0.5rem 0 0; }
@media (max-width: 900px) { .roadmap-hint { display: flex; } }
.rm-edge { fill: none; stroke: var(--line-2); stroke-width: 1.6; transition: stroke 0.3s, stroke-width 0.3s; }
.rm-edge.is-lit { stroke: color-mix(in srgb, var(--primary) 70%, transparent); stroke-width: 2.2; }
.rm-edge.is-done { stroke: color-mix(in srgb, var(--good) 60%, transparent); }
.rm-arrowhead { fill: var(--line-2); }
.rm-node { cursor: pointer; text-decoration: none !important; }
.rm-node .rm-halo { fill: none; stroke: none; }
.rm-node .rm-disc { fill: var(--bg-elev); stroke: var(--lvc); stroke-width: 2; transition: fill 0.3s; }
.rm-node .rm-track { fill: none; stroke: none; }
.rm-node .rm-prog { fill: none; stroke: var(--lvc); stroke-width: 6; stroke-linecap: round; transition: stroke-dasharray 0.8s var(--ease); }
.rm-node .rm-glyph { text-anchor: middle; font-family: var(--font-math); font-size: 20px; fill: var(--lvc); font-weight: 600; }
.rm-node .rm-num { text-anchor: middle; font-family: var(--font-display); font-size: 12px; fill: var(--fg-3); font-weight: 600; }
.rm-node .rm-label { text-anchor: middle; font-size: 13px; fill: var(--fg); font-weight: 700; }
.rm-node:hover .rm-disc, .rm-node:focus-visible .rm-disc { fill: color-mix(in srgb, var(--lvc) 12%, var(--bg-elev)); }
.rm-node:focus-visible { outline: none; }
.rm-node:focus-visible .rm-halo { stroke: var(--primary); stroke-width: 2; }
.rm-node.is-started .rm-track { stroke: color-mix(in srgb, var(--lvc) 18%, transparent); stroke-width: 6; }
.rm-node.is-done .rm-disc { fill: var(--lvc); }
.rm-node.is-done .rm-glyph { fill: var(--bg-elev); }
.rm-node.is-next .rm-halo { stroke: var(--accent); stroke-width: 2.5; stroke-dasharray: 4 5; animation: rm-spin 12s linear infinite; transform-box: fill-box; transform-origin: center; }
.rm-node.is-dim { opacity: 0.45; }
@keyframes rm-spin { to { transform: rotate(360deg); } }

/* ---------- ホーム：科目カード ---------- */

.level-group { margin-top: 2.2rem; }
.level-head { display: flex; align-items: baseline; gap: 0.7rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.level-head h3 { margin: 0; font-size: 1.15rem; }
.level-chip { font-size: 0.75rem; font-weight: 800; letter-spacing: 0.04em; color: var(--lvc); background: color-mix(in srgb, var(--lvc) 12%, transparent); padding: 0.15rem 0.6rem; border-radius: 999px; }
.level-note { font-size: 0.82rem; color: var(--fg-3); }
.subject-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); gap: 0.9rem; }
.subject-card {
  position: relative;
  display: flex;
  gap: 0.9rem;
  padding: 1.1rem 1.1rem 1.3rem;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-3);
  color: var(--fg);
  text-decoration: none !important;
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease), border-color 0.18s;
  overflow: hidden;
}
.subject-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: color-mix(in srgb, var(--lvc) 40%, var(--line)); }
.sc-glyph {
  display: grid;
  place-items: center;
  flex: none;
  width: 3rem;
  height: 3rem;
  border-radius: 14px;
  background: color-mix(in srgb, var(--lvc) 12%, transparent);
  color: var(--lvc);
  font-family: var(--font-math);
  font-size: 1.35rem;
  font-weight: 600;
}
.sc-body { display: grid; gap: 0.15rem; min-width: 0; }
.sc-num { font-family: var(--font-display); font-size: 0.8rem; color: var(--fg-3); font-weight: 600; }
.sc-title { font-weight: 800; font-size: 1.02rem; line-height: 1.45; }
.sc-desc { font-size: 0.84rem; color: var(--fg-2); line-height: 1.65; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.sc-meta { font-size: 0.78rem; color: var(--fg-3); font-weight: 600; margin-top: 0.3rem; }
.sc-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: transparent; }
.sc-progress span { display: block; height: 100%; width: 0; background: var(--lvc); transition: width 0.8s var(--ease); }
.subject-card.is-done::after { content: "∎ 修了"; position: absolute; top: 0.7rem; right: 0.8rem; font-size: 0.72rem; font-weight: 800; color: var(--good); }

/* ---------- ホーム：特長・CTA ---------- */

.feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 1rem; }
.feature { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-3); padding: 1.3rem 1.3rem 1.2rem; }
.feature h3 { margin: 0.8rem 0 0.4rem; font-size: 1.05rem; display: flex; align-items: center; gap: 0.5rem; }
.feature p { margin: 0; color: var(--fg-2); font-size: 0.9rem; line-height: 1.8; }
.feature a { display: inline-flex; align-items: center; gap: 0.2em; margin-top: 0.7rem; font-weight: 700; font-size: 0.88rem; }
.feature-icon { display: grid; place-items: center; width: 2.6rem; height: 2.6rem; border-radius: 12px; background: var(--primary-soft); color: var(--primary); }
.feature-pro { background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 10%, var(--bg-elev)), var(--bg-elev) 60%); }
.feature-pro .feature-icon { background: var(--accent-soft); color: var(--accent); }
.pro-badge { font-size: 0.68rem; font-weight: 800; letter-spacing: 0.06em; color: var(--on-primary); background: linear-gradient(90deg, var(--accent), var(--seal)); padding: 0.1rem 0.5rem; border-radius: 999px; }
.cta-band { padding-bottom: 5rem; }
.cta-band-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding: 2rem 2.2rem;
  border-radius: var(--radius-4);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  background-image: radial-gradient(circle at 100% 0, color-mix(in srgb, var(--primary) 10%, transparent), transparent 50%);
}
.cta-band-inner h2 { margin: 0 0 0.3rem; font-family: var(--font-serif); font-size: 1.5rem; }
.cta-band-inner p { margin: 0; color: var(--fg-2); }

/* ---------- 科目ページ ---------- */

.subject-hero { padding: 2rem 0 2.2rem; background: linear-gradient(180deg, color-mix(in srgb, var(--lvc) 8%, transparent), transparent); border-bottom: 1px solid var(--line); }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; font-size: 0.82rem; color: var(--fg-3); margin-bottom: 1.2rem; }
.crumbs a { color: var(--fg-2); }
.subject-hero-grid { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 1.6rem; align-items: start; }
.subject-glyph {
  display: grid;
  place-items: center;
  width: 5.5rem;
  height: 5.5rem;
  border-radius: 26px;
  background: var(--bg-elev);
  border: 2px solid color-mix(in srgb, var(--lvc) 45%, transparent);
  color: var(--lvc);
  font-family: var(--font-math);
  font-size: 2.4rem;
  font-weight: 600;
  box-shadow: var(--shadow-2);
}
.subject-hero h1 { font-family: var(--font-serif); font-size: clamp(1.8rem, 4vw, 2.5rem); margin: 0 0 0.6rem; line-height: 1.25; }
.subject-hero .lead { margin: 0 0 1rem; font-size: 1rem; }
.meta-row { display: flex; flex-wrap: wrap; gap: 0.5rem 1.2rem; font-size: 0.85rem; color: var(--fg-2); font-weight: 600; }
.meta-row span, .doc-meta span { display: inline-flex; align-items: center; gap: 0.35em; }
.subject-progress { margin-top: 1.1rem; max-width: 30rem; }
.subject-progress .bar, .mini-progress { height: 8px; border-radius: 999px; background: var(--bg-sunken); overflow: hidden; border: 1px solid var(--line); }
.subject-progress .bar span, .mini-progress span { display: block; height: 100%; width: 0; background: var(--lvc, var(--primary)); border-radius: inherit; transition: width 0.8s var(--ease); }
.subject-progress-label { margin: 0.4rem 0 0; font-size: 0.8rem; color: var(--fg-3); font-weight: 700; }
.subject-hero .cta-row { margin-top: 1.2rem; }
.relations { display: flex; flex-wrap: wrap; gap: 0.8rem 2rem; margin-top: 1.6rem; padding-top: 1.2rem; border-top: 1px dashed var(--line-2); }
.relations > div { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.rel-label { font-size: 0.78rem; color: var(--fg-3); font-weight: 800; margin-right: 0.2rem; }
.subject-chip { display: inline-flex; align-items: center; gap: 0.4em; padding: 0.25rem 0.7rem 0.25rem 0.3rem; border-radius: 999px; background: var(--bg-elev); border: 1px solid var(--line); color: var(--fg); font-size: 0.83rem; font-weight: 700; text-decoration: none !important; }
.subject-chip:hover { border-color: var(--lvc); }
.subject-chip .glyph { display: grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: color-mix(in srgb, var(--lvc) 14%, transparent); color: var(--lvc); font-family: var(--font-math); font-size: 0.85rem; }
.subject-chip.is-done { border-color: color-mix(in srgb, var(--good) 45%, var(--line)); }
.subject-chip.is-done::after { content: "✓"; color: var(--good); font-weight: 900; }
@media (max-width: 600px) {
  .subject-hero-grid { grid-template-columns: 1fr; gap: 1rem; }
  .subject-glyph { width: 4rem; height: 4rem; font-size: 1.8rem; border-radius: 18px; }
}

.subject-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2.5rem; padding-top: 2rem; padding-bottom: 4rem; }
.chapter-section h2 { font-size: 1.2rem; margin: 0 0 0.9rem; }
.chapter-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr)); gap: 0.7rem; }
.chapter-card {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.9rem 1rem;
  border-radius: var(--radius-3);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--fg);
  text-decoration: none !important;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s var(--ease);
  height: 100%;
}
.chapter-card:hover { border-color: var(--primary); box-shadow: var(--shadow-2); transform: translateY(-1px); }
.cc-num { display: grid; place-items: center; flex: none; width: 2.4rem; height: 2.4rem; border-radius: 50%; background: var(--bg-sunken); font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; color: var(--fg-2); }
.cc-main { display: grid; gap: 0.1rem; min-width: 0; flex: 1; }
.cc-title { font-weight: 800; line-height: 1.5; }
.cc-meta { font-size: 0.78rem; color: var(--fg-3); font-weight: 600; display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0.2em; }
.cc-status { flex: none; width: 1.4rem; height: 1.4rem; border-radius: 50%; border: 2px solid var(--line-2); }
.chapter-card.is-reading .cc-status { border-color: var(--accent); background: conic-gradient(var(--accent) var(--p, 30%), transparent 0); }
.chapter-card.is-done .cc-num { background: var(--good-soft); color: var(--good); }
.chapter-card.is-done .cc-status { border-color: var(--good); background: var(--good); box-shadow: inset 0 0 0 3px var(--bg-elev); }
.subject-readme { max-width: 46rem; }
.subject-readme > h2:first-child { margin-top: 0; }

/* ---------- 章ページ（本文レイアウト） ---------- */

.layout-doc { display: grid; grid-template-columns: 290px minmax(0, 1fr); max-width: 90rem; margin: 0 auto; }
.sidebar { position: sticky; top: 60px; height: calc(100vh - 60px); overflow-y: auto; border-right: 1px solid var(--line); scrollbar-width: thin; }
.sidebar-inner { padding: 1.3rem 0.9rem 3rem 1.1rem; }
.sidebar-subject { display: flex; align-items: center; gap: 0.7rem; color: var(--fg); font-weight: 800; line-height: 1.35; text-decoration: none !important; margin-bottom: 0.8rem; }
.sidebar-subject small { display: block; color: var(--fg-3); font-size: 0.72rem; font-weight: 700; }
.sidebar-subject .glyph { display: grid; place-items: center; flex: none; width: 2.5rem; height: 2.5rem; border-radius: 12px; background: color-mix(in srgb, var(--lvc) 13%, transparent); color: var(--lvc); font-family: var(--font-math); font-size: 1.15rem; }
.sidebar .mini-progress { margin: 0 0.2rem 1rem; height: 6px; }
.sidebar .mini-progress span { background: var(--lvc, var(--primary)); }
.sidebar-subject + .mini-progress { --lvc: inherit; }
.sidebar-chapters { list-style: none; margin: 0; padding: 0; font-size: 0.88rem; }
.sidebar-chapters > li > a { display: flex; align-items: flex-start; gap: 0.55rem; padding: 0.42rem 0.55rem; border-radius: var(--radius-2); color: var(--fg-2); line-height: 1.5; text-decoration: none !important; }
.sidebar-chapters > li > a:hover { background: var(--bg-hover); color: var(--fg); }
.sidebar-chapters > li > a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); font-weight: 800; }
.sidebar-chapters .n { flex: none; min-width: 1.2em; font-family: var(--font-display); font-weight: 600; color: var(--fg-3); }
.sidebar-chapters .st { flex: none; width: 9px; height: 9px; margin-top: 0.5em; border-radius: 50%; border: 1.5px solid var(--line-2); }
.sidebar-chapters a.is-reading .st { border-color: var(--accent); background: var(--accent); }
.sidebar-chapters a.is-done .st { border-color: var(--good); background: var(--good); }
.sidebar-toc { list-style: none; margin: 0.2rem 0 0.6rem 1.9rem; padding: 0 0 0 0.6rem; border-left: 2px solid var(--line); font-size: 0.82rem; }
.sidebar-toc a { display: block; padding: 0.22rem 0.4rem; color: var(--fg-3); line-height: 1.5; border-radius: 6px; text-decoration: none !important; }
.sidebar-toc a:hover { color: var(--fg); }
.sidebar-toc a.is-active { color: var(--primary); font-weight: 700; background: color-mix(in srgb, var(--primary) 7%, transparent); }
.drawer-scrim { display: none; }

.doc { padding: 1.8rem clamp(16px, 4vw, 3.5rem) 4rem; min-width: 0; }
.doc > * { max-width: 47rem; margin-left: auto; margin-right: auto; }
.doc-standalone { padding-top: 2.5rem; }
.doc-head { margin-bottom: 2rem; padding-bottom: 1.4rem; border-bottom: 1px solid var(--line); }
.doc-head h1 { font-family: var(--font-serif); font-size: clamp(1.75rem, 4vw, 2.35rem); line-height: 1.3; margin: 0.2rem 0 0.8rem; }
.doc-meta { display: flex; flex-wrap: wrap; gap: 0.4rem 1.1rem; font-size: 0.85rem; color: var(--fg-3); font-weight: 600; }
.doc-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 1rem; }

@media (max-width: 1100px) {
  .layout-doc { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: inline-grid; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: auto;
    width: min(88vw, 330px);
    z-index: 60;
    background: var(--bg-elev);
    box-shadow: var(--shadow-3);
    transform: translateX(-105%);
    transition: transform 0.28s var(--ease);
    border-right: 0;
  }
  body.drawer-open .sidebar { transform: none; }
  body.drawer-open .drawer-scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgb(10 12 18 / 0.4); }
  .sidebar-inner { padding-top: 1.2rem; padding-bottom: 5rem; }
}

/* ---------- 本文（prose） ---------- */
/* 実験ラボ（.lab）の中には本文のスタイルを及ぼさない（:where で詳細度は上げない） */

.prose { font-size: 1.03rem; line-height: 1.95; }
.prose > :first-child { margin-top: 0; }
.prose h1:not(:where(.lab *)) { font-family: var(--font-serif); font-size: 2rem; line-height: 1.3; margin: 0 0 1.4rem; }
.prose h2:not(:where(.lab *)) { font-family: var(--font-serif); font-size: 1.5rem; line-height: 1.4; margin: 3.2rem 0 1rem; padding-bottom: 0.4rem; border-bottom: 1px solid var(--line); scroll-margin-top: 80px; }
.prose h3:not(:where(.lab *)) { font-size: 1.15rem; line-height: 1.5; margin: 2.2rem 0 0.8rem; scroll-margin-top: 80px; }
.prose h4:not(:where(.lab *)) { font-size: 1rem; margin: 1.8rem 0 0.6rem; }
.prose p:not(:where(.lab *)) { margin: 1rem 0; }
.prose ul:not(:where(.lab *)), .prose ol:not(:where(.lab *)) { padding-left: 1.5em; margin: 1rem 0; }
.prose li:not(:where(.lab *)) { margin: 0.35rem 0; }
.prose li:not(:where(.lab *)) > p { margin: 0.3rem 0; }
.prose hr:not(:where(.lab *)) { border: 0; border-top: 1px solid var(--line); margin: 2.8rem 0; }
.prose strong { font-weight: 800; }
.prose a:not(:where(.lab *)) { text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--primary) 35%, transparent); text-underline-offset: 0.2em; }
.prose a:not(:where(.lab *)):hover { text-decoration-color: var(--primary); }
.prose code:not(:where(.lab *)) { font-family: var(--font-mono); font-size: 0.88em; background: var(--bg-sunken); padding: 0.12em 0.4em; border-radius: 5px; }
.prose pre:not(:where(.lab *)) { background: var(--bg-sunken); padding: 0.9rem 1.1rem; border-radius: var(--radius-2); overflow-x: auto; line-height: 1.55; border: 1px solid var(--line); }
.prose pre code { background: none; padding: 0; }
.prose table:not(:where(.lab *)) { display: block; overflow-x: auto; border-collapse: collapse; margin: 1.4rem 0; font-size: 0.92rem; max-width: 100%; }
.prose th:not(:where(.lab *)), .prose td:not(:where(.lab *)) { border: 1px solid var(--line); padding: 0.45rem 0.75rem; vertical-align: top; }
.prose th:not(:where(.lab *)) { background: var(--bg-sunken); text-align: left; font-weight: 800; }
.prose tr:nth-child(even) td:not(:where(.lab *)) { background: color-mix(in srgb, var(--bg-sunken) 45%, transparent); }
.prose input[type="checkbox"] { accent-color: var(--primary); }
.center { text-align: center; }

/* 数式 */
.math-display { overflow-x: auto; overflow-y: hidden; margin: 1.1rem 0; padding: 0.2rem 0; scrollbar-width: thin; }
.katex { font-size: 1.07em; }
.katex-display { margin: 0.4rem 0; }
/* 文中の大きな分数（P1〜P6）：かっこなどと接しないよう左右に、行が続いても上下の分数が重ならないよう行の上に、余白をとる */
.frac-big { margin-inline: 0.15em; }
.frac-big .strut { margin-top: 0.35em; }
/* 本文の図（<科目>/img/*.svg）。段落に図だけがあるときは中央に置く */
.prose p > img:only-child { display: block; max-width: min(100%, 640px); height: auto; margin: 0.6rem auto; border-radius: var(--radius-2); }
.math-error { color: var(--bad); }

/* 引用・定理ボックス */
.prose blockquote { margin: 1.5rem 0; padding: 0.9rem 1.2rem; border-left: 3px solid var(--line-2); background: var(--bg-elev); border-radius: 0 var(--radius-3) var(--radius-3) 0; position: relative; }
.prose blockquote > :first-child { margin-top: 0.1rem; }
.prose blockquote > :last-child { margin-bottom: 0.1rem; }
.prose blockquote.thm { border: 1px solid color-mix(in srgb, var(--bc) 30%, transparent); border-left: 4px solid var(--bc); background: var(--bs); border-radius: var(--radius-2) var(--radius-3) var(--radius-3) var(--radius-2); padding: 1rem 1.25rem; scroll-margin-top: 84px; }
.prose blockquote.thm-def { --bc: var(--def); --bs: var(--def-soft); }
.prose blockquote.thm-thm { --bc: var(--thm); --bs: var(--thm-soft); }
.prose blockquote.thm > p:first-child > strong:first-of-type { color: var(--bc); margin-right: 0.2em; }
.prose blockquote.goal { border: 1px solid color-mix(in srgb, var(--good) 28%, transparent); border-left: 4px solid var(--good); background: var(--good-soft); border-radius: var(--radius-2) var(--radius-3) var(--radius-3) var(--radius-2); }
.prose blockquote.goal > p:first-child > strong:first-child { color: var(--good); display: inline-flex; align-items: center; gap: 0.3em; }
.prose blockquote.goal ul { margin: 0.4rem 0; }
.prose p.item { scroll-margin-top: 84px; }
.prose p.item > strong:first-child, .prose p.proof-head > strong:first-child { color: var(--fg); font-weight: 800; }
.prose p.item-example > strong:first-child { color: var(--primary); }
.prose p.item-remark > strong:first-child { color: var(--warn); }
.prose :target { animation: target-flash 1.6s var(--ease); }
@keyframes target-flash { 0%, 30% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 45%, transparent); } 100% { box-shadow: 0 0 0 4px transparent; } }

/* 定理ボックスの操作（リンク・AI に質問） */
.item-tools { position: absolute; top: 0.4rem; right: 0.4rem; display: flex; gap: 0.15rem; opacity: 0; transition: opacity 0.15s; }
.prose blockquote.thm[id] > p:first-child { padding-right: 3.6rem; }
.prose blockquote.thm:hover .item-tools, .prose blockquote.thm:focus-within .item-tools { opacity: 1; }
.item-tools button { display: grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 8px; background: color-mix(in srgb, var(--bg-elev) 80%, transparent); color: var(--fg-3); cursor: pointer; }
.item-tools button:hover { color: var(--primary); background: var(--bg-elev); }
@media (hover: none) { .item-tools { opacity: 1; } }

/* 補足ボックス */
.callout { margin: 1.5rem 0; padding: 0.8rem 1.2rem; border-left: 3px solid var(--cc); background: color-mix(in srgb, var(--cc) 7%, var(--bg-elev)); border-radius: 0 var(--radius-3) var(--radius-3) 0; }
.callout > :last-child { margin-bottom: 0.2rem; }
.callout-title { font-weight: 800; margin: 0.1rem 0 0.2rem; font-size: 0.92rem; color: var(--cc); }
.callout-note { --cc: var(--primary); }
.callout-tip { --cc: var(--good); }
.callout-important { --cc: var(--lv3); }
.callout-warning { --cc: var(--warn); }
.callout-caution { --cc: var(--bad); }

/* 折りたたみ（解答など） */
.prose details:not(:where(.lab *)) { margin: 1rem 0 1.4rem; border: 1px solid var(--line); border-radius: var(--radius-3); background: var(--bg-elev); padding: 0 1.1rem; }
.prose details > summary { cursor: pointer; padding: 0.65rem 0; font-weight: 800; color: var(--primary); list-style: none; display: flex; align-items: center; gap: 0.5rem; }
.prose details > summary::-webkit-details-marker { display: none; }
.prose details > summary::before { content: ""; width: 0.55em; height: 0.55em; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform 0.2s var(--ease); margin-right: 0.15rem; }
.prose details[open] > summary::before { transform: rotate(45deg); }
.prose details[open] > summary { border-bottom: 1px solid var(--line); margin-bottom: 0.5rem; }

/* 演習カード */
.exercise { position: relative; margin: 1.8rem 0; padding: 1.1rem 1.3rem 1rem; border: 1px solid var(--line); border-radius: var(--radius-4); background: var(--bg-elev); box-shadow: var(--shadow-1); scroll-margin-top: 84px; }
.exercise > h2, .exercise > h3 { margin-top: 0.2rem; border: 0; padding: 0; font-size: 1.25rem; }
.exercise > p:first-child { margin-top: 0; }
.exercise > p:first-child > strong:first-child {
  display: inline-block;
  margin-right: 0.35em;
  padding: 0.05rem 0.65rem;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.9rem;
}
.stars { color: var(--accent); letter-spacing: 0.05em; font-size: 0.95em; }
.exercise details { background: var(--bg); }
.exercise details > summary { color: var(--fg-2); }
.exercise.is-solved { border-color: color-mix(in srgb, var(--good) 45%, var(--line)); }
.exercise.is-hint { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.exercise.is-stuck { border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.ex-grade { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.8rem; margin-top: 0.9rem; padding-top: 0.9rem; border-top: 1px dashed var(--line-2); font-size: 0.88rem; }
.ex-grade-label { color: var(--fg-3); font-weight: 700; }
.ex-grade-btns { display: inline-flex; flex-wrap: wrap; gap: 0.35rem; }
.ex-grade button {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.32rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: var(--bg-elev);
  color: var(--fg-2);
  font-weight: 700;
  font-size: 0.84rem;
  cursor: pointer;
}
.ex-grade button:hover { color: var(--fg); background: var(--bg-hover); }
.ex-grade button[aria-pressed="true"][data-g="solved"] { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.ex-grade button[aria-pressed="true"][data-g="hint"] { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.ex-grade button[aria-pressed="true"][data-g="stuck"] { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.ex-grade .ex-ask { margin-left: auto; }
.ex-grade-note { color: var(--fg-3); font-size: 0.8rem; }

/* 章末 */
.doc-end { margin-top: 3.5rem; }
.complete-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 1.5rem;
  flex-wrap: wrap;
  padding: 1.4rem 1.6rem;
  border-radius: var(--radius-4);
  border: 1px solid var(--line);
  background: var(--bg-elev);
  background-image: radial-gradient(circle at 0 0, color-mix(in srgb, var(--good) 10%, transparent), transparent 55%);
}
.complete-title { margin: 0 0 0.2rem; font-weight: 800; font-size: 1.1rem; }
.complete-copy p { margin: 0; color: var(--fg-2); font-size: 0.9rem; }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; margin-top: 1.2rem; }
.pager-link { display: grid; gap: 0.1rem; padding: 0.9rem 1.1rem; border-radius: var(--radius-3); border: 1px solid var(--line); background: var(--bg-elev); color: var(--fg); font-weight: 800; line-height: 1.45; text-decoration: none !important; }
.pager-link:hover { border-color: var(--primary); }
.pager-link small { display: inline-flex; align-items: center; gap: 0.2em; color: var(--fg-3); font-size: 0.76rem; font-weight: 700; }
.pager-next { text-align: right; justify-items: end; }
.doc-footnote { display: flex; flex-wrap: wrap; gap: 0.5rem 1.4rem; margin-top: 1.4rem; font-size: 0.82rem; }
.doc-footnote a { display: inline-flex; align-items: center; gap: 0.35em; color: var(--fg-3); }
@media (max-width: 600px) { .pager { grid-template-columns: 1fr; } .pager-next { text-align: left; justify-items: start; } }

/* ---------- 実験室ページ ---------- */

.lab-nav { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 1.4rem; }
.lab-nav a { display: inline-flex; align-items: center; gap: 0.45em; padding: 0.3rem 0.8rem 0.3rem 0.35rem; border-radius: 999px; background: var(--bg-elev); border: 1px solid var(--line); color: var(--fg); font-size: 0.85rem; font-weight: 700; text-decoration: none !important; }
.lab-nav a:hover { border-color: var(--primary); }
.lab-glyph { display: grid; place-items: center; flex: none; min-width: 3rem; height: 3rem; padding: 0 0.4rem; border-radius: 14px; background: var(--primary-soft); color: var(--primary); font-family: var(--font-math); font-size: 1.05rem; font-weight: 600; white-space: nowrap; }
.lab-glyph.sm { min-width: 1.9rem; height: 1.9rem; border-radius: 999px; font-size: 0.72rem; padding: 0 0.35rem; }
.labs-list { padding-bottom: 4rem; max-width: 56rem; }
.lab-entry { padding: 2rem 0 1rem; border-top: 1px solid var(--line); scroll-margin-top: 70px; }
.lab-entry-head { display: flex; gap: 1rem; align-items: flex-start; }
.lab-entry h2 { margin: 0; font-size: 1.3rem; font-family: var(--font-serif); }
.lab-entry-head p { margin: 0.25rem 0 0; color: var(--fg-2); font-size: 0.93rem; }
.lab-where { display: flex; align-items: center; gap: 0.35em; font-size: 0.85rem !important; }

/* ---------- 学習記録ページ ---------- */

.me-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; padding-bottom: 4rem; }
.summary-row { display: flex; flex-wrap: wrap; align-items: center; gap: 1.5rem 2.5rem; }
.big-ring { position: relative; width: 150px; height: 150px; flex: none; }
.big-ring svg { width: 100%; height: 100%; }
.big-ring .ring-track, .big-ring .ring-prog { stroke-width: 11; }
.big-ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.big-ring-label span { font-family: var(--font-display); font-size: 2.1rem; font-weight: 600; line-height: 1; }
.big-ring-label small { font-size: 0.7rem; color: var(--fg-3); font-weight: 700; margin-top: 0.3rem; }
.me-summary .stat-grid { flex: 1; min-width: 16rem; }
.subject-bars { display: grid; gap: 0.35rem; }
.sbar { display: grid; grid-template-columns: 2.2rem minmax(0, 11rem) minmax(0, 1fr) 3.2rem; align-items: center; gap: 0.7rem; padding: 0.3rem 0.4rem; border-radius: 8px; color: var(--fg); text-decoration: none !important; font-size: 0.88rem; }
.sbar:hover { background: var(--bg-hover); }
.sbar .glyph { display: grid; place-items: center; width: 2rem; height: 2rem; border-radius: 50%; background: color-mix(in srgb, var(--lvc) 13%, transparent); color: var(--lvc); font-family: var(--font-math); font-size: 0.9rem; }
.sbar .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sbar .track { height: 8px; border-radius: 999px; background: var(--bg-sunken); overflow: hidden; }
.sbar .track span { display: block; height: 100%; background: var(--lvc); border-radius: inherit; }
.sbar .pct { text-align: right; font-variant-numeric: tabular-nums; color: var(--fg-2); font-weight: 700; font-size: 0.82rem; }
@media (max-width: 560px) { .sbar { grid-template-columns: 2.2rem minmax(0, 1fr) 3rem; } .sbar .track { grid-column: 2 / 4; grid-row: 2; } }
.ex-summary { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.ex-pill { display: inline-flex; align-items: center; gap: 0.4em; padding: 0.35rem 0.8rem; border-radius: 999px; font-weight: 800; font-size: 0.88rem; }
.ex-pill.solved { background: var(--good-soft); color: var(--good); }
.ex-pill.hint { background: var(--warn-soft); color: var(--warn); }
.ex-pill.stuck { background: var(--bad-soft); color: var(--bad); }
.review-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; }
.review-list a { display: flex; justify-content: space-between; gap: 1rem; padding: 0.5rem 0.75rem; border-radius: var(--radius-2); border: 1px solid var(--line); color: var(--fg); font-size: 0.88rem; text-decoration: none !important; }
.review-list a:hover { border-color: var(--primary); }
.review-list small { color: var(--fg-3); white-space: nowrap; }
.empty { color: var(--fg-3); font-size: 0.9rem; margin: 0; }
.badges { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: 0.7rem; }
.badge-item { display: grid; justify-items: center; text-align: center; gap: 0.3rem; padding: 1rem 0.6rem; border-radius: var(--radius-3); border: 1px solid var(--line); background: var(--bg); font-size: 0.8rem; color: var(--fg-2); line-height: 1.4; }
.badge-item .medal { display: grid; place-items: center; width: 3rem; height: 3rem; border-radius: 50%; background: var(--bg-sunken); color: var(--fg-3); font-family: var(--font-math); font-size: 1.2rem; }
.badge-item b { color: var(--fg); font-size: 0.86rem; }
.badge-item.is-earned { background: var(--bg-elev); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.badge-item.is-earned .medal { background: linear-gradient(135deg, var(--accent), var(--seal)); color: #fff; }
.badge-item:not(.is-earned) { opacity: 0.6; }
.field { display: grid; gap: 0.3rem; max-width: 20rem; font-size: 0.85rem; font-weight: 700; color: var(--fg-2); }
.field input { font: inherit; font-size: 1rem; padding: 0.5rem 0.8rem; border-radius: var(--radius-2); border: 1px solid var(--line-2); background: var(--bg); color: var(--fg); }
.share-preview { margin-top: 1rem; border-radius: var(--radius-3); overflow: hidden; border: 1px solid var(--line); max-width: 36rem; }
.share-preview canvas { display: block; width: 100%; height: auto; }

/* ---------- 共有ページ ---------- */

.share-page .panel { margin-bottom: 1rem; }
.share-page .roadmap { box-shadow: none; }

/* ---------- AI チューター（紹介ページ） ---------- */

.pro-hero { padding: 4rem 0 2rem; position: relative; overflow: hidden; }
.pro-hero-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 0.95fr); gap: 3rem; align-items: center; }
.pro-hero h1.display { font-size: clamp(2.2rem, 5vw, 3.4rem); margin: 0.3rem 0 1rem; }
.pro-note { display: flex; align-items: center; gap: 0.4em; font-size: 0.84rem; color: var(--fg-3); margin-top: 1rem; }
.tutor-mock { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-4); box-shadow: var(--shadow-2); padding: 1.1rem; display: grid; gap: 0.7rem; }
.mock-context { display: inline-flex; align-items: center; gap: 0.4em; justify-self: start; font-size: 0.78rem; font-weight: 800; color: var(--fg-2); background: var(--bg-sunken); padding: 0.25rem 0.7rem; border-radius: 999px; }
.mock-msg { padding: 0.7rem 0.95rem; border-radius: 16px; font-size: 0.92rem; line-height: 1.75; }
.mock-msg p { margin: 0 0 0.4rem; }
.mock-msg p:last-child { margin: 0; }
.mock-user { justify-self: end; max-width: 85%; background: var(--primary); color: var(--on-primary); border-bottom-right-radius: 5px; }
.mock-ai { max-width: 92%; background: var(--bg-sunken); border-bottom-left-radius: 5px; }
.mock-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.mock-chips span { font-size: 0.78rem; font-weight: 700; padding: 0.25rem 0.7rem; border-radius: 999px; border: 1px solid var(--line-2); color: var(--fg-2); }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: 1rem; max-width: 50rem; }
.plan { position: relative; padding: 1.5rem 1.6rem; border-radius: var(--radius-4); border: 1px solid var(--line); background: var(--bg-elev); }
.plan h3 { margin: 0; font-size: 1.1rem; }
.plan ul { list-style: none; margin: 1rem 0 1.2rem; padding: 0; display: grid; gap: 0.5rem; font-size: 0.92rem; }
.plan li { display: flex; gap: 0.5em; align-items: flex-start; }
.plan li .icon { color: var(--good); margin-top: 0.3em; }
.price { margin: 0.4rem 0 0; font-family: var(--font-display); font-size: 2.2rem; font-weight: 600; line-height: 1.2; }
.price small { font-size: 0.95rem; color: var(--fg-3); font-family: var(--font-sans); font-weight: 700; }
.price-sub { margin: 0.2rem 0 0; font-size: 0.82rem; color: var(--fg-3); font-weight: 600; }
.plan-pro { border: 2px solid var(--primary); box-shadow: 0 16px 40px color-mix(in srgb, var(--primary) 18%, transparent); }
.plan-badge { position: absolute; top: -0.8rem; left: 1.4rem; margin: 0; font-size: 0.75rem; font-weight: 800; color: var(--on-primary); background: var(--primary); padding: 0.15rem 0.7rem; border-radius: 999px; }
.faq { border: 1px solid var(--line); border-radius: var(--radius-3); background: var(--bg-elev); padding: 0 1.2rem; margin-bottom: 0.7rem; }
.faq summary { cursor: pointer; padding: 0.9rem 0; font-weight: 800; }
.faq p { margin: 0 0 1rem; color: var(--fg-2); font-size: 0.93rem; }
@media (max-width: 900px) { .pro-hero-grid { grid-template-columns: 1fr; } }

/* ---------- 検索 ---------- */

.dialog-backdrop { position: fixed; inset: 0; z-index: 80; background: rgb(10 12 18 / 0.42); backdrop-filter: blur(2px); animation: fade-in 0.15s var(--ease); }
.search-dialog {
  position: fixed;
  z-index: 81;
  top: 9vh;
  left: 50%;
  transform: translateX(-50%);
  width: min(42rem, calc(100vw - 24px));
  max-height: 78vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-4);
  box-shadow: var(--shadow-3);
  overflow: hidden;
  animation: pop-in 0.18s var(--ease);
}
.search-field { display: flex; align-items: center; gap: 0.6rem; padding: 0.9rem 1rem; border-bottom: 1px solid var(--line); color: var(--fg-3); }
.search-field input { flex: 1; border: 0; background: transparent; font: inherit; font-size: 1.1rem; color: var(--fg); outline: none; min-width: 0; }
.search-field input:focus-visible { box-shadow: none; }
.search-field kbd { font-family: var(--font-mono); font-size: 0.72rem; padding: 0.1rem 0.4rem; border: 1px solid var(--line); border-radius: 5px; }
.search-results { overflow-y: auto; padding: 0.4rem; }
.search-group { padding: 0.6rem 0.7rem 0.2rem; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.06em; color: var(--fg-3); }
.search-item { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.1rem 0.7rem; padding: 0.55rem 0.7rem; border-radius: var(--radius-2); color: var(--fg); text-decoration: none !important; }
.search-item[aria-selected="true"], .search-item:hover { background: var(--primary-soft); }
.search-kind { grid-row: span 2; align-self: center; font-size: 0.68rem; font-weight: 800; padding: 0.12rem 0.45rem; border-radius: 6px; background: var(--bg-sunken); color: var(--fg-2); white-space: nowrap; }
.search-kind.k-d { background: var(--def-soft); color: var(--def); }
.search-kind.k-t { background: var(--thm-soft); color: var(--thm); }
.search-kind.k-k { background: var(--good-soft); color: var(--good); }
.search-kind.k-l { background: var(--primary-soft); color: var(--primary); }
.search-title { font-weight: 700; line-height: 1.45; }
.search-title mark { background: color-mix(in srgb, var(--accent) 35%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.search-sub { font-size: 0.78rem; color: var(--fg-3); line-height: 1.4; }
.search-empty { padding: 1.6rem 1rem; text-align: center; color: var(--fg-3); font-size: 0.9rem; }
.search-foot { display: flex; gap: 1rem; padding: 0.5rem 1rem; border-top: 1px solid var(--line); font-size: 0.75rem; color: var(--fg-3); }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateX(-50%) translateY(-6px) scale(0.98); } }

/* ---------- AI チューターのパネル ---------- */

.tutor {
  position: fixed;
  z-index: 70;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(440px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-3);
  transform: translateX(105%);
  transition: transform 0.3s var(--ease);
}
.tutor.is-open { transform: none; }
.tutor-head { display: flex; align-items: center; gap: 0.6rem; padding: 0.8rem 0.8rem 0.8rem 1.1rem; border-bottom: 1px solid var(--line); }
.tutor-head h2 { margin: 0; font-size: 1rem; display: flex; align-items: center; gap: 0.4rem; }
.tutor-head h2 .icon { color: var(--accent); }
.tutor-head .icon-btn { margin-left: auto; }
.tutor-context { display: flex; align-items: flex-start; gap: 0.5rem; margin: 0.8rem 1rem 0; padding: 0.55rem 0.75rem; border-radius: var(--radius-2); background: var(--bg-sunken); font-size: 0.82rem; color: var(--fg-2); }
.tutor-context b { color: var(--fg); }
.tutor-context q { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--fg-3); quotes: "「" "」"; }
.tutor-context button { margin-left: auto; border: 0; background: none; color: var(--fg-3); cursor: pointer; padding: 0; }
.tutor-modes { display: flex; gap: 0.3rem; padding: 0.7rem 1rem 0; flex-wrap: wrap; }
.tutor-modes button { display: inline-flex; align-items: center; gap: 0.3em; padding: 0.3rem 0.7rem; border-radius: 999px; border: 1px solid var(--line); background: var(--bg-elev); font-size: 0.8rem; font-weight: 700; color: var(--fg-2); cursor: pointer; }
.tutor-modes button[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.tutor-log { flex: 1; overflow-y: auto; padding: 1rem; display: grid; align-content: start; gap: 0.8rem; }
.msg { padding: 0.7rem 0.95rem; border-radius: 16px; font-size: 0.93rem; line-height: 1.8; max-width: 94%; overflow-wrap: anywhere; }
.msg p { margin: 0 0 0.5rem; }
.msg p:last-child { margin: 0; }
.msg ul, .msg ol { margin: 0.3rem 0; padding-left: 1.3em; }
.msg .katex-display { margin: 0.4rem 0; overflow-x: auto; overflow-y: hidden; }
.msg-user { justify-self: end; background: var(--primary); color: var(--on-primary); border-bottom-right-radius: 5px; white-space: pre-wrap; }
.msg-ai { justify-self: start; background: var(--bg-sunken); border-bottom-left-radius: 5px; }
.msg-ai.is-streaming::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--primary); }
.msg-note { justify-self: center; text-align: center; max-width: 100%; font-size: 0.8rem; color: var(--fg-3); background: none; padding: 0.2rem 0.5rem; }
.msg-demo { border: 1px dashed var(--line-2); }
.msg-error { background: var(--bad-soft); color: var(--bad); }
@keyframes blink { 50% { opacity: 0; } }
.tutor-empty { text-align: center; color: var(--fg-3); font-size: 0.88rem; padding: 1.5rem 0.5rem; }
.tutor-empty .icon { color: var(--accent); }
.tutor-suggest { display: flex; flex-wrap: wrap; gap: 0.35rem; padding: 0 1rem 0.6rem; }
.tutor-suggest button { padding: 0.28rem 0.7rem; border-radius: 999px; border: 1px solid var(--line-2); background: var(--bg-elev); font-size: 0.78rem; font-weight: 700; color: var(--fg-2); cursor: pointer; }
.tutor-suggest button:hover { border-color: var(--primary); color: var(--primary); }
.tutor-compose { display: flex; gap: 0.5rem; align-items: flex-end; padding: 0.7rem 0.8rem 0.4rem 1rem; border-top: 1px solid var(--line); }
.tutor-compose textarea { flex: 1; resize: none; min-height: 2.8rem; max-height: 9rem; font: inherit; font-size: 0.95rem; line-height: 1.6; padding: 0.55rem 0.8rem; border-radius: 14px; border: 1px solid var(--line-2); background: var(--bg); color: var(--fg); }
.tutor-compose textarea:focus { outline: none; box-shadow: var(--focus-ring); }
.tutor-send { display: grid; place-items: center; width: 2.8rem; height: 2.8rem; flex: none; border-radius: 50%; border: 0; background: var(--primary); color: var(--on-primary); cursor: pointer; }
.tutor-send:disabled { opacity: 0.45; cursor: not-allowed; }
.tutor-foot { display: flex; justify-content: space-between; gap: 0.6rem; padding: 0 1rem calc(0.6rem + env(safe-area-inset-bottom)); font-size: 0.72rem; color: var(--fg-3); }
.tutor-foot a { font-weight: 700; }
@media (max-width: 640px) {
  .tutor { top: auto; height: 88vh; width: 100vw; border-left: 0; border-top-left-radius: 20px; border-top-right-radius: 20px; transform: translateY(105%); }
  .tutor.is-open { transform: none; }
}

/* テキストを選んだときの小さなメニュー */
.select-pop {
  position: absolute;
  z-index: 65;
  display: flex;
  gap: 2px;
  padding: 4px;
  border-radius: 12px;
  background: var(--fg);
  box-shadow: var(--shadow-2);
  animation: fade-in 0.12s var(--ease);
}
.select-pop button { display: inline-flex; align-items: center; gap: 0.35em; padding: 0.35rem 0.7rem; border: 0; border-radius: 9px; background: transparent; color: var(--bg); font-size: 0.82rem; font-weight: 700; cursor: pointer; white-space: nowrap; }
.select-pop button:hover { background: color-mix(in srgb, var(--bg) 16%, transparent); }

/* トースト・Q.E.D. の判子 */
.toast {
  position: fixed;
  z-index: 90;
  left: 50%;
  bottom: calc(1.4rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-size: 0.9rem;
  font-weight: 700;
  box-shadow: var(--shadow-2);
  animation: toast-in 0.25s var(--ease);
  max-width: calc(100vw - 32px);
}
@media (max-width: 760px) { .toast { bottom: calc(70px + env(safe-area-inset-bottom)); } }
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(8px); } }
.qed-overlay { position: fixed; inset: 0; z-index: 95; display: grid; place-items: center; pointer-events: none; }
.qed-stamp {
  display: grid;
  place-items: center;
  text-align: center;
  width: 12rem;
  height: 12rem;
  border-radius: 50%;
  border: 6px solid var(--seal);
  color: var(--seal);
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  box-shadow: inset 0 0 0 7px var(--bg-elev), inset 0 0 0 9px var(--seal), var(--shadow-3);
  font-family: var(--font-display);
  animation: stamp 1.9s var(--ease) forwards;
}
.qed-stamp b { font-size: 2.3rem; line-height: 1; letter-spacing: 0.04em; }
.qed-stamp span { font-family: var(--font-sans); font-size: 0.85rem; font-weight: 800; margin-top: 0.4rem; color: var(--fg); }
@keyframes stamp {
  0% { opacity: 0; transform: scale(2.2) rotate(-24deg); }
  18% { opacity: 1; transform: scale(0.94) rotate(-12deg); }
  26% { transform: scale(1) rotate(-12deg); }
  78% { opacity: 1; transform: scale(1) rotate(-12deg); }
  100% { opacity: 0; transform: scale(1.04) rotate(-12deg); }
}

/* ---------- フッター ---------- */

.site-footer { border-top: 1px solid var(--line); padding: 3rem 0 2rem; margin-top: 2rem; background: color-mix(in srgb, var(--bg-sunken) 50%, var(--bg)); font-size: 0.88rem; }
.footer-grid { display: grid; grid-template-columns: 1.6fr repeat(3, 1fr); gap: 2rem; }
.footer-brand p { color: var(--fg-3); margin: 0.8rem 0 0; line-height: 1.8; }
.site-footer nav { display: grid; align-content: start; gap: 0.35rem; }
.site-footer nav h2 { margin: 0 0 0.3rem; font-size: 0.78rem; letter-spacing: 0.06em; color: var(--fg-3); }
.site-footer nav a { color: var(--fg-2); display: inline-flex; align-items: center; gap: 0.3em; }
.footer-note { margin-top: 2rem; padding-top: 1.2rem; border-top: 1px solid var(--line); color: var(--fg-3); font-size: 0.8rem; }
@media (max-width: 760px) { .footer-grid { grid-template-columns: 1fr 1fr; } .footer-brand { grid-column: 1 / -1; } }

/* ---------- スマホの本文 ---------- */

@media (max-width: 600px) {
  body { font-size: 16px; }
  .wrap { padding: 0 16px; }
  .section { padding: 3rem 0; }
  .prose { font-size: 1rem; line-height: 1.9; }
  .prose h2:not(:where(.lab *)) { font-size: 1.3rem; margin-top: 2.6rem; }
  .prose blockquote, .prose blockquote.thm { padding: 0.8rem 0.9rem; margin-left: -4px; margin-right: -4px; }
  .exercise { padding: 0.95rem 1rem 0.9rem; margin-left: -4px; margin-right: -4px; }
  .panel { padding: 1.1rem 1rem; border-radius: var(--radius-3); }
  .cta-band-inner { padding: 1.5rem 1.2rem; }
}

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

@media print {
  .topbar, .tabbar, .sidebar, .doc-actions, .doc-end, .site-footer, .ex-grade, .item-tools, .lab { display: none !important; }
  .layout-doc { display: block; }
  .prose details:not(:where(.lab *)) { border: 0; padding: 0; }
  body { background: #fff; }
}

/* ---------- 経験値とレベル（web/app/quest.js） ---------- */
.level-chip-top {
  display: inline-flex; align-items: center; gap: 0.4em; height: 32px; padding: 0 0.7rem; border-radius: 999px;
  background: var(--good-soft); color: var(--good); font-weight: 800; font-size: 0.88rem;
  text-decoration: none !important; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.level-chip-top .lvbar { display: inline-block; width: 2.6rem; height: 0.35rem; border-radius: 999px; background: color-mix(in srgb, var(--good) 22%, transparent); overflow: hidden; }
.level-chip-top .lvbar span { display: block; height: 100%; background: var(--good); }
@media (max-width: 520px) { .level-chip-top .lvbar { display: none; } }
.quest-bar { display: block; height: 0.55rem; border-radius: 999px; background: var(--bg-sunken); overflow: hidden; margin: 0.35rem 0 0.5rem; }
.quest-bar span { display: block; height: 100%; background: var(--good); transition: width 0.8s var(--ease); }
.quest-book { border: 1px solid var(--line); border-radius: 14px; background: var(--bg-elev); padding: 1rem 1.1rem; margin: 1.2rem 0; }
.me-page .quest-book { border: 0; padding: 0; margin: 0; background: none; }
.quest-book p { margin: 0.3rem 0; }
.quest-top { display: flex; gap: 1rem; align-items: flex-start; }
.quest-lv { flex: none; min-width: 5rem; padding: 0.5rem 0.7rem; border-radius: 12px; background: var(--good); color: #fff; text-align: center; font-family: var(--font-display); font-size: 1.9rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.quest-lv small { display: block; font-size: 0.75rem; font-family: var(--font-sans, inherit); opacity: 0.85; }
.quest-info { flex: 1; min-width: 0; }
.quest-title { font-weight: 800; }
.quest-sub, .quest-titles { color: var(--fg-2); font-size: 0.9rem; }
.quest-book details { margin: 0.7rem 0; }
.quest-book summary { cursor: pointer; font-weight: 700; color: var(--primary); }
.quest-gates { padding-left: 1.2em; }
.quest-gates li.is-pass, .gate-groups li.is-pass { color: var(--good); font-weight: 700; }
.gate-card { border: 2px solid var(--good); border-radius: 14px; background: var(--good-soft); padding: 1rem 1.2rem; margin: 1.5rem 0; }
.gate-card p { margin: 0.3rem 0; }
.gate-title { font-weight: 800; color: var(--good); }
.gate-note { color: var(--fg-2); font-size: 0.92rem; }
@media (max-width: 520px) { .quest-top { flex-direction: column; gap: 0.5rem; } }

/* ---------- パートナー（web/app/partner.js・partner-art.js） ---------- */
.partner-art { display: inline-block; line-height: 0; }
.partner-art svg, .partner-svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* 動き：呼吸・まばたき・たまごのゆれ・光の紋章。ごほうびの瞬間（is-hop）だけ大きく動く */
.partner-svg .pt-body { transform-box: view-box; transform-origin: 100px 184px; animation: pt-breathe 3.6s ease-in-out infinite; }
.partner-svg .pt-eyes { transform-box: fill-box; transform-origin: center; animation: pt-blink 5.2s infinite; }
.partner-svg .pt-egg { transform-box: view-box; transform-origin: 100px 178px; animation: pt-wobble 4.8s ease-in-out infinite; }
.partner-svg .pt-halo { transform-box: view-box; transform-origin: 100px 86px; animation: pt-halo 6s ease-in-out infinite; }
.partner-svg .pt-joy { transform-box: fill-box; transform-origin: center; animation: pt-joy 1.2s var(--ease) both; }
.partner-svg.is-happy .pt-eyes { animation: none; }
.partner-svg.is-still *, .chip-partner .pt-body, .chip-partner .pt-halo { animation: none !important; }
.partner-art.is-hop svg { animation: pt-hop 0.7s var(--ease); }
@keyframes pt-breathe { 50% { transform: scale(1.015, 0.985); } }
@keyframes pt-blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(0.1); } }
@keyframes pt-wobble { 0%, 70%, 100% { transform: rotate(0); } 76% { transform: rotate(-5deg); } 82% { transform: rotate(4deg); } 88% { transform: rotate(-2deg); } }
@keyframes pt-halo { 50% { opacity: 0.7; transform: scale(1.02); } }
@keyframes pt-joy { from { opacity: 0; transform: scale(0.4); } 40% { opacity: 1; transform: scale(1.15); } to { opacity: 1; transform: scale(1); } }
@keyframes pt-hop { 0% { transform: translateY(0) scale(1); } 25% { transform: translateY(0) scale(1.08, 0.9); } 55% { transform: translateY(-14%) scale(0.95, 1.06); } 80% { transform: translateY(0) scale(1.05, 0.95); } 100% { transform: none; } }
@media (prefers-reduced-motion: reduce) { .partner-svg *, .partner-art.is-hop svg { animation: none !important; } }

/* ダークモード：輪郭（ココア色）が背景に沈まないよう、ふちに淡い光を足す */
:root[data-theme="dark"] .partner-svg { filter: drop-shadow(0 0 0.8px rgb(255 255 255 / 0.75)) drop-shadow(0 0 6px rgb(141 157 255 / 0.18)); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .partner-svg { filter: drop-shadow(0 0 0.8px rgb(255 255 255 / 0.75)) drop-shadow(0 0 6px rgb(141 157 255 / 0.18)); } }

/* 上部のレベル表示に、小さなパートナー */
.level-chip-top.has-partner { padding-left: 0.3rem; }
.chip-partner { width: 30px; height: 30px; margin: -6px -0.1rem -2px 0; }

/* 経験値のパネル：パートナーの舞台とセリフ */
.partner-stage {
  flex: none; position: relative; width: 168px; height: 168px; padding: 8px; border: 0; border-radius: 50%; cursor: pointer;
  background: radial-gradient(circle at 50% 62%, color-mix(in srgb, var(--pc) 20%, transparent) 0 54%, color-mix(in srgb, var(--pc) 7%, transparent) 55% 70%, transparent 71%);
  -webkit-tap-highlight-color: transparent;
}
.partner-stage .partner-art { width: 100%; height: 100%; }
.partner-stage:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.partner-name { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0.2rem 0.6rem; margin: 0.2rem 0 0.4rem !important; }
.partner-name b { font-family: var(--font-serif); font-size: 1.35rem; }
.partner-name span { font-size: 0.78rem; font-weight: 800; color: var(--fg-2); padding: 0.1rem 0.55rem; border-radius: 999px; background: var(--bg-sunken); }
.partner-say {
  position: relative; display: inline-block; max-width: 34rem; margin: 0 0 0.7rem !important; padding: 0.55rem 0.85rem;
  border-radius: 14px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); font-size: 0.92rem; line-height: 1.6;
}
.partner-say::before { content: ""; position: absolute; left: -7px; top: 14px; width: 12px; height: 12px; background: inherit; border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); transform: rotate(45deg); }
.partner-say:empty { display: none; }
.quest-lv-inline { display: inline-block; margin-right: 0.3rem; padding: 0.05rem 0.5rem; border-radius: 8px; background: var(--good); color: #fff; font-family: var(--font-display); font-variant-numeric: tabular-nums; }
.partner-next { font-weight: 700; }
.quest-book.has-partner .quest-top { align-items: center; }
@media (max-width: 520px) {
  .quest-book.has-partner .quest-top { flex-direction: column; align-items: center; text-align: center; }
  .quest-book.has-partner .quest-info { width: 100%; }
  .partner-name { justify-content: center; }
  .partner-say::before { left: calc(50% - 6px); top: -7px; transform: rotate(135deg); }
}

/* まだ選んでいない人へのお誘い */
.partner-invite { display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap; margin-top: 0.9rem; padding: 0.8rem 1rem; border-radius: var(--radius-3); border: 1px dashed var(--line-2); background: var(--bg); }
.partner-invite-eggs { display: flex; }
.partner-invite-eggs span { width: 40px; height: 40px; margin-right: -8px; }
.partner-invite-text { flex: 1; min-width: 12rem; display: grid; font-size: 0.85rem; color: var(--fg-2); }
.partner-invite-text b { color: var(--fg); font-size: 0.95rem; }
.partner-toggle { margin: 0.4rem 0 0 !important; text-align: right; }

/* 図鑑 */
.zukan-list { list-style: none; padding: 0; margin: 0.8rem 0 0; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.6rem; }
.zukan-list li { display: grid; justify-items: center; align-content: start; gap: 0.15rem; padding: 0.6rem 0.4rem 0.7rem; border-radius: var(--radius-3); border: 1px solid var(--line); background: var(--bg); text-align: center; }
.zukan-list li.is-current { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); background: var(--bg-elev); box-shadow: var(--shadow-1); }
.zukan-art { width: 100%; max-width: 104px; aspect-ratio: 1; }
.zukan-list b { font-size: 0.8rem; line-height: 1.35; }
.zukan-list small { font-size: 0.72rem; color: var(--fg-3); font-variant-numeric: tabular-nums; }
.zukan-note { font-size: 0.72rem; line-height: 1.5; color: var(--fg-2); }
.zukan-list .is-unknown .zukan-art svg { filter: brightness(0) opacity(0.14); }
:root[data-theme="dark"] .zukan-list .is-unknown .zukan-art svg { filter: brightness(0) invert(1) opacity(0.12); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .zukan-list .is-unknown .zukan-art svg { filter: brightness(0) invert(1) opacity(0.12); } }
@media (max-width: 760px) { .zukan-list { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* 選ぶ画面 */
.partner-dialog {
  position: fixed; z-index: 81; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(44rem, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow-y: auto;
  padding: 1.6rem 1.6rem 1.3rem; background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-4); box-shadow: var(--shadow-3);
  animation: pop-in-center 0.22s var(--ease);
}
@keyframes pop-in-center { from { opacity: 0; transform: translate(-50%, -48%) scale(0.97); } }
.partner-dialog-head h2 { font-family: var(--font-serif); font-size: 1.45rem; margin: 0.1rem 0 0.4rem; }
.partner-dialog-head p:not(.eyebrow) { margin: 0; color: var(--fg-2); font-size: 0.92rem; }
.partner-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.7rem; margin: 1.2rem 0 0.6rem; }
.partner-option {
  position: relative; display: grid; justify-items: center; gap: 0.3rem; padding: 1rem 0.8rem 0.9rem; text-align: center; font: inherit; color: var(--fg); cursor: pointer;
  border: 2px solid var(--line); border-radius: var(--radius-3); background: var(--bg);
  transition: border-color 0.15s, transform 0.15s var(--ease), box-shadow 0.15s;
}
.partner-option:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.partner-option[aria-checked="true"] { border-color: var(--pc); background: color-mix(in srgb, var(--pc) 8%, var(--bg-elev)); box-shadow: 0 8px 24px color-mix(in srgb, var(--pc) 22%, transparent); }
.partner-option:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.po-art { width: 104px; height: 104px; }
.partner-option:not([aria-checked="true"]) .po-art .pt-egg { animation: none; }
.po-future { position: absolute; top: 0.6rem; right: 0.6rem; width: 40px; height: 40px; }
.po-future svg { filter: brightness(0) opacity(0.13); }
:root[data-theme="dark"] .po-future svg { filter: brightness(0) invert(1) opacity(0.14); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .po-future svg { filter: brightness(0) invert(1) opacity(0.14); } }
.po-future::after { content: "?"; position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; color: var(--fg-3); font-size: 0.9rem; }
.po-text { display: grid; gap: 0.2rem; font-size: 0.8rem; line-height: 1.5; color: var(--fg-2); }
.po-text b { display: grid; font-family: var(--font-serif); font-size: 1.15rem; color: var(--fg); }
.po-text b small { font-family: var(--font-sans); font-size: 0.72rem; font-weight: 800; color: var(--pc); letter-spacing: 0.04em; }
.partner-about { margin: 0.2rem 0 0.8rem; min-height: 1.6em; color: var(--fg-2); font-size: 0.9rem; text-align: center; }
.partner-name-field { max-width: 18rem; margin: 0 auto; }
.partner-dialog-actions { justify-content: center; }
.partner-off { margin-left: auto; font-size: 0.8rem; }
@media (max-width: 600px) {
  .partner-dialog { padding: 1.2rem 1rem 1rem; }
  .partner-options { grid-template-columns: minmax(0, 1fr); gap: 0.5rem; }
  .partner-option { grid-template-columns: auto minmax(0, 1fr); justify-items: start; text-align: left; align-items: center; padding: 0.6rem 0.8rem; }
  .po-art { width: 72px; height: 72px; }
  .po-future { top: 50%; transform: translateY(-50%); }
  .po-text { padding-right: 2.6rem; }
  .partner-off { margin-left: 0; }
}

/* 進化の演出 */
.evo-dialog { width: min(26rem, calc(100vw - 24px)); text-align: center; overflow: hidden; }
.evo-dialog h2 { position: relative; font-family: var(--font-serif); font-size: 1.35rem; margin: 0.4rem 0 0.3rem; }
.evo-dialog p { position: relative; margin: 0 0 0.4rem; color: var(--fg-2); font-size: 0.92rem; }
.evo-dialog .evo-next { font-size: 0.8rem; font-weight: 800; color: var(--fg-3); }
.evo-dialog .btn-row { position: relative; justify-content: center; }
.evo-rays {
  position: absolute; left: 50%; top: 7.4rem; width: 34rem; height: 34rem; margin: -17rem 0 0 -17rem; border-radius: 50%; pointer-events: none;
  background: repeating-conic-gradient(from 0deg, color-mix(in srgb, var(--accent) 22%, transparent) 0 8deg, transparent 8deg 22deg);
  mask-image: radial-gradient(circle, #000 0 30%, transparent 62%);
  -webkit-mask-image: radial-gradient(circle, #000 0 30%, transparent 62%);
  animation: evo-spin 18s linear infinite;
}
.evo-stage { position: relative; width: 200px; height: 200px; margin: 0 auto; }
.evo-stage.is-charging svg { animation: evo-charge 1.5s ease-in both; }
.evo-stage.is-flash::after { content: ""; position: absolute; inset: -40%; border-radius: 50%; background: radial-gradient(circle, #fff 0 35%, rgb(255 255 255 / 0) 70%); animation: evo-flash 0.9s ease-out both; }
.evo-stage.is-flash svg { animation: evo-pop 0.7s var(--ease) both; }
@keyframes evo-spin { to { transform: rotate(360deg); } }
@keyframes evo-charge { 0% { filter: none; transform: none; } 20%, 40%, 60%, 80% { transform: translateX(-3px); } 30%, 50%, 70%, 90% { transform: translateX(3px); } 100% { filter: brightness(2.2) saturate(0.3); transform: scale(1.06); } }
@keyframes evo-flash { from { opacity: 1; transform: scale(0.6); } to { opacity: 0; transform: scale(1.3); } }
@keyframes evo-pop { from { transform: scale(0.6); } 60% { transform: scale(1.08); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) { .evo-rays, .evo-stage svg, .evo-stage::after { animation: none !important; } }

/* ホーム：おかえりのあいさつ */
.welcome-partner { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 0.4rem; }
.welcome-partner .partner-art { flex: none; width: 76px; height: 76px; cursor: pointer; }
.welcome-partner .partner-say { margin: 0 !important; font-size: 0.88rem; }
.welcome-partner .partner-invite { margin: 0; padding: 0.5rem 0.8rem; }

/* 共有された学習マップのパートナー */
.share-hero { display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; flex-wrap: wrap; }
.share-partner { display: grid; justify-items: center; gap: 0.2rem; text-align: center; }
.share-partner .partner-art { width: 132px; height: 132px; }
.share-partner-text { display: grid; }
.share-partner-text b { font-family: var(--font-serif); font-size: 1.1rem; }
.share-partner-text small { font-size: 0.78rem; color: var(--fg-2); font-weight: 700; }
