/* Static learn pages (/learn/math/*). One small stylesheet, no JS, no web fonts.
   Calm, typographic, textbook-like. CSP: style-src 'self', so no inline styles. */

:root {
  color-scheme: light dark;
  --bg: #fbfbf9;
  --surface: #f2f2ee;
  --surface-strong: #e9e9e3;
  --text: #1c1c1a;
  --muted: #5d5d57;
  --line: #dcdcd4;
  --accent: #0b6b4f;
  --accent-soft: #e3f1ea;
  --warn: #8a3b1f;
  --warn-soft: #f8ebe4;
  --focus: #1456c4;
  --cta-bg: #1c1c1a;
  --cta-text: #fbfbf9;
  --measure: 42rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0f0e;
    --surface: #181a18;
    --surface-strong: #222522;
    --text: #ebebe6;
    --muted: #a3a39b;
    --line: #2d302d;
    --accent: #6fcfa6;
    --accent-soft: #14251e;
    --warn: #f0a583;
    --warn-soft: #271913;
    --focus: #8db6ff;
    --cta-bg: #ebebe6;
    --cta-text: #0e0f0e;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Yu Gothic", Meiryo, system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.9;
  letter-spacing: 0.01em;
  word-break: normal;
  overflow-wrap: anywhere;
  line-break: strict;
}

@media (min-width: 40rem) {
  body {
    font-size: 1.0625rem;
  }
}

a {
  color: var(--accent);
  text-underline-offset: 0.2em;
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
  border-radius: 4px;
}

/* Layout ------------------------------------------------------------ */

.site-header,
main,
.site-footer {
  width: 100%;
  max-width: calc(var(--measure) + 2rem);
  margin-inline: auto;
  padding-inline: 1rem;
}

.site-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-block: 1rem;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.4;
}

.site-header .brand {
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-decoration: none;
}

main {
  padding-block: 1rem 3rem;
}

article > section,
article > aside,
article > nav {
  margin-top: 2.75rem;
}

/* Headings ------------------------------------------------------------ */

.eyebrow {
  margin: 1.5rem 0 0.5rem;
  color: var(--accent);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.4;
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.5;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-wrap: balance;
}

@media (min-width: 40rem) {
  h1 {
    font-size: 1.875rem;
  }
}

h2 {
  margin: 0 0 0.75rem;
  padding-top: 0.25rem;
  font-size: 1.1875rem;
  line-height: 1.5;
  font-weight: 700;
}

h2::before {
  content: "";
  display: block;
  width: 2rem;
  height: 3px;
  margin-bottom: 0.75rem;
  background: var(--accent);
  border-radius: 2px;
}

.lead {
  margin: 1.25rem 0 0;
  font-size: 1.0625rem;
  line-height: 1.95;
  color: var(--text);
}

@media (min-width: 40rem) {
  .lead {
    font-size: 1.125rem;
  }
}

.section-sub {
  margin: -0.25rem 0 1rem;
  color: var(--muted);
  font-size: 0.9375rem;
}

p {
  margin: 0 0 1rem;
}

article ul,
article ol {
  margin: 0 0 1rem;
  padding-left: 1.5rem;
}

li {
  margin-bottom: 0.4rem;
}

strong {
  font-weight: 700;
}

/* Math (semantic HTML: var / sup / sub, no JS) ---------------------------- */

var {
  font-family: "Times New Roman", "Hiragino Mincho ProN", "Noto Serif JP", Georgia, serif;
  font-style: italic;
  font-size: 1.06em;
}

sup,
sub {
  font-size: 0.72em;
  line-height: 0;
}

.m {
  white-space: nowrap;
  font-family: "Times New Roman", "Hiragino Mincho ProN", "Noto Serif JP", Georgia, serif;
  font-size: 1.04em;
}

/* Long inline math may wrap on narrow screens rather than overflow. */
@media (max-width: 30rem) {
  .m {
    white-space: normal;
  }
}

.frac sup,
.frac sub {
  font-size: 0.8em;
}

.frac {
  white-space: nowrap;
}

.mtext {
  font-family: inherit;
  font-style: normal;
}

.eq {
  margin: 0 0 1rem;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border-left: 3px solid var(--line);
  border-radius: 0 6px 6px 0;
  overflow-x: auto;
  font-family: "Times New Roman", "Hiragino Mincho ProN", "Noto Serif JP", Georgia, serif;
  font-size: 1.1em;
  line-height: 1.8;
}

.eq p {
  margin: 0;
  white-space: nowrap;
}

/* Problem box -------------------------------------------------------------- */

.problem {
  padding: 1.25rem 1.25rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.problem h2 {
  font-size: 1rem;
  color: var(--muted);
}

.problem h2::before {
  display: none;
}

/* Hints and answer: native details/summary ------------------------------- */

.hint,
.answer {
  margin: 0 0 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}

.hint[open],
.answer[open] {
  border-color: var(--accent);
}

summary {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 3rem;
  padding: 0.5rem 1rem;
  cursor: pointer;
  list-style: none;
  font-weight: 700;
  line-height: 1.5;
  border-radius: 10px;
}

summary::-webkit-details-marker {
  display: none;
}

summary::after {
  content: "";
  flex: none;
  width: 0.55rem;
  height: 0.55rem;
  margin-left: auto;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 160ms ease;
}

details[open] > summary::after {
  transform: rotate(-135deg);
}

summary:hover {
  background: var(--surface);
}

.hint-no {
  flex: none;
  padding: 0.05rem 0.6rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8125rem;
  letter-spacing: 0.04em;
}

.hint-label {
  font-weight: 700;
}

.hint-body {
  padding: 0.25rem 1rem 0.5rem;
  border-top: 1px solid var(--line);
  padding-top: 1rem;
}

/* Tables -------------------------------------------------------------------- */

.table-wrap {
  margin: 0 0 1.25rem;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
  line-height: 1.6;
}

th,
td {
  min-width: 6.5em;
  overflow-wrap: normal;
  padding: 0.55rem 0.75rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

thead th {
  background: var(--surface);
  font-weight: 700;
  white-space: nowrap;
}

tbody tr:last-child th,
tbody tr:last-child td {
  border-bottom: 0;
}

tbody th {
  font-weight: 600;
}

/* Common mistakes ------------------------------------------------------------ */

.mistakes {
  list-style: none;
  padding: 0;
}

.mistakes li {
  margin: 0 0 1rem;
  padding: 0.9rem 1rem 0.1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.mistakes .wrong {
  margin-bottom: 0.5rem;
  padding-left: 0.75rem;
  border-left: 3px solid var(--warn);
  color: var(--warn);
  font-weight: 700;
}

/* CTA ----------------------------------------------------------------------- */

.cta {
  padding: 1.5rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.cta-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3rem;
  padding: 0.5rem 1.75rem;
  border-radius: 999px;
  background: var(--cta-bg);
  color: var(--cta-text);
  font-weight: 700;
  text-decoration: none;
}

.cta-button:hover {
  opacity: 0.88;
}

.cta-note {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

@media (max-width: 30rem) {
  .cta-button {
    display: flex;
    width: 100%;
  }
}

/* Related + footer --------------------------------------------------------- */

.related ul {
  list-style: none;
  padding: 0;
}

.related li {
  margin: 0;
  border-bottom: 1px solid var(--line);
}

.related a {
  display: block;
  padding: 0.75rem 0;
  min-height: 2.75rem;
}

.site-footer {
  padding-block: 1.5rem 3rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.7;
}

.site-footer p {
  margin-bottom: 0.5rem;
}

@media (prefers-reduced-motion: reduce) {
  summary::after {
    transition: none;
  }
}

@media print {
  .site-header,
  .cta,
  .related {
    display: none;
  }
}

/* Breadcrumb header and index pages (/learn, /learn/math) -------------- */

.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.5rem;
}

.crumbs a:not(.brand) {
  color: var(--muted);
}

.crumbs [aria-current="page"] {
  color: var(--text);
}

.toc {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
  border-top: 1px solid var(--line);
}

.toc li {
  margin: 0;
  border-bottom: 1px solid var(--line);
}

.toc a {
  display: block;
  padding: 1rem 0;
  min-height: 2.75rem;
  color: var(--text);
  text-decoration: none;
}

.toc a:hover .toc-title {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.toc-title {
  display: block;
  font-weight: 700;
  line-height: 1.6;
}

.toc-lead {
  display: block;
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.75;
}
