/* =========================================================
   base.css — shared styles for every page.
   Mobile-first, light/dark via prefers-color-scheme, print-ready.
   No inline styles anywhere (CSP: style-src 'self').
   ========================================================= */

:root {
  --font-sans: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "BIZ UDPGothic",
    "Yu Gothic UI", "Yu Gothic", "Meiryo", "Noto Sans JP", system-ui, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Consolas", "BIZ UDGothic", monospace;

  --bg: #ffffff;
  --bg-alt: #f5f6f8;
  --surface: #ffffff;
  --text: #1a1d21;          /* 16.5:1 on --bg */
  --text-muted: #4f5660;    /* 7.4:1 on --bg */
  --border: #c9ced6;
  --accent: #0b5cad;        /* 6.6:1 on --bg */
  --accent-contrast: #ffffff;
  --accent-soft: #e6f0fa;
  --danger: #b3261e;
  --ok: #1f6f3a;
  --mark-bg: #fff3b0;
  --mark-text: #3d3200;
  --focus: #e07b00;

  --radius: 8px;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2.5rem;
  --maxw: 48rem;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171b;
    --bg-alt: #1c2026;
    --surface: #1c2026;
    --text: #e8eaed;        /* 14:1 */
    --text-muted: #aab1bb;  /* 7.8:1 */
    --border: #3a414b;
    --accent: #7ab7f5;      /* 8.3:1 */
    --accent-contrast: #0b1520;
    --accent-soft: #1d2b3a;
    --danger: #ff8a80;
    --ok: #7fd59a;
    --mark-bg: #4a3f00;
    --mark-text: #fff3b0;
    --focus: #ffb44d;
  }
}

/* ---------- Reset-ish ---------- */
*, *::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: var(--font-sans);
  font-size: 1rem;
  line-height: 1.8;
  line-break: strict;
  overflow-wrap: anywhere;
}
img, svg { max-width: 100%; height: auto; }
h1, h2, h3, h4 { line-height: 1.4; margin: var(--space-4) 0 var(--space-2); }
h1 { font-size: 1.6rem; margin-top: var(--space-3); }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 1.05rem; }
p, ul, ol, dl, table { margin: 0 0 var(--space-3); }
a { color: var(--accent); text-underline-offset: 0.2em; }
a:hover { text-decoration-thickness: 2px; }
code { font-family: var(--font-mono); font-size: 0.95em; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ---------- Utilities ---------- */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.muted { color: var(--text-muted); }
.small { font-size: 0.875rem; }
[hidden] { display: none !important; }

/* Placeholder marker: owner must replace these before launch. */
.ph {
  background: var(--mark-bg);
  color: var(--mark-text);
  padding: 0 0.2em;
  border-radius: 3px;
  font-family: var(--font-mono);
}

/* ---------- Layout ---------- */
.skip-link {
  position: absolute; left: var(--space-2); top: -3rem;
  background: var(--accent); color: var(--accent-contrast);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius);
  z-index: 100;
}
.skip-link:focus { top: var(--space-2); }

.container { max-width: var(--maxw); margin: 0 auto; padding: 0 var(--space-3); }

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.site-header .container {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: var(--space-2); padding-top: var(--space-2); padding-bottom: var(--space-2);
}
.site-title { font-weight: 700; color: var(--text); text-decoration: none; }
.site-nav ul { display: flex; gap: var(--space-3); list-style: none; margin: 0; padding: 0; }
.site-nav a { color: var(--text-muted); }

main { display: block; padding-bottom: var(--space-5); }

.breadcrumb { font-size: 0.875rem; color: var(--text-muted); margin-top: var(--space-3); }
.breadcrumb ol { list-style: none; display: flex; flex-wrap: wrap; gap: var(--space-1); margin: 0; padding: 0; }
.breadcrumb li + li::before { content: "›"; margin-right: var(--space-1); }

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-alt);
  font-size: 0.875rem;
  color: var(--text-muted);
  padding: var(--space-4) 0;
}
.site-footer ul { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-3); }

/* ---------- Components ---------- */
.notice {
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  margin: var(--space-3) 0;
}
.notice p:last-child { margin-bottom: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
}
.card-list { list-style: none; padding: 0; display: grid; gap: var(--space-3); }
.card-list > li { margin: 0; }
.card h2, .card h3, .card h4 { margin-top: 0; }
.badge {
  display: inline-block; font-size: 0.75rem; font-weight: 700;
  padding: 0 0.5em; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-muted);
}

/* Definition table (legal pages) */
.def-table { width: 100%; border-collapse: collapse; }
.def-table th, .def-table td {
  text-align: left; vertical-align: top;
  padding: var(--space-2); border-bottom: 1px solid var(--border);
}
.def-table th { width: 32%; background: var(--bg-alt); font-weight: 600; }
@media (max-width: 36rem) {
  .def-table th, .def-table td { display: block; width: 100%; }
  .def-table th { border-bottom: 0; }
}

/* ---------- Forms ---------- */
.form-grid { display: grid; gap: var(--space-3); }
.field { display: grid; gap: var(--space-1); }
.field label, .field legend { font-weight: 600; }
.field .hint { font-size: 0.875rem; color: var(--text-muted); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-2) var(--space-3); margin: 0; }

input[type="text"], input[type="number"], input[type="email"], input[type="date"], select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--text-muted);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  min-height: 2.75rem; /* 44px touch target */
  width: 100%;
  max-width: 20rem;
}
input[aria-invalid="true"] { border-color: var(--danger); border-width: 2px; }
.error-text { color: var(--danger); font-size: 0.875rem; }

.btn-row { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-3) 0; }
.btn {
  font: inherit; font-weight: 600;
  min-height: 2.75rem; padding: 0.5rem 1.25rem;
  border-radius: 6px; cursor: pointer;
  border: 1px solid var(--accent);
  background: var(--surface); color: var(--accent);
}
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.6; cursor: not-allowed; }

/* ---------- Results ---------- */
.results {
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin: var(--space-4) 0;
  background: var(--surface);
}
.results:empty { display: none; }
.result-main { font-size: 1.5rem; font-weight: 700; margin: 0 0 var(--space-2); }
.result-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.result-table th, .result-table td { padding: var(--space-1) var(--space-2); border-bottom: 1px solid var(--border); text-align: left; }
.result-table td.num { text-align: right; }

/* ---------- Pro teaser ---------- */
.pro-teaser {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  background: var(--bg-alt);
}
.pro-teaser h2 { margin-top: 0; font-size: 1.1rem; }

.lead { font-size: 1.1rem; font-weight: 600; }

/* ---------- FAQ ---------- */
.faq details { border-bottom: 1px solid var(--border); padding: var(--space-2) 0; }
.faq summary { cursor: pointer; font-weight: 600; min-height: 2.75rem; display: flex; align-items: center; }
.faq details > *:not(summary) { margin-top: var(--space-2); }

/* ---------- Disclosure marker ----------
   Summaries use display:flex (for the 44px touch target), which hides the native ▶ marker.
   Draw our own so it is obvious the row can be opened. */
summary { list-style: none; }
summary::-webkit-details-marker { display: none; }
summary::before {
  content: "▶"; flex: none; display: inline-block;
  font-size: 0.7em; margin-right: 0.6em; color: var(--text-muted);
  transition: transform 0.15s ease;
}
details[open] > summary::before { transform: rotate(90deg); }
@media (prefers-reduced-motion: reduce) { summary::before { transition: none; } }

/* ---------- Larger screens ---------- */
@media (min-width: 40rem) {
  h1 { font-size: 1.9rem; }
  .card-list { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Print ---------- */
@media print {
  :root {
    --bg: #fff; --surface: #fff; --text: #000; --text-muted: #333;
    --border: #999; --accent: #000; --bg-alt: #fff; --accent-soft: #fff;
  }
  @page { margin: 15mm; }
  body { font-size: 10.5pt; line-height: 1.6; }
  .site-header, .site-nav, .site-footer, .skip-link, .breadcrumb,
  .btn-row, .pro-teaser, .no-print, form .hint { display: none !important; }
  .container { max-width: none; padding: 0; }
  a { color: #000; text-decoration: none; }
  .results { border: 1px solid #000; break-inside: avoid; }
  .faq details { break-inside: avoid; }
  /* Closed <details> are opened on `beforeprint` by site.js so FAQ answers print. */
  .print-only { display: block !important; }
}
.print-only { display: none; }
