/* ============================================================
   材料研究 / 第 009 号 — stylesheet
   Editorial grid: masthead / stage / readout / panel / notes.
   Every control is drawn with 1px rules; no assets, no webfonts.
   ============================================================ */

:root {
  --paper:      #E2DFDA;
  --paper-deep: #D6D2CB;
  --ink:        #1c1b19;
  --ink-soft:   #4a4740;
  --ink-faint:  #8d8880;
  --rule:       #1c1b19;
  --rule-soft:  rgba(28, 27, 25, 0.22);
  --accent:     #d8455a;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Songti SC",
           "Source Han Serif SC", "Noto Serif CJK SC", Georgia, serif;
  --mono:  ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas,
           "Noto Sans Mono CJK SC", monospace;
  --sans:  -apple-system, "Helvetica Neue", "PingFang SC",
           "Noto Sans CJK SC", Arial, sans-serif;

  --gap: 22px;
  --rule-w: 1px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body { overflow-x: hidden; }

.paper {
  max-width: 1440px;
  margin: 0 auto;
  padding: 26px 28px 40px;
  display: grid;
  grid-template-columns: 1fr 256px;
  grid-template-areas:
    "mast  mast"
    "stage panel"
    "read  notes";
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: var(--gap);
  min-height: 100vh;
}

/* ---------------- masthead ---------------- */

.masthead {
  grid-area: mast;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  border-bottom: var(--rule-w) solid var(--rule);
  padding-bottom: 12px;
}

.kicker {
  margin: 0 0 10px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.title {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(38px, 5.4vw, 68px);
  line-height: 0.98;
  letter-spacing: -0.015em;
}

.title-line { display: block; }

.standfirst {
  margin: 14px 0 0;
  max-width: 42ch;
  font-family: var(--serif);
  font-size: 13.5px;
  line-height: 1.62;
  color: var(--ink-soft);
}

.masthead-right {
  text-align: right;
  flex: 0 0 auto;
  padding-top: 4px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: var(--rule-w) solid var(--rule);
  padding: 5px 10px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
}

.badge-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: breathe 2.4s ease-in-out infinite;
}

.badge.is-paused  .badge-dot { animation: none; background: var(--ink-faint); }
.badge.is-dead    .badge-dot { animation: none; background: #b4442f; }
.badge.is-idle    .badge-dot { animation: none; background: var(--ink-faint); }

@keyframes breathe {
  0%, 100% { opacity: 1;    transform: scale(1); }
  50%      { opacity: 0.35; transform: scale(0.72); }
}

.badge-sub {
  margin: 8px 0 0;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.16em;
  color: var(--ink-faint);
}

/* ---------------- stage ---------------- */

.stage {
  grid-area: stage;
  position: relative;
  min-height: 380px;
  border: var(--rule-w) solid var(--rule);
  background: var(--paper-deep);
  overflow: hidden;
  touch-action: none;
}

#gpu {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

#gpu.is-dragging { cursor: grabbing; }
#gpu.tool-knife  { cursor: crosshair; }

.fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 8px;
  padding: 40px clamp(24px, 6%, 72px);
  background: var(--paper);
}
.fallback[hidden] { display: none; }

.fallback-kicker {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.fallback-title {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(26px, 3.4vw, 40px);
}
.fallback-body {
  margin: 6px 0 0;
  max-width: 46ch;
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--ink-soft);
}
.fallback-foot {
  margin: 14px 0 0;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
}

/* ---------------- readout ---------------- */

.readout {
  grid-area: read;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-top: var(--rule-w) solid var(--rule);
  padding-top: 12px;
}

.hints { display: flex; flex-direction: column; gap: 3px; }
.hints-line {
  margin: 0;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.55;
}
.hints-line b { font-weight: 600; color: var(--ink); }
.hints-line.keys {
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}

.stats {
  border-collapse: collapse;
  width: min(420px, 100%);
  font-variant-numeric: tabular-nums;
}
.stats-caption {
  caption-side: top;
  text-align: left;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding-bottom: 6px;
}
.stats th, .stats td {
  border-bottom: 1px solid var(--rule-soft);
  padding: 4px 0;
  text-align: left;
  font-weight: 400;
  font-size: 12px;
}
.stats th { color: var(--ink-soft); width: 34%; }
.stats .num {
  font-family: var(--mono);
  font-size: 12.5px;
  text-align: right;
  width: 32%;
}
.stats .unit {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  padding-left: 10px;
  width: 34%;
}

.stats-foot {
  margin: 0;
  max-width: 46ch;
  font-size: 11px;
  line-height: 1.6;
  color: var(--ink-faint);
}

/* ---------------- panel ---------------- */

.panel {
  grid-area: panel;
  border: var(--rule-w) solid var(--rule);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-self: start;
  background: var(--paper);
}

.panel-title {
  margin: 0;
  padding-bottom: 8px;
  border-bottom: var(--rule-w) solid var(--rule);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.field { display: flex; flex-direction: column; gap: 7px; }

.label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* segmented square buttons */
.seg { display: flex; flex-wrap: wrap; gap: 0; }
.seg .btn {
  flex: 1 1 auto;
  border-right-width: 0;
}
.seg .btn:last-child { border-right-width: var(--rule-w); }

.btn {
  appearance: none;
  background: transparent;
  color: var(--ink);
  border: var(--rule-w) solid var(--rule);
  padding: 6px 9px;
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1.35;
  cursor: pointer;
  transition: background 120ms linear, color 120ms linear;
  white-space: nowrap;
}
.btn:hover { background: rgba(28, 27, 25, 0.06); }
.btn:active { background: rgba(28, 27, 25, 0.12); }
.btn[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}
.btn:focus-visible,
.sw:focus-visible,
.slider:focus-visible,
.check input:focus-visible + .box,
.notes-summary:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
}
.btn[disabled] { opacity: 0.35; cursor: not-allowed; }

.btn-wide { width: 100%; text-align: left; }

.field-actions { gap: 0; }
.field-actions .btn { border-bottom-width: 0; }
.field-actions .btn:last-child { border-bottom-width: var(--rule-w); }

/* swatches */
.swatches { display: flex; gap: 6px; }
.sw {
  flex: 1 1 0;
  appearance: none;
  background: transparent;
  border: var(--rule-w) solid var(--rule);
  padding: 6px 4px 5px;
  font-family: var(--sans);
  font-size: 11px;
  color: var(--ink-soft);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.sw[aria-pressed="true"] {
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}
.sw-chip {
  width: 100%;
  height: 9px;
  background: var(--c);
  display: block;
}

/* sliders: 1px track, square handle */
.slider {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 14px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}
.slider::-webkit-slider-runnable-track {
  height: var(--rule-w);
  background: var(--rule);
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 9px; height: 14px;
  margin-top: -6.5px;
  background: var(--ink);
  border: 0;
  border-radius: 0;
}
.slider::-moz-range-track { height: var(--rule-w); background: var(--rule); }
.slider::-moz-range-thumb {
  width: 9px; height: 14px;
  background: var(--ink);
  border: 0;
  border-radius: 0;
}
.slider-ends {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-faint);
}

/* checkbox */
.field-checks { gap: 8px; }
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}
.check input {
  position: absolute;
  opacity: 0;
  width: 0; height: 0;
}
.check .box {
  width: 11px; height: 11px;
  border: var(--rule-w) solid var(--rule);
  display: inline-block;
  position: relative;
  flex: 0 0 auto;
}
.check input:checked + .box::after {
  content: "";
  position: absolute;
  inset: 2px;
  background: var(--ink);
}

/* ---------------- notes ---------------- */

.notes {
  grid-area: notes;
  border: var(--rule-w) solid var(--rule);
  align-self: start;
}
.notes-summary {
  cursor: pointer;
  padding: 9px 12px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.notes-summary::-webkit-details-marker { display: none; }
.notes-summary::after { content: "＋"; font-size: 11px; }
.notes[open] .notes-summary::after { content: "－"; }
.notes[open] .notes-summary { border-bottom: var(--rule-w) solid var(--rule); }

.notes-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 340px;
  overflow-y: auto;
}
.notes-body article h3 {
  margin: 0 0 4px;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 14px;
}
.notes-body article p {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.66;
  color: var(--ink-soft);
}
.notes-body b { font-family: var(--mono); font-weight: 400; color: var(--ink); }

/* ---------------- toast ---------------- */

.toast-wrap {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 40;
  width: max-content;
  max-width: min(88vw, 520px);
}
.toast {
  background: var(--paper);
  border: var(--rule-w) solid var(--rule);
  padding: 8px 16px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 13.5px;
  color: var(--ink);
  box-shadow: 3px 3px 0 rgba(28, 27, 25, 0.14);
  animation: toast-in 260ms cubic-bezier(0.16, 1, 0.3, 1);
  text-align: center;
}
.toast.is-out { animation: toast-out 340ms ease-in forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px) rotate(-0.6deg); }
  to   { opacity: 1; transform: none; }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(-6px); }
}

/* ---------------- responsive: stack on narrow ---------------- */

@media (max-width: 900px) {
  .paper {
    grid-template-columns: 1fr;
    grid-template-areas:
      "mast"
      "stage"
      "read"
      "panel"
      "notes";
    grid-template-rows: auto auto auto auto auto;
    padding: 18px 16px 32px;
    gap: 18px;
  }
  .masthead { flex-direction: column; }
  .masthead-right { text-align: left; }
  .badge-sub { margin-top: 6px; }
  .stage { min-height: 300px; aspect-ratio: 4 / 3; }
  .panel { width: 100%; }
  .notes-body { max-height: none; }
  .stats { width: 100%; }
}

/* ---------------- reduced motion ---------------- */

@media (prefers-reduced-motion: reduce) {
  .badge-dot { animation: none; }
  .toast { animation: none; }
  .btn { transition: none; }
}
