/* #13 カラーピッカー（改）— Design System「Sandbox No.12」のトークンと部品で組む。
   テーマは <html data-theme> が優先、無ければ OS 設定。 */

/* ============ トークン ============ */
:root {
  --bg: #f7f7f8; --surface: #ffffff; --surface-2: #f1f2f4; --border: #e3e5e8; --border-strong: #858a97;
  --text: #17181c; --muted: #5c6170; --faint: #6b7080;
  --accent: #4f46e5; --accent-fg: #ffffff; --accent-weak: #eef0fe; --accent-weak-fg: #4338ca;
  --err: #b91c1c; --err-bg: #fef2f2; --warn: #b45309; --warn-bg: #fffbeb; --info: #2563eb; --info-bg: #eff6ff;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --pill-shadow: 0 1px 2px rgba(16,24,40,.12);
  --edge: rgba(0,0,0,.08);
  color-scheme: light;

  --font-sans: Inter, "Noto Sans JP", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --radius-xs: 3px; --radius-sm: 4px; --radius-tip: 6px; --radius-control: 7px; --radius-seg: 8px; --radius-switch: 9px; --radius-pane: 10px;
  --control-height: 32px; --icon-size: 16px; --content-width: 1120px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0e11; --surface: #15171c; --surface-2: #1c1f26; --border: #2a2e37; --border-strong: #666d7b;
    --text: #e7e9ee; --muted: #a1a7b5; --faint: #858b9b;
    --accent: #818cf8; --accent-fg: #0d0e11; --accent-weak: #22244a; --accent-weak-fg: #c7d2fe;
    --err: #f87171; --err-bg: #2a1416; --warn: #fbbf24; --warn-bg: #2a2110; --info: #93c5fd; --info-bg: #142033;
    --shadow: none; --pill-shadow: 0 1px 2px rgba(0,0,0,.5); --edge: rgba(255,255,255,.12);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0e11; --surface: #15171c; --surface-2: #1c1f26; --border: #2a2e37; --border-strong: #666d7b;
  --text: #e7e9ee; --muted: #a1a7b5; --faint: #858b9b;
  --accent: #818cf8; --accent-fg: #0d0e11; --accent-weak: #22244a; --accent-weak-fg: #c7d2fe;
  --err: #f87171; --err-bg: #2a1416; --warn: #fbbf24; --warn-bg: #2a2110; --info: #93c5fd; --info-bg: #142033;
  --shadow: none; --pill-shadow: 0 1px 2px rgba(0,0,0,.5); --edge: rgba(255,255,255,.12);
  color-scheme: dark;
}

/* ============ 基本 ============ */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font-sans); }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
svg { width: var(--icon-size); height: var(--icon-size); stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
button, select, input, textarea { font: inherit; color: inherit; margin: 0; }
::selection { background: var(--accent-weak); color: var(--text); }

/* ============ 部品（No.12 components/bundle.css から、このページで使う分） ============ */

/* ---- header ---- */
header.app { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface); }
.logo { display: flex; align-items: center; gap: 10px; }
.logo-mark { width: 28px; height: 28px; border-radius: var(--radius-control); background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; font: 600 13px var(--font-mono); }
.logo-name { font-size: 15px; font-weight: 600; line-height: 1.5; }
.spacer { flex: 1; }

/* ---- pane ---- */
.pane { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-pane); box-shadow: var(--shadow); }
.pane-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-height: 53px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.pane-title { font-size: 12px; font-weight: 600; line-height: 1.5; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; }
.pane-body { padding: 14px; }

/* ---- button ---- */
.btn { display: inline-flex; align-items: center; gap: 6px; height: var(--control-height); padding: 0 12px; border-radius: var(--radius-control); border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 500; font-size: 13px; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.icon { width: var(--control-height); padding: 0; justify-content: center; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:disabled:hover { background: var(--surface); filter: none; }
.btn.primary:disabled:hover { background: var(--accent); }

/* ---- text input ---- */
.in { height: var(--control-height); width: 200px; padding: 0 10px; border-radius: var(--radius-control); border: 1px solid var(--border-strong); background: var(--surface); font-size: 14px; }
.in::placeholder { color: var(--faint); }
.in:hover { border-color: var(--muted); }
.in.is-invalid { border-color: var(--err); background-color: var(--err-bg); }
.in.is-invalid:focus-visible { outline-color: var(--err); }

/* ---- focus ---- */
.btn:focus-visible, .in:focus-visible, input[type=range]:focus-visible,
.switch input:focus-visible + span, .seg input:focus-visible + span, .tip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- range ---- */
input[type=range] { width: 160px; accent-color: var(--accent); margin: 0; cursor: pointer; }

/* ---- switch ---- */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--muted); user-select: none; position: relative; align-self: flex-start; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { width: 30px; height: 18px; border-radius: var(--radius-switch); background: var(--border-strong); position: relative; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(12px); }
.switch:has(input:checked) { color: var(--text); }
.switch:has(input:disabled) { opacity: .45; cursor: not-allowed; }

/* ---- segmented ---- */
.seg { display: inline-flex; padding: 2px; gap: 2px; border-radius: var(--radius-seg); background: var(--surface-2); border: 1px solid var(--border); }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: inline-flex; align-items: center; height: 26px; padding: 0 12px; border-radius: var(--radius-tip); font-size: 13px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.seg label:hover span { color: var(--text); }
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--pill-shadow); }

/* ---- tooltip（反転配色。hover は 0.4 秒待ち、キーボードの focus では即座） ---- */
.tip { position: relative; }
.tip::after { content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translate(-50%, 4px); padding: 4px 8px; border-radius: var(--radius-tip); background: var(--text); color: var(--bg); font: 500 12px/1.4 var(--font-sans); text-transform: none; letter-spacing: 0; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .12s, transform .12s; z-index: 5; }
.tip[data-pos="bottom"]::after { bottom: auto; top: calc(100% + 8px); transform: translate(-50%, -4px); }
.tip:hover::after, .tip:focus-visible::after { opacity: 1; transform: translate(-50%, 0); transition-delay: .4s; }
.tip:focus-visible::after { transition-delay: 0s; }
.tip[data-align="end"]::after { left: auto; right: 0; transform: translate(0, -4px); }
.tip[data-align="start"]::after { left: 0; transform: translate(0, 4px); }
.tip[data-align="end"]:hover::after, .tip[data-align="end"]:focus-visible::after,
.tip[data-align="start"]:hover::after, .tip[data-align="start"]:focus-visible::after { transform: none; }
.tip.wrap::after { white-space: normal; width: 240px; }

/* ---- message ---- */
.msg { display: flex; align-items: flex-start; gap: 8px; min-height: var(--control-height); padding: 7px 12px; border-radius: var(--radius-control); font-size: 12px; line-height: 1.5; }
.msg svg { margin-top: 1px; }
.msg.err { color: var(--err); background: var(--err-bg); }
.msg.warn { color: var(--warn); background: var(--warn-bg); }

/* ============ レイアウト ============ */
.cp-noscript { margin: 24px 20px 0; }
.cp-main { max-width: var(--content-width); margin: 0 auto; padding: 24px 20px 32px; display: flex; flex-wrap: wrap; align-items: flex-start; gap: 20px; }
.cp-col-image { flex: 999 1 520px; min-width: 0; }
.cp-col-color { flex: 1 1 380px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.cp-stack { display: flex; flex-direction: column; gap: 14px; }
.cp-row { display: flex; align-items: center; gap: 8px; }
@media (max-width: 860px) {
  header.app { padding-left: 16px; padding-right: 16px; }
  .cp-main { padding: 16px; }
}

/* ペイン見出しの中の部品は大文字化しない */
.cp-meta { font: 400 12px var(--font-mono); color: var(--muted); }
.cp-meta.is-err { color: var(--err); font-family: var(--font-sans); }
.cp-label { font-size: 12px; color: var(--muted); }
/* 画像ペイン見出しの右側。折り返すときはまとめて次の行へ */
.cp-tools { display: flex; align-items: center; gap: 8px; margin-left: auto; }

/* (?) の補足。タップでも出るよう :focus でも開く */
.cp-help { display: inline-grid; place-items: center; width: 24px; height: 24px; margin: -4px 0; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--muted); cursor: help; }
.cp-help:hover { color: var(--text); }
.cp-help:focus::after { opacity: 1; transform: none; transition-delay: 0s; }

/* ============ 画像 ============ */
/* 透明部分が分かるよう市松の地 */
.cp-frame { position: relative; display: grid; place-items: center; min-height: clamp(240px, 46vw, 400px); border: 1px solid var(--border); border-radius: var(--radius-control); background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface) 0 50%) 0 0 / 16px 16px; overflow: hidden; }
.cp-frame.is-empty { border-style: dashed; border-color: var(--border-strong); background: var(--surface); }
.cp-frame.is-over { outline: 2px solid var(--accent); outline-offset: 2px; }
.cp-canvas { display: block; max-width: 100%; max-height: 560px; cursor: crosshair; touch-action: none; }
.cp-drop { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--muted); cursor: pointer; transition: background .12s; }
.cp-drop:hover { background: var(--surface-2); }
.cp-drop:focus-within { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: inherit; }
.cp-drop svg { width: 24px; height: 24px; margin-bottom: 4px; }
.cp-drop-title { font-size: 14px; font-weight: 500; color: var(--text); }
.cp-drop-sub { font-size: 12px; }
.cp-file { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.cp-loupe { position: absolute; top: 10px; left: 10px; display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border-radius: var(--radius-control); background: var(--text); color: var(--bg); font: 500 12px var(--font-mono); pointer-events: none; }
.cp-loupe-sw { width: 24px; height: 24px; border-radius: var(--radius-sm); box-shadow: inset 0 0 0 1px var(--edge); }
.cp-frame-msg { position: absolute; left: 10px; right: 10px; bottom: 10px; }

/* 頻出色の帯。幅が画像の中の割合 */
.cp-sub { margin-bottom: 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
.cp-freq { display: flex; gap: 2px; height: 44px; }
.cp-freq.is-empty { border-radius: var(--radius-control); background: var(--surface-2); }
.cp-freq-seg { min-width: 14px; height: 100%; padding: 0; border: 0; border-radius: 0; cursor: pointer; box-shadow: inset 0 0 0 1px var(--edge); }
.cp-freq-seg:first-child { border-radius: var(--radius-control) 0 0 var(--radius-control); }
.cp-freq-seg:last-child { border-radius: 0 var(--radius-control) var(--radius-control) 0; }
.cp-freq-seg:only-child { border-radius: var(--radius-control); }
.cp-freq-seg:hover { outline: 2px solid var(--text); outline-offset: 1px; z-index: 1; }

/* ============ 現在色 ============ */
.cp-swatch { display: block; width: 100%; height: 148px; padding: 0; border: 0; border-radius: var(--radius-control); cursor: copy; box-shadow: inset 0 0 0 1px var(--edge); }
.in.cp-hex { flex: 1; width: auto; min-width: 0; font: 500 16px var(--font-mono); letter-spacing: .02em; }
.cp-values { display: flex; flex-wrap: wrap; gap: 2px 16px; font: 12px var(--font-mono); color: var(--muted); }
.cp-hsv { display: grid; gap: 12px; }
.cp-hsv-row { display: grid; grid-template-columns: 14px minmax(0, 1fr) 40px; align-items: center; gap: 10px; }
.cp-hsv-row > span { font: 500 12px var(--font-mono); color: var(--muted); }
output { font: 12px var(--font-mono); text-align: right; font-variant-numeric: tabular-nums; }
/* H / S / V の溝は今の色から作るグラデーション（JS が background を入れる） */
input.cp-track { -webkit-appearance: none; appearance: none; width: 100%; height: 14px; border-radius: 7px; box-shadow: inset 0 0 0 1px var(--edge); }
input.cp-track::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); border: 2px solid var(--text); box-shadow: 0 0 0 1px var(--surface); }
input.cp-track::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 2px solid var(--text); }
input.cp-track::-moz-range-track { background: transparent; }

/* ============ パレット ============ */
.cp-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.cp-list:empty { display: none; }
.cp-prow { display: grid; grid-template-columns: 32px 66px minmax(0, 1fr) 32px; align-items: center; gap: 8px; }
.cp-chip-sw { flex-shrink: 0; width: 32px; height: 32px; padding: 0; border: 0; border-radius: var(--radius-control); cursor: pointer; box-shadow: inset 0 0 0 1px var(--edge); }
.cp-prow-hex { font: 13px var(--font-mono); }
.in.cp-name { width: 100%; min-width: 0; font-size: 13px; }
.cp-empty { font-size: 13px; color: var(--muted); }

/* ============ 吹き出し（ボタン・入力欄に付く結果とエラー） ============ */
.cp-anchor { position: relative; display: inline-flex; }
.cp-anchor.is-block { display: flex; flex: 1; min-width: 0; }
.cp-pop { position: absolute; top: calc(100% + 8px); right: 0; z-index: 6; display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: var(--radius-tip); background: var(--text); color: var(--bg); font: 500 12px/1.4 var(--font-sans); white-space: nowrap; text-transform: none; letter-spacing: 0; }
.cp-pop.is-err { background: var(--err); color: var(--bg); }
.cp-pop.at-start { left: 0; right: auto; white-space: normal; width: max-content; max-width: 260px; }
.cp-pop svg { width: 14px; height: 14px; }

/* ============ 合成（折り畳み） ============ */
.cp-fold > summary { list-style: none; cursor: pointer; border-bottom: 0; border-radius: var(--radius-pane); }
.cp-fold[open] > summary { border-bottom: 1px solid var(--border); border-radius: var(--radius-pane) var(--radius-pane) 0 0; }
.cp-fold > summary::-webkit-details-marker { display: none; }
.cp-fold > summary:hover { background: var(--surface-2); }
.cp-fold > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cp-chev { color: var(--muted); transform: rotate(-90deg); transition: transform .15s; }
.cp-fold[open] .cp-chev { transform: none; }
.cp-mini { width: 14px; height: 14px; border-radius: var(--radius-sm); box-shadow: inset 0 0 0 1px var(--edge); }
.cp-state { padding: 2px 8px; border-radius: var(--radius-tip); background: var(--accent-weak); color: var(--accent-weak-fg); font-size: 12px; font-weight: 500; }
.cp-field { display: grid; grid-template-columns: 72px minmax(0, 1fr); align-items: center; gap: 12px; min-height: 32px; }
.cp-flabel { display: inline-flex; align-items: center; gap: 2px; font-size: 13px; color: var(--muted); }
.cp-op { display: grid; grid-template-columns: minmax(0, 1fr) 40px; align-items: center; gap: 10px; }
.cp-op input[type=range] { width: 100%; }
.in.cp-layer-hex { width: 92px; font: 13px var(--font-mono); }

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