:root {
  --bg: #0b0d12;
  --surface: #151922;
  --surface-2: #1d2230;
  --border: #2a3142;
  --text: #e6e8ee;
  --muted: #8b93a7;
  --accent: #6ea8ff;
  --accent-text: #0b0d12;
  --green: #4ade80;
  --lime: #a3e635;
  --yellow: #facc15;
  --orange: #fb923c;
  --red: #f87171;
  --mono: ui-monospace, "JetBrains Mono", Menlo, monospace;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  display: grid;
  grid-template-columns: 320px 1fr;
  font:
    13px / 1.5 system-ui,
    sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* ja のパラメーター名に添えるオプション名。ふりがなとして控えめに */
rt {
  font: 9px var(--mono);
  color: var(--muted);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

h1 {
  margin: 0;
  font-size: 16px;
}

h2 {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

button,
select,
input {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
}

button {
  padding: 4px 10px;
  cursor: pointer;
}

button:hover {
  background: var(--border);
  color: var(--text);
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button.is-active,
button.is-active:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

/* ---- 左パネル ---- */

.panel {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 16px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

/* 既定値に戻すはめったに使わず、押し間違えると調整が消えるので、パネルの最下部右に小さく置く */
.panel-foot {
  margin-top: auto;
  padding-top: 12px;
  display: flex;
  justify-content: flex-end;
}

button.quiet {
  padding: 2px 6px;
  font-size: 11px;
  color: var(--muted);
  background: transparent;
  border-color: transparent;
}

button.quiet:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}

.panel section {
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.row {
  display: grid;
  grid-template-columns: 76px 1fr auto;
  gap: 8px;
  align-items: center;
  margin: 4px 0;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.section-head h2 {
  margin: 0;
}

/* 既定は代表値のボタンだけ。「詳細」でスライダーに切り替える (細かい値は使う人が限られる) */
/* 代表値は目盛り付きの段。点と値を 1 つのボタンにし、線は最初と最後の点の間だけに引く */
.presets {
  position: relative;
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
}

.presets::before {
  content: "";
  position: absolute;
  top: 9px;
  height: 2px;
  /* 列が N 等分なので、端の点の中心は端から 1/(2N)。4 段前提 */
  left: 12.5%;
  right: 12.5%;
  background: var(--border);
}

.presets button,
.presets button:hover {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 3px 0 2px;
  background: none;
  border: 0;
  font: 10px var(--mono);
  color: var(--muted);
}

.presets button:hover {
  color: var(--text);
}

.stop-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg);
}

.presets button:hover .stop-dot {
  border-color: var(--muted);
}

.presets button.is-active,
.presets button.is-active:hover {
  background: none;
  color: var(--text);
}

.presets button.is-active .stop-dot {
  border-color: var(--accent);
  background: var(--accent);
}

.ranges .row input[type="range"] {
  display: none;
}

.ranges.is-detail .row input[type="range"] {
  display: block;
}

.ranges.is-detail .presets {
  display: none;
}

.row output {
  min-width: 44px;
  text-align: right;
  font-family: var(--mono);
  color: var(--muted);
}

.field {
  margin: 6px 0;
}

.field-label {
  display: block;
  margin-bottom: 4px;
}

.schemes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

/* 地と文字色はパネル側に固定し、配色の見た目は縮図の canvas だけで見せる (地の色で文字が読めなくなるのを避ける) */
.colors-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.colors {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.colors input[type="color"] {
  width: 28px;
  height: 24px;
  padding: 1px;
  cursor: pointer;
}

.scheme-card {
  display: grid;
  gap: 4px;
  padding: 4px;
  text-align: left;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.scheme-card:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--muted);
}

.scheme-card[aria-pressed="true"] {
  border-color: var(--accent);
}

.scheme-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.scheme-card canvas {
  width: 100%;
  aspect-ratio: 136 / 64;
  display: block;
  border-radius: 3px;
}

.scheme-name {
  font-size: 11px;
  font-weight: 600;
}

.scheme-strip {
  display: flex;
  height: 5px;
  border-radius: 2px;
  overflow: hidden;
}

.scheme-strip i {
  flex: 1;
}

.buttons {
  display: flex;
  gap: 6px;
  margin: 6px 0;
}

.styles {
  display: grid;
  gap: 3px;
  margin-top: 4px;
}

.style-row {
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 8px;
  align-items: center;
}

.segs {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.seg {
  position: relative;
  display: grid;
  place-items: center;
  padding: 2px 0;
  font-size: 11px;
  color: var(--muted);
  background: var(--surface);
  cursor: pointer;
}

.seg + .seg {
  border-left: 1px solid var(--border);
}

/* radio 自体は隠し、ラベル全体を押せる面にする (キーボード操作と読み上げは input が担う) */
.seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg:hover {
  color: var(--text);
  background: var(--surface-2);
}

.seg:has(input:checked) {
  color: var(--accent-text);
  background: var(--accent);
}

.seg:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.style-legend {
  line-height: 1.6;
}

fieldset.field {
  padding: 0;
  border: 0;
}

.chip {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.mx {
  display: grid;
  gap: 2px;
  margin-top: 8px;
  user-select: none;
}

.mx-head {
  border-radius: 4px;
}

.mx-head-col {
  height: 8px;
  align-self: end;
}

.mx-head-row {
  width: 8px;
  align-self: stretch;
}

.mx-cell {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font: 10px var(--mono);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: ns-resize;
  touch-action: none;
}

.hint {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--muted);
}

/* ---- 右側 ---- */

.main {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(240px, 1fr) auto;
  gap: 10px;
  padding: 12px;
  overflow: hidden;
}

.head-links {
  display: flex;
  align-items: center;
  gap: 8px;
}

.gh {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}

.gh:hover,
.gh:focus-visible {
  text-decoration: underline;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 12px;
}

.check {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

/* 二択・数択はつなげたトグルにする。選択側だけ塗る */
.toggle-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.toggle-group button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 0;
  border-radius: 0;
  padding: 3px 9px;
  font: 12px var(--mono);
  color: var(--muted);
}

.toggle-group button + button {
  border-left: 1px solid var(--border);
}

.toggle-group button:hover {
  color: var(--text);
}

.toggle-group button.is-active,
.toggle-group button.is-active:hover {
  background: var(--accent);
  color: var(--accent-text);
}

/* オン / オフの即時反映の設定はスイッチ。押せる範囲は文字まで含め、高さ 24px を確保する (WCAG 2.5.8) */
.switch,
.switch:hover {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 0 2px;
  background: none;
  border: 0;
  font-size: 12px;
  color: var(--muted);
}

.switch:hover,
.switch[aria-checked="true"] {
  color: var(--text);
}

.switch .track {
  position: relative;
  flex: none;
  width: 28px;
  height: 16px;
  border-radius: 999px;
  background: var(--border);
  transition: background 0.15s;
}

.switch .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.15s;
}

.switch[aria-checked="true"] .track {
  background: var(--accent);
}

.switch[aria-checked="true"] .track::after {
  transform: translateX(12px);
  background: var(--accent-text);
}

@media (prefers-reduced-motion: reduce) {
  .switch .track,
  .switch .track::after {
    transition: none;
  }
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.stage {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  /* 端末の枠を外側に描く余白。stage.js の BEZEL_PAD_PX と揃える */
  padding: 14px;
  overflow: hidden;
  background:
    repeating-conic-gradient(var(--surface) 0 25%, var(--bg) 0 50%) 0 0 / 16px
    16px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.stage[data-scale]::after {
  content: attr(data-scale);
  position: absolute;
  right: 8px;
  bottom: 6px;
  font: 11px var(--mono);
  color: var(--muted);
}

/* cover は 1 画面ぶんを大きく見せ、続きは stage の中でスクロールして見る */
.stage[data-fit="cover"] {
  align-items: start;
  overflow: auto;
}

.frame-holder {
  position: relative;
}

.frame-clip {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* 最初の 1 画面を囲う端末の枠。外側に影で描き、中の操作は iframe に通す */
.device-screen {
  position: absolute;
  inset: 0 0 auto;
  border-radius: 4px;
  box-shadow:
    0 0 0 6px var(--surface-2),
    0 0 0 7px var(--border);
  pointer-events: none;
}

.device-screen[data-device="mobile"],
.device-screen[data-device="tablet"] {
  border-radius: 10px;
  box-shadow:
    0 0 0 9px var(--surface-2),
    0 0 0 10px var(--border);
}

/* 枠より下 = スクロールしないと見えない部分。少し暗くして 1 画面目と見分ける */
.device-fold {
  position: absolute;
  inset: auto 0 0;
  background: rgb(0 0 0 / 0.4);
  pointer-events: none;
}

.device-fold::before {
  content: "↓ " attr(data-label);
  position: absolute;
  top: 12px;
  left: 0;
  right: 0;
  text-align: center;
  font: 11px var(--mono);
  color: var(--muted);
}

.frame-holder iframe {
  display: block;
  border: 0;
  transform-origin: 0 0;
}

.bottom {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-height: 42vh;
  min-height: 0;
}

.card {
  min-width: 0;
  overflow: auto;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.card-head h2 {
  margin: 0;
}

pre {
  margin: 0;
  padding: 10px;
  overflow: auto;
  font: 12px / 1.5 var(--mono);
  background: var(--bg);
  border-radius: 6px;
}

.perf {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.perf th,
.perf td {
  padding: 3px 6px;
  text-align: left;
  white-space: nowrap;
}

.perf th {
  color: var(--muted);
  font-weight: 500;
}

.perf tbody tr {
  cursor: pointer;
  border-top: 1px solid var(--border);
}

.perf tbody tr:hover {
  background: var(--surface-2);
}

.perf tr.is-current {
  background: var(--surface-2);
  outline: 1px solid var(--accent);
}

.perf td:nth-child(3) {
  letter-spacing: 0.05em;
}

.stars-5 td:nth-child(3) {
  color: var(--green);
}
.stars-4 td:nth-child(3) {
  color: var(--lime);
}
.stars-3 td:nth-child(3) {
  color: var(--yellow);
}
.stars-2 td:nth-child(3) {
  color: var(--orange);
}
.stars-1 td:nth-child(3) {
  color: var(--red);
}

.meter {
  margin: 8px 0 0;
  font-family: var(--mono);
}

@media (max-width: 900px) {
  body {
    height: auto;
    grid-template-columns: 1fr;
  }
  .main {
    grid-template-rows: auto 60vh auto;
  }
  .bottom {
    grid-template-columns: 1fr;
    max-height: none;
  }
}
