/* ドパガキ図鑑 — 分類標本庫（紙と墨）＋ 実験装置（暗い計器盤）
   普段は編集的で静かに。強い動きはサンプル動画の中だけに置く。 */

:root {
  --paper: #f3efe6;
  --paper-hi: #fbf9f4;
  --paper-band: #e8e1d2;
  --ink: #191613;
  --ink-2: #5a5248;
  --rule: #cfc6b4;
  --rule-strong: #8c8270;
  --signal: #c4320b;
  --signal-tint: #f8e3d8;
  --marker: #ffd23f;
  --watch: #7a5a00;
  --watch-tint: #f6eed3;
  --deck: #1d1a17;
  --deck-2: #2a2622;
  --deck-field: #12100e;
  --deck-ink: #f3efe6;
  --deck-muted: #bdb4a6;
  --deck-line: #7d7568;
  --phosphor: #ffd23f;
  --focus: var(--ink);

  --font-sans: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Yu Gothic", Meiryo, system-ui, sans-serif;
  --font-serif: "Hiragino Mincho ProN", "Yu Mincho", YuMincho, "Noto Serif JP", "BIZ UDPMincho", serif;
  --font-mono: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, monospace;

  --gutter: clamp(16px, 3vw, 32px);
  --toolbar-h: 0px;
  --dock-h: 0px;
}

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

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--toolbar-h) + 12px);
  scroll-padding-bottom: calc(var(--dock-h) + 12px);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.75;
  line-break: strict;
  overflow-wrap: anywhere;
  padding-bottom: var(--dock-h);
}

h1,
h2,
h3 {
  text-wrap: balance;
}

p,
li,
dd {
  text-wrap: pretty;
}

a {
  color: inherit;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

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

main:focus,
[tabindex="-1"]:focus:not(:focus-visible) {
  outline: none;
}

/* 視覚的に隠すテキストを含む部品は、隠しテキストの基準位置を自分に置く */
.btn,
.chip,
.filter-chip,
.specimen__btn {
  position: relative;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -100px;
  z-index: 100;
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  font-weight: 700;
  text-decoration: none;
}

.skip-link:focus {
  top: 12px;
  --focus: var(--marker);
}

.noscript {
  max-width: 1440px;
  margin: 24px auto;
  padding: 16px var(--gutter);
  border: 2px solid var(--signal);
}

/* ------------------------------------------------------------------ buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 14px;
  border: 1.5px solid var(--ink);
  background: var(--paper-hi);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
  text-decoration: none;
  border-radius: 0;
  transition: background-color 0.12s ease, color 0.12s ease;
}

@media (hover: hover) {
  .btn:hover {
    background: var(--paper-band);
  }
}

.btn--ink {
  background: var(--ink);
  color: var(--paper);
}

@media (hover: hover) {
  .btn--ink:hover {
    background: #3a342d;
  }
}

.btn--ghost {
  background: transparent;
}

.btn--signal {
  background: var(--phosphor);
  border-color: var(--phosphor);
  color: var(--ink);
}

@media (hover: hover) {
  .btn--signal:hover {
    background: #ffe27a;
  }
}

.btn--deck {
  background: transparent;
  border-color: var(--deck-line);
  color: var(--deck-ink);
}

@media (hover: hover) {
  .btn--deck:hover {
    background: var(--deck-2);
  }
}

.btn--large {
  min-height: 48px;
  padding: 8px 20px;
  font-size: 15px;
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
}

.btn--select[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

.btn--select[aria-pressed="true"]::before {
  content: "✓" / "";
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 32px;
  padding: 3px 10px;
  border: 1px solid var(--rule-strong);
  background: var(--paper-hi);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  border-radius: 999px;
}

@media (hover: hover) {
  .chip:hover {
    border-color: var(--ink);
  }
}

.chip[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

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

.masthead {
  max-width: 1440px;
  margin: 0 auto;
  padding: 18px var(--gutter) 0;
}

.masthead__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 24px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--ink);
}

.masthead__label {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.12em;
}

.masthead__nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 18px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.masthead__nav a {
  display: inline-block;
  padding: 4px 0;
  font-size: 14px;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

@media (hover: hover) {
  .masthead__nav a:hover {
    text-decoration-thickness: 2px;
  }
}

.masthead__body {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  align-items: end;
  gap: 20px 56px;
  padding: 26px 0 22px;
}

.masthead__title {
  display: inline-flex;
  align-items: flex-start;
  gap: 0.14em;
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(54px, 8.4vw, 118px);
  font-weight: 700;
  line-height: 0.98;
  letter-spacing: -0.01em;
}

.seal {
  margin-top: 0.28em;
  padding: 9px 5px;
  background: var(--signal);
  color: #fff;
  font-size: 15px;
  letter-spacing: 0.24em;
  line-height: 1;
  writing-mode: vertical-rl;
  border-radius: 2px;
  transform: rotate(5deg);
}

.masthead__subtitle {
  margin: 12px 0 0;
  font-family: var(--font-serif);
  font-size: clamp(20px, 2.4vw, 30px);
  letter-spacing: 0.06em;
}

.masthead__subtitle .times {
  color: var(--signal);
  padding: 0 0.15em;
}

.masthead__lede {
  margin: 0 0 16px;
  font-size: 15px;
}

.masthead__counts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
}

.masthead__counts div {
  padding: 6px 10px 8px;
  border-left: 1px solid var(--rule);
}

.masthead__counts div:first-child {
  border-left: 0;
  padding-left: 0;
}

.masthead__counts dt {
  font-size: 12px;
  color: var(--ink-2);
}

.masthead__counts dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 30px;
  font-weight: 600;
  line-height: 1.15;
}

/* 共通構造：予告 → 入力 → 即時反応 → 増幅 → 次の約束 */
.stages {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px 18px;
  padding: 14px 0 20px;
  border-top: 3px double var(--ink);
}

.stages__title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 15px;
  letter-spacing: 0.3em;
  writing-mode: vertical-rl;
  border-left: 1px solid var(--ink);
  padding-left: 6px;
}

.stages__list {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0 26px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.stage {
  position: relative;
  padding: 10px 12px 12px;
  border: 1px solid var(--ink);
  background: var(--paper-hi);
}

.stage:not(:last-child)::after {
  content: "→" / "";
  position: absolute;
  top: 50%;
  right: -22px;
  transform: translateY(-50%);
  font-size: 18px;
  color: var(--signal);
}

.stage__no {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-2);
}

.stage__no::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--signal);
}

.stage__name {
  margin: 2px 0 2px;
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 700;
  line-height: 1.3;
}

.stage__text {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-2);
}

.stages__note {
  grid-column: 2;
  margin: 2px 0 0;
  font-size: 14px;
}

/* ------------------------------------------------------------------ toolbar */

.toolbar {
  background: var(--paper);
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
}

.toolbar__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 10px var(--gutter);
}

.search {
  display: flex;
  flex: 1 1 340px;
  align-items: center;
  gap: 10px;
  max-width: 520px;
}

.search__label {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.search__input {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1.5px solid var(--ink);
  border-radius: 0;
  background: var(--paper-hi);
  font-size: 16px;
}

.search__input::placeholder {
  color: #6e665b;
}

.toolbar__summary {
  margin: 0;
  font-size: 13px;
  color: var(--ink-2);
}

.toolbar__summary b {
  color: var(--ink);
  font-family: var(--font-mono);
}

.toolbar__filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 3px 6px 3px 10px;
  border: 1px solid var(--ink);
  background: var(--marker);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
}

.filter-chip__x {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--marker);
  font-size: 11px;
  line-height: 1;
}

.toolbar__clear {
  margin-left: auto;
}

/* ------------------------------------------------------------------- layout */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 var(--gutter) 56px;
}

.section {
  padding-top: 36px;
}

.section__head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline;
  column-gap: 14px;
  margin-bottom: 18px;
  padding-top: 12px;
  border-top: 2px solid var(--ink);
}

.section__no {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 22px;
  color: var(--signal);
}

.section__title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(26px, 3vw, 38px);
  line-height: 1.25;
}

.section__count {
  margin-left: 4px;
  font-family: var(--font-mono);
  font-size: 0.5em;
  color: var(--ink-2);
  vertical-align: 0.6em;
}

.section__lede,
.section__filter {
  grid-column: 2;
  max-width: 60em;
  margin: 6px 0 0;
  color: var(--ink-2);
  font-size: 15px;
}

.section__filter:empty {
  display: none;
}

.filter-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  margin-top: 4px;
  padding: 6px 10px;
  border-left: 4px solid var(--marker);
  background: var(--paper-hi);
  color: var(--ink);
  font-size: 14px;
}

.filter-line__count {
  font-family: var(--font-mono);
  font-weight: 700;
}

.filter-line .btn {
  min-height: 32px;
  padding: 3px 10px;
  font-size: 13px;
}

.empty {
  padding: 24px;
  border: 1px dashed var(--rule-strong);
  background: var(--paper-hi);
}

.empty p {
  margin: 0 0 10px;
}

/* ------------------------------------------------------------------- matrix */

.dot-sample {
  display: inline-block;
  width: 11px;
  height: 11px;
  margin: 0 3px;
  border-radius: 50%;
  background: var(--ink);
  vertical-align: -1px;
}

.matrix-frame {
  border: 1px solid var(--ink);
  background-color: var(--paper-hi);
}

.matrix-readout {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  margin: 0;
  padding: 6px 12px;
  background: var(--deck);
  color: var(--phosphor);
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.02em;
}

.matrix-readout::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--phosphor);
  box-shadow: 0 0 0 3px rgba(255, 210, 63, 0.25);
}

.matrix-scroll {
  --rowhead-w: 168px;
  /* 見出し内の視覚的に隠したテキストをこの枠の中に閉じ込め、ページ全体の横幅を広げない */
  position: relative;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-padding-left: var(--rowhead-w);
  background-image:
    linear-gradient(to right, rgba(25, 22, 19, 0.045) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(25, 22, 19, 0.045) 1px, transparent 1px);
  background-size: 12px 12px;
}

.matrix {
  width: 100%;
  min-width: max-content;
  border-collapse: separate;
  border-spacing: 0;
}

.matrix th,
.matrix td {
  padding: 0;
  font-weight: inherit;
}

.matrix__corner {
  position: sticky;
  left: 0;
  z-index: 3;
  width: var(--rowhead-w);
  padding: 10px 10px 8px !important;
  background: var(--paper-hi);
  border-right: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  font-size: 11px;
  line-height: 1.4;
  text-align: left;
  vertical-align: bottom;
  color: var(--ink-2);
}

.matrix__corner span {
  display: block;
}

.matrix__corner .matrix__corner-col {
  text-align: right;
}

.matrix__col {
  min-width: 46px;
  border-left: 1px solid var(--rule);
  border-bottom: 1px solid var(--ink);
  vertical-align: bottom;
}

.matrix__col-btn {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 124px;
  padding: 10px 0 8px;
  border: 0;
  background: transparent;
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1;
  writing-mode: vertical-rl;
  text-orientation: mixed;
}

.matrix__col-no {
  margin-bottom: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--ink-2);
  text-combine-upright: all;
}

.matrix__row-head {
  position: sticky;
  left: 0;
  z-index: 2;
  width: var(--rowhead-w);
  background: var(--paper-hi);
  border-right: 1px solid var(--ink);
  border-top: 1px solid var(--rule);
  text-align: left;
}

.matrix tbody tr:first-child > * {
  border-top: 0;
}

.matrix__row-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 40px;
  padding: 4px 10px;
  border: 0;
  background: transparent;
  font-size: 14px;
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
}

.matrix__row-no {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  color: var(--ink-2);
}

.matrix__cell {
  border-top: 1px solid var(--rule);
  border-left: 1px solid var(--rule);
  text-align: center;
}

.matrix__cell-btn {
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 44px;
  height: 40px;
  border: 0;
  background: transparent;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border: 1.5px solid var(--rule-strong);
  border-radius: 50%;
  vertical-align: middle;
}

.dot--pair {
  width: 15px;
  height: 15px;
  border-color: var(--ink);
  background: var(--ink);
}

/* 照準：ホバー・フォーカス中の行と列 */
.matrix .is-cross {
  background-color: var(--paper-band);
}

/* 選択中の行と列 */
.matrix .is-row-selected,
.matrix .is-col-selected {
  background-color: var(--signal-tint);
}

.matrix__row-btn[aria-pressed="true"],
.matrix__col-btn[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

.matrix__row-btn[aria-pressed="true"] .matrix__row-no,
.matrix__col-btn[aria-pressed="true"] .matrix__col-no {
  color: var(--paper);
}

@media (hover: hover) {
  .matrix__cell-btn:hover .dot {
    border-color: var(--ink);
    transform: scale(1.25);
  }
}

.matrix__cell-btn[aria-pressed="true"] {
  background: var(--signal);
}

.matrix__cell-btn[aria-pressed="true"] .dot {
  border-color: #fff;
  background: #fff;
  animation: stamp 0.22s ease-out;
}

/* 検索に一致する行・列の見出しに蛍光ペンの印 */
.is-hit .matrix__row-name,
.is-hit .matrix__col-name {
  background: linear-gradient(transparent 52%, var(--marker) 52%);
}

.matrix__col.is-hit .matrix__col-name {
  background: linear-gradient(to left, transparent 48%, var(--marker) 48%);
}

.matrix__row-btn[aria-pressed="true"] .matrix__row-name,
.matrix__col-btn[aria-pressed="true"] .matrix__col-name {
  background: none;
}

.matrix-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  margin: 0;
  padding: 8px 12px;
  border-top: 1px solid var(--ink);
  font-size: 13px;
}

.matrix-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.matrix-legend__scroll {
  display: none;
  color: var(--ink-2);
}

@keyframes stamp {
  from {
    transform: scale(1.8);
  }
  to {
    transform: scale(1);
  }
}

/* ---------------------------------------------------------------- selection */

.selection {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  padding: 16px 18px 14px;
  border: 1.5px solid var(--ink);
  background: var(--paper-hi);
  box-shadow: 6px 6px 0 var(--paper-band);
}

.selection__title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 19px;
}

.selection__axes {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: end;
  gap: 10px;
}

.selection__times {
  padding-bottom: 6px;
  font-family: var(--font-serif);
  font-size: 26px;
  color: var(--signal);
}

.field__label {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
  font-weight: 700;
}

.field__select {
  width: 100%;
  height: 46px;
  padding: 0 38px 0 12px;
  border: 1.5px solid var(--ink);
  border-radius: 0;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink) 50%),
    linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
  font-size: 16px;
  appearance: none;
}

.selection__status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.pair-mark {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 22px;
  height: 22px;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
}

.pair-mark--pair {
  background: var(--ink);
  color: var(--paper);
}

.selection__quick {
  display: grid;
  gap: 8px;
}

.selection__quick:empty {
  display: none;
}

.quick-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin: 0;
  font-size: 13px;
}

.quick-row__label {
  font-weight: 700;
  color: var(--ink-2);
}

.selection__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.selection__copy-status:empty {
  display: none;
}

.selection__presets {
  padding-top: 12px;
  border-top: 1px dashed var(--rule-strong);
}

.selection__presets-label {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 700;
}

.selection__presets-note {
  font-weight: 400;
  color: var(--ink-2);
}

.preset-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr));
  gap: 8px;
}

.preset {
  display: grid;
  gap: 1px;
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid var(--ink);
  background: var(--paper);
  text-align: left;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.4;
}

@media (hover: hover) {
  .preset:hover {
    background: var(--paper-band);
  }
}

.preset__formula {
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-2);
}

.selection__copy-status,
.workshop__status {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

/* -------------------------------------------------------------- engine card */

.engine-list {
  display: grid;
  gap: 18px;
}

.engine-card {
  container-type: inline-size;
  position: relative;
  border: 1px solid var(--ink);
  border-top: 6px solid var(--accent);
  background: var(--paper-hi);
  scroll-margin-top: calc(var(--toolbar-h) + 12px);
}

.engine-card.is-selected {
  outline: 3px solid var(--signal);
  outline-offset: -1px;
}

/* 狭い標本：動画と名前を横に並べ、残りは全幅で積む（空の行を作らない） */
.engine-card__grid {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 14px 16px;
  padding: 14px;
}

.specimen {
  grid-column: 1;
  grid-row: 1;
  margin: 0;
}

.engine-card__head {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
}

.engine-card__facts,
.engine-card__ethics,
.engine-card__pair,
.engine-card__actions,
.engine-card__transcript {
  grid-column: 1 / -1;
}

/* 広い標本：動画｜名前と注意｜分類情報 の三段組 */
@container (min-width: 700px) {
  .engine-card__grid {
    grid-template-columns: 176px minmax(0, 1.05fr) minmax(0, 1fr);
    grid-template-areas:
      "spec head facts"
      "spec ethics facts"
      "spec pair facts"
      "spec actions actions"
      "transcript transcript transcript";
    grid-template-rows: auto auto auto 1fr auto;
    gap: 12px 24px;
    padding: 18px;
  }

  .specimen {
    grid-area: spec;
  }

  .engine-card__head {
    grid-area: head;
  }

  .engine-card__facts {
    grid-area: facts;
  }

  .engine-card__ethics {
    grid-area: ethics;
  }

  .engine-card__pair {
    grid-area: pair;
  }

  .engine-card__actions {
    grid-area: actions;
    align-self: end;
  }

  .engine-card__transcript {
    grid-area: transcript;
  }
}

.code-tag {
  display: inline-block;
  padding: 1px 7px;
  background: var(--accent, var(--ink));
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.engine-card__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin: 0;
}

.engine-card__en {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-2);
}

.engine-card__name {
  margin: 4px 0 2px;
  font-family: var(--font-serif);
  font-size: clamp(24px, 4.5cqi, 32px);
  line-height: 1.2;
}

.engine-card__catch {
  margin: 0;
  font-size: 15.5px;
  font-weight: 700;
  line-height: 1.6;
}

.engine-card__summary {
  margin: 8px 0 0;
  font-size: 14px;
  color: var(--ink-2);
}

/* 動画の標本枠 */
.specimen__frame {
  padding: 5px;
  border: 1px solid var(--ink);
  background: var(--bg);
}

.specimen__video {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 9 / 16;
  background: var(--bg);
}

.specimen__video:not([controls]) {
  cursor: pointer;
}

.specimen__controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.specimen__btn {
  display: inline-flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 4px 8px;
  border: 1.5px solid var(--ink);
  background: var(--paper-hi);
  font-size: 13px;
  font-weight: 700;
}

@media (hover: hover) {
  .specimen__btn:hover {
    background: var(--paper-band);
  }
}

.specimen__play {
  background: var(--ink);
  color: var(--paper);
}

@media (hover: hover) {
  .specimen__play:hover {
    background: #3a342d;
  }
}

.specimen__icon {
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 10px solid currentColor;
}

.is-playing .specimen__icon {
  width: 10px;
  height: 12px;
  border: 0;
  border-left: 3px solid currentColor;
  border-right: 3px solid currentColor;
}

.specimen__btn[aria-pressed="true"] {
  background: var(--marker);
}

.specimen__note {
  margin: 6px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-2);
}

.facts {
  display: grid;
  gap: 10px;
  margin: 0;
}

.facts > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0 10px;
  padding-top: 8px;
  border-top: 1px solid var(--rule);
}



.facts > div:first-child {
  padding-top: 0;
  border-top: 0;
}

.facts dt {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-2);
  line-height: 1.8;
}

.engine-card .facts dt {
  letter-spacing: 0.04em;
}

.facts dd {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.7;
}

.loop {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.loop li {
  display: inline-flex;
  align-items: center;
}

.loop li:not(:last-child)::after {
  content: "→" / "";
  margin: 0 6px;
  color: var(--signal);
  font-weight: 700;
}

.loop li span {
  padding: 0 6px;
  border: 1px solid var(--rule-strong);
  background: #fff;
  font-size: 13.5px;
  line-height: 1.6;
}

.ethics-note {
  margin: 0;
  padding: 10px 12px;
  border-left: 5px solid var(--signal);
  background: var(--signal-tint);
  font-size: 14px;
  line-height: 1.65;
}

.ethics-note--watch {
  border-left-color: var(--watch);
  background: var(--watch-tint);
}

.ethics-note__title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 2px;
  font-weight: 800;
}

.ethics-note__icon {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 18px;
  background: var(--signal);
  color: #fff;
  font-size: 12px;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  line-height: 1;
  padding-top: 5px;
}

.ethics-note--watch .ethics-note__icon {
  background: var(--watch);
}

.ethics-note p {
  margin: 0;
}

.pair-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}

.card-actions__pairs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 13px;
}

.card-actions__label {
  font-weight: 700;
  color: var(--ink-2);
}

.transcript {
  border-top: 1px dashed var(--rule-strong);
  padding-top: 6px;
  font-size: 14px;
}

.transcript summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

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

.transcript summary::before {
  content: "＋" / "";
  color: var(--signal);
}

.transcript[open] summary::before {
  content: "－" / "";
}

.transcript p {
  margin: 4px 0 2px;
  color: var(--ink-2);
}

/* --------------------------------------------------------------- theme card */

.theme-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr));
  gap: 16px;
}

.theme-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0;
  border: 1px solid var(--ink);
  background: var(--paper-hi);
  scroll-margin-top: calc(var(--toolbar-h) + 12px);
}

.theme-card.is-selected {
  outline: 3px solid var(--signal);
  outline-offset: -1px;
}

.theme-card__spine {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px 10px;
  border-right: 1px solid var(--ink);
  background: var(--paper);
}

.theme-card__name {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 26px;
  line-height: 1.15;
  letter-spacing: 0.12em;
  writing-mode: vertical-rl;
}

.theme-card__no {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
}

.theme-card__body {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 12px 14px 14px;
  min-width: 0;
}

.theme-card__en {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-2);
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.swatches li {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--ink-2);
}

.swatch {
  width: 18px;
  height: 18px;
  border: 1px solid var(--ink);
  background: var(--c);
}

.vocab {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.vocab li {
  padding: 1px 8px;
  border: 1px solid var(--ink);
  background: #fff;
  font-size: 13.5px;
  font-weight: 600;
}

.theme-card .facts {
  margin-top: 8px;
}

.theme-card .facts > div {
  grid-template-columns: 3.2em minmax(0, 1fr);
}

.theme-card .facts dd {
  font-size: 13.5px;
}

/* ---------------------------------------------------- workshop（実験装置） */

.workshop {
  --focus: var(--phosphor);
  display: grid;
  align-content: start;
  gap: 16px;
  margin-top: 36px;
  padding: 18px 18px 20px;
  border: 1px solid #000;
  background: var(--deck);
  color: var(--deck-ink);
  scroll-margin-top: calc(var(--toolbar-h) + 12px);
}

.workshop__head {
  display: grid;
  gap: 4px;
}

.workshop__label {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--phosphor);
}

.workshop__title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 28px;
  line-height: 1.25;
}

.workshop__combo {
  margin: 6px 0 0;
  padding: 8px 10px;
  border: 1px dashed var(--deck-line);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.5;
}

.workshop__combo .muted {
  color: var(--deck-muted);
  font-weight: 400;
}

.workshop__combo .code {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--phosphor);
  margin-right: 4px;
}

.workshop__pair {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 13.5px;
  color: var(--deck-muted);
}

.workshop__pair:empty {
  display: none;
}

.workshop .pair-mark {
  border-color: var(--deck-ink);
}

.workshop .pair-mark--pair {
  background: var(--phosphor);
  border-color: var(--phosphor);
  color: var(--ink);
}

.workshop__empty {
  padding: 12px 14px;
  border-left: 4px solid var(--phosphor);
  background: var(--deck-2);
  font-size: 14px;
}

.workshop__empty p {
  margin: 0 0 6px;
}

.workshop__steps {
  margin: 0;
  padding-left: 1.5em;
  color: var(--deck-muted);
  font-size: 13px;
}

.workshop__body {
  display: grid;
  gap: 16px;
}

.workshop__form {
  display: grid;
  gap: 14px;
  padding: 12px 0 2px;
}

.workshop__more {
  border-top: 1px solid var(--deck-line);
  padding-top: 4px;
}

.workshop__more-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 10px;
  min-height: 40px;
  padding: 8px 0 4px;
  cursor: pointer;
  list-style: none;
}

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

.workshop__more-summary::before {
  content: "＋" / "";
  color: var(--phosphor);
  font-weight: 700;
}

.workshop__more[open] > .workshop__more-summary::before {
  content: "－" / "";
}

.workshop__more-title {
  font-size: 14px;
  font-weight: 700;
}

.workshop__more-state {
  font-size: 12.5px;
  color: var(--deck-muted);
}

.workshop__field {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.workshop__field legend,
.workshop__field > label,
.workshop__output-head label {
  display: block;
  margin-bottom: 6px;
  padding: 0;
  font-size: 13px;
  font-weight: 700;
}

.workshop__optional {
  margin-left: 8px;
  font-weight: 400;
  color: var(--deck-muted);
  font-size: 12px;
}

.sub-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sub-chip {
  min-height: 32px;
  padding: 3px 10px;
  border: 1px solid var(--deck-line);
  border-radius: 999px;
  background: transparent;
  color: var(--deck-ink);
  font-size: 13px;
  font-weight: 600;
}

@media (hover: hover) {
  .sub-chip:hover:not(:disabled) {
    border-color: var(--deck-ink);
  }
}

.sub-chip[aria-pressed="true"] {
  background: var(--phosphor);
  border-color: var(--phosphor);
  color: var(--ink);
}

.sub-chip[aria-pressed="true"]::before {
  content: "＋" / "";
}

.sub-chip:disabled {
  border-style: dashed;
  color: var(--deck-muted);
}

.workshop__hint {
  margin: 6px 0 0;
  font-size: 12.5px;
  color: var(--deck-muted);
}

.workshop__hint:empty {
  display: none;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--deck-line);
}

.segmented__opt {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 40px;
  padding: 4px 6px;
  border-left: 1px solid var(--deck-line);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
}

.segmented__opt:first-child {
  border-left: 0;
}

.segmented__opt input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented__opt:has(input:checked) {
  background: var(--deck-ink);
  color: var(--ink);
}

.segmented__opt:has(input:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: -3px;
}

.workshop__input {
  width: 100%;
  height: 42px;
  padding: 0 10px;
  border: 1.5px solid var(--deck-line);
  border-radius: 0;
  background: var(--deck-field);
  color: var(--deck-ink);
  font-size: 16px;
}

.workshop__input::placeholder,
.workshop__textarea::placeholder {
  color: #a39a8c;
}

.workshop__field--check {
  display: flex;
  align-items: center;
  gap: 10px;
}

.workshop__field--check input {
  width: 24px;
  height: 24px;
  margin: 0;
  accent-color: var(--phosphor);
}

.workshop__field--check label {
  margin: 0;
  font-weight: 600;
  font-size: 14px;
}

.workshop__output {
  display: grid;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--deck-line);
}

.workshop__output-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
}

.workshop__output-head label {
  margin: 0;
}

.workshop__meta {
  display: flex;
  gap: 10px;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--deck-muted);
}

.workshop__dirty {
  padding: 0 6px;
  background: var(--phosphor);
  color: var(--ink);
  font-weight: 700;
}

.workshop__textarea {
  display: block;
  width: 100%;
  min-height: 300px;
  height: clamp(300px, 48vh, 560px);
  padding: 12px;
  border: 1.5px solid var(--deck-line);
  border-radius: 0;
  background: var(--deck-field);
  color: var(--deck-ink);
  font-size: 13.5px;
  line-height: 1.65;
  resize: vertical;
}

.workshop__stale {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--phosphor);
  font-size: 13.5px;
}

.workshop__stale p {
  margin: 0;
}

.workshop__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.workshop__actions .btn--large {
  flex: 1 1 100%;
}

.workshop__actions .btn--deck {
  flex: 1 1 auto;
}

.workshop__status {
  min-height: 1.6em;
  color: var(--phosphor);
}

.workshop__status.is-error {
  color: #ffb4a0;
}

.workshop__status:not(:empty)::before,
.selection__copy-status:not(:empty)::before {
  content: "■ " / "";
}

.workshop.is-empty .workshop__body {
  display: none;
}

/* ------------------------------------------------------------------- ethics */

.ethics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  gap: 16px 28px;
}

.ethics__title {
  margin: 0 0 8px;
  font-family: var(--font-serif);
  font-size: 19px;
}

.ethics__list {
  margin: 0;
  padding-left: 1.6em;
  font-size: 15px;
}

.ethics__list li {
  padding: 4px 0;
  border-bottom: 1px solid var(--rule);
}

.ethics__list--flags {
  padding: 0;
  list-style: none;
}

.ethics__list--flags li {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.ethics__list--flags li::before {
  content: "▲" / "";
  color: var(--signal);
  font-size: 12px;
}

.ethics__closing {
  margin: 20px 0 0;
  padding: 14px 16px;
  border: 1.5px solid var(--ink);
  background: var(--paper-hi);
  font-family: var(--font-serif);
  font-size: 17px;
}

/* ------------------------------------------------------------------- footer */

.footer {
  border-top: 3px double var(--ink);
}

.footer__inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 18px var(--gutter) 28px;
  font-size: 13px;
  color: var(--ink-2);
}

.footer__inner p {
  margin: 0 0 4px;
}

/* --------------------------------------------------------------------- dock */

.dock {
  --focus: var(--phosphor);
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px var(--gutter) calc(8px + env(safe-area-inset-bottom));
  border-top: 2px solid var(--phosphor);
  background: var(--deck);
  color: var(--deck-ink);
}

.dock__combo {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dock__link {
  flex: none;
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 6px 14px;
  background: var(--phosphor);
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
}

/* --------------------------------------------------------------- responsive */

@media (min-width: 1180px) {
  .toolbar {
    position: sticky;
    top: 0;
    z-index: 20;
  }

  .layout {
    grid-template-columns: minmax(0, 1fr) clamp(380px, 30vw, 440px);
    grid-template-areas:
      "matrix prompt"
      "engines prompt"
      "themes prompt"
      "ethics prompt";
    column-gap: 32px;
  }

  .section--matrix {
    grid-area: matrix;
  }

  .section--engines {
    grid-area: engines;
  }

  .section--themes {
    grid-area: themes;
  }

  .section--ethics {
    grid-area: ethics;
  }

  .workshop {
    grid-area: prompt;
    position: sticky;
    top: calc(var(--toolbar-h) + 16px);
    align-self: start;
    max-height: calc(100vh - var(--toolbar-h) - 32px);
    overflow-y: auto;
    scrollbar-color: var(--deck-line) var(--deck);
  }

  .workshop__textarea {
    min-height: 180px;
    height: clamp(180px, calc(100vh - var(--toolbar-h) - 600px), 560px);
  }

  .dock {
    display: none !important;
  }
}

@media (max-width: 960px) {
  .masthead__body {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }

  .stages__list {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .stage {
    display: grid;
    grid-template-columns: 3.4em 6.4em minmax(0, 1fr);
    align-items: baseline;
    gap: 0 10px;
    padding: 8px 12px;
  }

  .stage:not(:last-child)::after {
    content: "↓" / "";
    top: auto;
    right: auto;
    bottom: -17px;
    left: 22px;
    transform: none;
    font-size: 13px;
    line-height: 1;
  }

  .stage__name {
    margin: 0;
    font-size: 17px;
  }
}

@media (max-width: 759px) {
  .masthead__nav ul {
    gap: 0 14px;
  }

  .masthead__counts dd {
    font-size: 24px;
  }

  .masthead__counts div {
    padding: 6px 6px 8px;
  }

  .stages {
    grid-template-columns: minmax(0, 1fr);
  }

  .stages__title {
    writing-mode: horizontal-tb;
    border-left: 0;
    border-bottom: 1px solid var(--ink);
    padding: 0 0 2px;
    letter-spacing: 0.2em;
    justify-self: start;
  }

  .stages__note {
    grid-column: 1;
  }

  .stage {
    grid-template-columns: 2.6em 5.6em minmax(0, 1fr);
  }

  .search {
    flex-basis: 100%;
    max-width: none;
  }

  .search__label {
    font-size: 13px;
  }

  .toolbar__clear {
    margin-left: 0;
  }

  .section__head {
    grid-template-columns: minmax(0, 1fr);
  }

  .section__no {
    font-size: 16px;
  }

  .section__lede,
  .section__filter {
    grid-column: 1;
  }

  .matrix-scroll {
    --rowhead-w: 84px;
  }

  .matrix__row-btn {
    min-height: 40px;
    padding: 4px 6px 4px 8px;
    font-size: 13px;
  }

  .matrix__row-no,
  .matrix__row-suffix {
    display: none;
  }

  .matrix__col {
    min-width: 38px;
  }

  .matrix__cell-btn {
    min-width: 38px;
  }

  .matrix__col-btn {
    min-height: 116px;
    font-size: 14px;
    letter-spacing: 0.04em;
  }

  .matrix__corner {
    font-size: 10px;
    padding: 8px 6px !important;
  }

  .matrix-legend__scroll {
    display: inline-flex;
  }

  .selection {
    padding: 14px;
    box-shadow: 4px 4px 0 var(--paper-band);
  }

  .selection__axes {
    grid-template-columns: minmax(0, 1fr);
  }

  .selection__times {
    display: none;
  }

  .workshop {
    margin-right: calc(var(--gutter) * -1);
    margin-left: calc(var(--gutter) * -1);
    padding: 18px var(--gutter) 22px;
    border-right: 0;
    border-left: 0;
  }

  .theme-card__name {
    font-size: 22px;
  }

  /* iOS で入力時に拡大されないよう 16px 以上にする */
  .workshop__textarea {
    font-size: 16px;
    line-height: 1.6;
  }
}

/* 動きを減らす設定：装飾的な遷移と滑らかなスクロールを止める */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .matrix__cell-btn:hover .dot {
    transform: none;
  }
}

/* 強制カラー（ハイコントラスト）でも相性の印と選択状態を残す */
@media (forced-colors: active) {
  .dot--pair,
  .dot-sample {
    forced-color-adjust: none;
    background: CanvasText;
    border-color: CanvasText;
  }

  .matrix__cell-btn[aria-pressed="true"],
  .matrix__row-btn[aria-pressed="true"],
  .matrix__col-btn[aria-pressed="true"],
  .chip[aria-pressed="true"],
  .sub-chip[aria-pressed="true"],
  .btn--select[aria-pressed="true"] {
    outline: 3px solid Highlight;
    outline-offset: -3px;
  }
}
