/* ツールの見た目。プレビュー（#preview の中）はトークンから inline で塗るのでここでは骨組みだけ */
:root {
  --tool: #2962FF;
  --tool-ink: #1b1f27;
  --tool-sub: #5b6270;
  --tool-line: #e3e6eb;
  --tool-bg: #f4f5f7;
  --tool-panel: #ffffff;
  font-family: system-ui, -apple-system, "Hiragino Sans", sans-serif;
  color: var(--tool-ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--tool-bg); font-size: 13px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

.bar { height: 52px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; background: var(--tool-panel); border-bottom: 1px solid var(--tool-line); position: sticky; top: 0; z-index: 10; }
.bar-title { font-weight: 700; font-size: 15px; }
.bar-title span { color: var(--tool); }
.bar-actions { display: flex; gap: 8px; }
.btn { font: inherit; border: 1px solid var(--tool-line); background: var(--tool-panel); color: var(--tool-ink); padding: 7px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c5cad3; }
.btn.primary { background: var(--tool); border-color: var(--tool); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.ghost { background: transparent; }
.btn.is-armed { background: #c62828; border-color: #c62828; color: #fff; }
.btn:disabled { opacity: .45; cursor: default; }

.layout { display: grid; grid-template-columns: 380px 1fr; height: calc(100vh - 52px); }
.inspector { background: var(--tool-panel); border-right: 1px solid var(--tool-line); overflow-y: auto; }
.tabs { display: flex; position: sticky; top: 0; background: var(--tool-panel); border-bottom: 1px solid var(--tool-line); z-index: 2; }
.tab { flex: 1; font: inherit; border: 0; background: none; padding: 12px 0; cursor: pointer; color: var(--tool-sub); border-bottom: 2px solid transparent; }
.tab.is-active { color: var(--tool); border-bottom-color: var(--tool); font-weight: 600; }
.panel { display: none; padding: 16px; }
.panel.is-active { display: block; }

.field { margin-bottom: 16px; }
.field > label, .field > div > label { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 6px; }
.field output { font-weight: 400; color: var(--tool-sub); font-family: ui-monospace, Menlo, monospace; }
.field.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
input[type=text], select, textarea { font: inherit; width: 100%; padding: 7px 8px; border: 1px solid var(--tool-line); border-radius: 6px; background: #fff; color: var(--tool-ink); }
textarea { resize: vertical; line-height: 1.6; }
input[type=color] { width: 40px; height: 34px; padding: 2px; border: 1px solid var(--tool-line); border-radius: 6px; background: #fff; flex: none; }
input[type=range] { width: 100%; accent-color: var(--tool); }
.note { color: var(--tool-sub); font-weight: 400; font-size: 11px; margin: 4px 0 0; }
.note.lead { margin: 0 0 16px; font-size: 12px; }
.sub { font-size: 12px; margin: 20px 0 8px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }

.seg { display: flex; border: 1px solid var(--tool-line); border-radius: 6px; overflow: hidden; }
.seg button { flex: 1; font: inherit; border: 0; border-right: 1px solid var(--tool-line); background: #fff; padding: 6px 0; cursor: pointer; color: var(--tool-sub); }
.seg button:last-child { border-right: 0; }
.seg button.is-on { background: var(--tool); color: #fff; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid2 label { font-size: 11px; color: var(--tool-sub); display: block; margin-bottom: 2px; }
.scale-strip { display: flex; gap: 4px; margin-top: 8px; flex-wrap: wrap; }
.scale-strip span { font-size: 10px; color: var(--tool-sub); background: var(--tool-bg); border-radius: 4px; padding: 2px 6px; font-family: ui-monospace, Menlo, monospace; }

/* 役割 */
.roles { border: 1px solid var(--tool-line); border-radius: 8px; overflow: hidden; }
.role-group { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--tool-sub); background: var(--tool-bg); padding: 4px 10px; }
.role { display: grid; grid-template-columns: 22px 1fr auto auto; gap: 8px; align-items: center; padding: 5px 10px; cursor: pointer; border-top: 1px solid var(--tool-line); }
.role:hover { background: #f8f9fb; }
.role.is-active { background: #eef3ff; box-shadow: inset 3px 0 0 var(--tool); }
.role.is-ng { background: #fdeceb; }
.role.is-ng:hover { background: #fbe2e0; }
.role.is-ng.is-active { background: #fbe2e0; box-shadow: inset 3px 0 0 #c62828; }
.role .warn { color: #c62828; font-size: 11px; font-weight: 700; cursor: help; }
.role .sw { width: 22px; height: 22px; border-radius: 5px; border: 1px solid rgba(0,0,0,.1); }
.role .k { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.role .ref { font-family: ui-monospace, Menlo, monospace; font-size: 11px; color: var(--tool-sub); }
.role .ref.custom { color: #b45309; }
.role-edit { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 8px; padding: 8px 0 4px; cursor: default; }
.role-edit input[type=text] { font-size: 12px; padding: 6px 8px; }
.role-edit .row.end { justify-content: flex-end; }
.seg.mini button { padding: 4px 0; font-size: 12px; }

/* マトリクス */
.matrix { display: grid; grid-template-columns: 56px repeat(14, minmax(0, 1fr)); gap: 1px; }
.matrix .lbl { font-size: 9px; color: var(--tool-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; align-self: center; }
.matrix .lbl.anchor { color: var(--tool); font-weight: 700; }
.matrix .head { font-size: 8px; color: var(--tool-sub); text-align: center; }
.cell, .chip-cell { aspect-ratio: 1; border: 0; padding: 0; cursor: pointer; position: relative; border-radius: 2px; }
.chip-cell { width: 18px; background: #fff; border: 1px solid var(--tool-line); }
.chip-cell.black { background: #000; }
.chips { display: flex; gap: 4px; align-items: center; margin-bottom: 6px; }
.cell.ng, .chip-cell.ng { opacity: .28; }
.cell.ng.is-target, .chip-cell.ng.is-target { opacity: 1; outline-color: #c62828; }
.cell:hover, .chip-cell:hover { opacity: 1; }
.cell:hover, .chip-cell:hover { outline: 2px solid var(--tool-ink); z-index: 1; }
.cell.used::after, .chip-cell.used::after { content: ""; position: absolute; inset: 35%; border-radius: 50%; background: currentColor; }
.cell.is-target, .chip-cell.is-target { outline: 2px solid var(--tool); outline-offset: 1px; z-index: 2; }

.contrast { display: grid; gap: 2px; }
.contrast .pair { display: grid; grid-template-columns: 1fr 52px 36px; gap: 6px; align-items: center; font-size: 11px; padding: 4px 8px; border-radius: 6px; background: var(--tool-bg); }
.contrast .demo { border-radius: 4px; padding: 2px 6px; font-family: ui-monospace, Menlo, monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contrast .ok { color: #0a7a3d; font-weight: 700; }
.contrast .ng { color: #c62828; font-weight: 700; }

.type-scale { border-top: 1px solid var(--tool-line); padding-top: 12px; }
.type-scale div { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; overflow: hidden; }
.type-scale code { font-size: 10px; color: var(--tool-sub); flex: none; }
.type-scale span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ステージ */
.stage { overflow: auto; padding: 16px 24px 24px; }
.stage-bar { display: flex; justify-content: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.stage-bar .seg { width: 180px; background: #fff; }
.mode-box { display: flex; gap: 12px; align-items: center; }
.mode-box .seg { flex: 1; }
.check { display: flex; gap: 6px; align-items: center; white-space: nowrap; cursor: pointer; }
.mode-seg button[data-v="dark"].is-on { background: #1b1f27; }
body.editing-dark .roles { border-color: #1b1f27; }
body.editing-dark .role-group { background: #1b1f27; color: #c9ced8; }
body.editing-dark .stage { background: #2a2e36; }
[hidden] { display: none !important; }

/* アプリのプレビュー（端末の枠） */
.phones { display: flex; gap: 28px; justify-content: center; flex-wrap: wrap; padding-bottom: 8px; }
.phone { width: 360px; height: 740px; border: 10px solid #15171c; border-radius: 44px; overflow: hidden; position: relative; display: flex; flex-direction: column; box-shadow: 0 8px 32px rgba(0,0,0,.12); flex: none; }
.phone .ic { width: 24px; height: 24px; display: block; }
.app-status { display: flex; justify-content: space-between; padding: 10px 24px 6px; font-weight: 600; }
.app-bar { display: grid; grid-template-columns: 28px 1fr 28px; align-items: center; padding: 8px 16px 12px; border-bottom: 1px solid; text-align: center; }
.app-bar:has(> strong:first-child) { grid-template-columns: 1fr 28px; text-align: left; }
.app-body { flex: 1; overflow: hidden; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.app-hello { display: flex; flex-direction: column; gap: 2px; padding: 4px 0; }
.app-card { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 20px !important; }
.app-section-title { margin-top: 4px; }
.app-list { display: flex; flex-direction: column; padding: 4px 16px !important; }
.app-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; }
.app-avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 15px !important; }
.app-item-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.app-more { align-self: center; }
.pv-btn.wide { width: 100%; }
.phone-toast { position: absolute; left: 16px; right: 16px; bottom: 84px; text-align: center; }
.app-tabbar { display: flex; border-top: 1px solid; padding: 8px 0 18px; }
.app-tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.app-form { gap: 6px; }
.app-form label { margin-top: 10px; }
.app-form input { width: 100%; }
.app-form [data-c="alert-error"] { margin-bottom: 4px; }
.app-actions { display: flex; gap: 10px; padding: 12px 16px 24px; border-top: 1px solid; }
.app-scrim { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.app-sheet { position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; gap: 12px; border-bottom-left-radius: 0 !important; border-bottom-right-radius: 0 !important; padding-bottom: 32px !important; }
.frame { max-width: 1120px; margin: 0 auto; border-radius: 10px; overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 32px rgba(0,0,0,.08); }

/* プレビューの骨組み（値は inline） */
.pv-root h1, .pv-root h2, .pv-root h3, .pv-root p { margin: 0; }
.pv-root button, .pv-root input { appearance: none; -webkit-appearance: none; outline: none; }
.pv-nav { display: flex; justify-content: space-between; align-items: center; border-width: 0 0 1px 0 !important; }
.pv-nav-links { display: flex; gap: 24px; align-items: center; }
.pv-btn { cursor: pointer; transition: background-color .15s; }
.pv-root [data-c^="button-primary"]:hover { background-color: var(--hover-bg) !important; }
.pv-root [data-c^="button-primary"]:active { background-color: var(--press-bg) !important; }
.pv-root [data-c="button-disabled"] { cursor: not-allowed; }
.pv-hero { padding: 96px 48px 80px; display: flex; flex-direction: column; align-items: flex-start; gap: 20px; }
.pv-lead { max-width: 36em; }
.pv-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.pv-row.end { justify-content: flex-end; }
[data-c="section-alt"] { display: flex; flex-direction: column; gap: 32px; }
.pv-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.pv-cards article { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
[data-c^="badge"] { display: inline-block; }
.pv-split { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; padding: 80px 48px; align-items: start; }
.pv-form { display: flex; flex-direction: column; gap: 8px; }
.pv-form h2 { margin-bottom: 8px; }
.pv-form label { margin-top: 8px; }
.pv-form input { width: 100%; }
.pv-form .pv-row { margin-top: 16px; }
.pv-stack { display: flex; flex-direction: column; gap: 16px; }
.pv-modal { display: flex; flex-direction: column; gap: 12px; }
[data-c="toast"] { align-self: center; }
[data-c="link"] { text-decoration: underline; text-underline-offset: 3px; }

dialog { width: min(860px, 92vw); height: 82vh; border: 0; border-radius: 12px; padding: 0; box-shadow: 0 24px 64px rgba(0,0,0,.3); }
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgba(15, 20, 30, .45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--tool-line); }
#md-output { flex: 1; border: 0; border-radius: 0; padding: 16px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; resize: none; }

.app-toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--tool-ink); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: min(640px, 90vw); white-space: pre-line; line-height: 1.6; }
.toast-action { font: inherit; font-weight: 700; margin-left: 12px; background: none; border: 1px solid rgba(255,255,255,.5); color: #fff; border-radius: 6px; padding: 3px 10px; cursor: pointer; }
body.dragging::after { content: "design.md をドロップして読み込む"; position: fixed; inset: 12px; border: 3px dashed var(--tool); border-radius: 16px; background: rgba(41, 98, 255, .08); display: grid; place-items: center; font-size: 18px; color: var(--tool); font-weight: 700; z-index: 100; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .inspector { border-right: 0; border-bottom: 1px solid var(--tool-line); }
  .stage { padding: 12px; }
  .bar-actions .btn.ghost:not(label) { display: none; }
  .pv-cards, .pv-split { grid-template-columns: 1fr; }
  .pv-hero, .pv-split { padding: 48px 20px; }
  .pv-nav-links span { display: none; }
  .phone { width: 100%; max-width: 360px; }
}

/* プレビューの点検（ホバーで役割を出す） */
.pv-root, .pv-root * { cursor: crosshair !important; }
.pv-root *:hover { outline: 1px dashed rgba(41, 98, 255, .6); outline-offset: 1px; }
.inspect { position: fixed; z-index: 60; pointer-events: none; background: #1b1f27; color: #fff; border-radius: 8px; padding: 8px 10px; font-size: 12px; line-height: 1.7; box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: 320px; }
.inspect strong { display: block; font-family: ui-monospace, Menlo, monospace; margin-bottom: 2px; }
.inspect code { font-family: ui-monospace, Menlo, monospace; color: #c9d4ff; }
.inspect .ok { color: #7ee2a8; font-weight: 700; }
.inspect .ng { color: #ff8a80; font-weight: 700; }
.inspect .tip-hint { color: #9aa3b2; font-size: 11px; margin-top: 2px; }
.tip-sw { display: inline-block; width: 11px; height: 11px; border-radius: 3px; border: 1px solid rgba(255,255,255,.4); margin-right: 6px; vertical-align: -1px; }
.role[data-hover] { box-shadow: inset 0 0 0 2px var(--tool); background: #eef3ff; }
.role { position: relative; scroll-margin-top: 56px; }
.role[data-hover]::after { content: attr(data-hover); position: absolute; top: 0; left: 36px; transform: translateY(-1px); background: var(--tool); color: #fff; font-size: 9px; font-weight: 700; padding: 0 5px; border-radius: 0 0 4px 4px; line-height: 1.5; }

/* unitcell tools の入口へ戻るリンク（道具をまたいで同じ形。文字色は周りから継ぐ） */
.ut-home { color: inherit; opacity: 0.6; font-size: 12px; font-weight: 400; text-decoration: none; white-space: nowrap; }
.ut-home::after { content: " /"; }
.ut-home:hover { opacity: 1; text-decoration: underline; }
