/*
 * Quiet Functionalism
 * 配色・書体・角丸は tools.include.bz/timer（public/embeds/presentation-timer.html）と同じ値にそろえる。
 * 主操作はインク色。信号色（--accent）は「選択中」「撮影中」など注意を向ける状態にだけ使う。
 * 間隔は 4px 単位（--s1〜--s6）。影は使わない（境界は 1px の線で示す）。
 */
:root {
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --r-sm: 1px;
  --r: 2px;
  --control-h: 32px;
  --panel-w: 328px;

  /* 面（surface > sunk > ground）・罫・文字・信号色は timer と同値 */
  --stage: #e7e7e4;
  --surface: #ffffff;
  --surface-2: #f2f2ef;
  --line: #d5d5d1;
  --line-strong: #bcbcb7;
  --text: #17171a;
  --text-2: #5b5b56;
  --text-3: #75756f;
  --accent: #d9531e;
  --ok: #3d7a4b;
  --error: #b3261e;
  --checker-a: #dcdcd8;
  --checker-b: #f2f2ef;

  --font: "Inter", system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

html.dark {
  --stage: #0f0f11;
  --surface: #1a1a1d;
  --surface-2: #141416;
  --line: #2d2d32;
  --line-strong: #3c3c42;
  --text: #f0f0ee;
  --text-2: #a6a6a0;
  --text-3: #8a8a84;
  --accent: #ff6a33;
  --ok: #6aab78;
  --error: #ef6b62;
  --checker-a: #2d2d32;
  --checker-b: #1a1a1d;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  font: 13px/1.5 var(--font);
  color: var(--text);
  background: var(--stage);
  -webkit-font-smoothing: antialiased;
}
h1, h2, p { margin: 0; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset:disabled { opacity: 0.4; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- パネル ---------- */
.panel {
  width: var(--panel-w);
  flex: none;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
/* 見出しは timer の .device__head・.label と同じ（48px の帯／10px・字間 .12em・大文字） */
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  flex: none;
  height: 48px;
  padding: 0 var(--s4);
  border-bottom: 1px solid var(--line);
}
.panel-head .label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
}
.theme-seg span { color: var(--text-3); height: 26px; padding: 0 var(--s3); font-size: 10px; font-weight: 500; letter-spacing: 0.1em; text-transform: uppercase; }
.panel-body { flex: 1; overflow-y: auto; }
.panel-foot {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--s2);
  padding: var(--s3) var(--s4);
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.panel-foot-note { padding: var(--s3) var(--s4) var(--s4); }

.group {
  display: grid;
  gap: var(--s3);
  padding: var(--s4);
  border-bottom: 1px solid var(--line);
}
.group-head { display: flex; align-items: center; justify-content: space-between; min-height: 20px; }
.group-title {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-2);
}
.idx { font-family: var(--mono); font-weight: 400; color: var(--text-3); letter-spacing: 0; }
.stack-gap { display: grid; gap: var(--s3); }

.label { font-size: 12px; color: var(--text-2); }
.stack { display: grid; gap: var(--s1); min-width: 0; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }

/* ---------- 入力 ---------- */
input[type=url], input[type=number] {
  width: 100%;
  height: var(--control-h);
  padding: 0 var(--s2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input[type=url] { font-family: var(--mono); font-size: 12px; }
input[type=number] { font-variant-numeric: tabular-nums; text-align: right; }
input[type=url]:hover, input[type=number]:hover { border-color: var(--text-3); }
input::placeholder { color: var(--text-3); }

.unit-input { position: relative; display: block; }
.unit-input input { padding-right: 34px; }
.unit-input > span {
  position: absolute;
  right: var(--s2);
  top: 50%;
  transform: translateY(-50%);
  font: 11px var(--mono);
  color: var(--text-3);
  pointer-events: none;
}

/* スライダー：ラベル / 操作 / 値 の3列。塗りの長さで現在値の位置を示す */
.slider {
  display: grid;
  grid-template-columns: 72px 1fr 56px;
  gap: var(--s3);
  align-items: center;
  min-height: 20px;
}
.slider output {
  text-align: right;
  font: 11px var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
input[type=range] {
  --p: 50%;
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 16px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 2px;
  background: linear-gradient(to right, var(--text) var(--p), var(--line-strong) var(--p));
}
input[type=range]::-moz-range-track { height: 2px; background: var(--line-strong); }
input[type=range]::-moz-range-progress { height: 2px; background: var(--text); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -5px;
  border: 1px solid var(--text);
  border-radius: var(--r-sm);
  background: var(--surface);
}
input[type=range]::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border: 1px solid var(--text);
  border-radius: var(--r-sm);
  background: var(--surface);
}
input[type=range]:active::-webkit-slider-thumb { background: var(--accent); border-color: var(--accent); }
input[type=range]:active::-moz-range-thumb { background: var(--accent); border-color: var(--accent); }
input[type=range]:focus-visible { outline-offset: 2px; }
fieldset:disabled input[type=range] { cursor: default; }

/* 色見本 */
.swatch { display: flex; align-items: center; gap: var(--s2); cursor: pointer; }
input[type=color] {
  appearance: none;
  -webkit-appearance: none;
  width: 32px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: none;
  cursor: pointer;
}
input[type=color]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type=color]::-webkit-color-swatch { border: 0; border-radius: var(--r-sm); }
input[type=color]::-moz-color-swatch { border: 0; border-radius: var(--r-sm); }

/* スイッチ（オン・オフ）：角の立った小さなトグル */
.switch { display: inline-flex; align-items: center; gap: var(--s2); cursor: pointer; }
.switch input {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 28px;
  height: 16px;
  margin: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: var(--surface-2);
  cursor: pointer;
}
.switch input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 10px;
  height: 10px;
  border-radius: var(--r-sm);
  background: var(--text-3);
}
.switch input:checked { background: var(--text); border-color: var(--text); }
.switch input:checked::after { left: 14px; background: var(--surface); }

/* チェックボックス（デバイス選択） */
.check { display: flex; align-items: center; gap: var(--s2); min-width: 0; cursor: pointer; }
.check input {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 14px;
  height: 14px;
  margin: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  cursor: pointer;
}
.check input:checked {
  border-color: var(--text);
  background: var(--text) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M3.5 7.2l2.3 2.3 4.7-5' fill='none' stroke='white' stroke-width='1.6'/%3E%3C/svg%3E") center / 12px no-repeat;
}
html.dark .check input:checked {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M3.5 7.2l2.3 2.3 4.7-5' fill='none' stroke='%231a1a1d' stroke-width='1.6'/%3E%3C/svg%3E");
}

/* セグメント（排他選択）：選択肢をすべて見せる */
.segmented {
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  overflow: hidden;
}
.segmented label { position: relative; cursor: pointer; }
.segmented label + label { border-left: 1px solid var(--line-strong); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  padding: 0 var(--s2);
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
}
.segmented label:hover span { color: var(--text); background: var(--surface-2); }
.segmented input:checked + span { background: var(--text); color: var(--surface); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.segmented-sm span { height: 30px; padding: 0 var(--s3); font-family: var(--mono); font-size: 11px; }

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--control-h);
  padding: 0 var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
}
.btn:hover { border-color: var(--text); }
.btn-primary {
  border-color: var(--text);
  background: var(--text);
  color: var(--surface);
  font-size: 13px;
  font-weight: 600;
}
.btn-primary:hover { border-color: var(--text-2); background: var(--text-2); }
.btn-primary:disabled { cursor: progress; opacity: 0.35; }
.btn-quiet { height: 24px; padding: 0 var(--s1); border-color: transparent; background: none; color: var(--text-2); }
.btn-quiet:hover { border-color: transparent; background: none; color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.btn-sm { height: 28px; padding: 0 var(--s2); }
.btn-file { position: relative; overflow: hidden; }
.btn-file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.message { white-space: pre-line; min-height: 18px; font-size: 12px; color: var(--text-2); }
.message:empty { display: none; }
.message.error { color: var(--error); }

/* ---------- デバイス一覧 ---------- */
.dev-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
}
.dev + .dev { border-top: 1px solid var(--line); }
.dev { position: relative; }
.dev.selected::before {
  content: "";
  position: absolute;
  left: -1px;
  top: -1px;
  bottom: -1px;
  width: 2px;
  background: var(--accent);
}
.dev-head {
  display: grid;
  grid-template-columns: 1fr auto 28px;
  align-items: center;
  gap: var(--s2);
  height: 36px;
  padding: 0 var(--s1) 0 var(--s3);
}
.dev-head .check span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev.off .dev-head .check span { color: var(--text-2); }

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: 11px var(--mono);
  color: var(--text-3);
}
.status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  border: 1px solid currentColor;
}
.status[data-kind="busy"] { color: var(--accent); }
.status[data-kind="busy"]::before { background: currentColor; }
.status[data-kind="ok"] { color: var(--ok); }
.status[data-kind="ok"]::before { background: currentColor; }
.status[data-kind="error"] { color: var(--error); }
.status[data-kind="error"]::before { background: currentColor; }
.status:empty { display: none; }

.disclosure {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: var(--r);
  background: none;
  color: var(--text-3);
  cursor: pointer;
}
.disclosure:hover { color: var(--text); background: var(--surface-2); }
.disclosure svg { display: block; margin: auto; }
.disclosure[aria-expanded="true"] svg { transform: rotate(180deg); }

.dev-body {
  display: grid;
  gap: var(--s3);
  padding: var(--s3);
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}
.dev-body input[type=url], .dev-body input[type=number] { background: var(--surface); }
.dev-body .segmented { background: var(--surface); }
.dev-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s1); }
/* 個別 URL：入力欄の右端に再撮影ボタンを収める */
.url-field { position: relative; }
.url-field + .btn-file { margin-top: var(--s1); }
.url-field input { padding-right: 76px; }
.url-field .btn { position: absolute; top: 3px; right: 3px; height: 26px; padding: 0 var(--s2); }
.z-input { display: grid; grid-template-columns: 72px 72px; gap: var(--s3); align-items: center; }
.z-input input { height: 28px; }

/* ---------- ステージ ---------- */
.stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.canvas-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s6);
}
canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  outline: 1px solid var(--line-strong);
  background: repeating-conic-gradient(var(--checker-a) 0% 25%, var(--checker-b) 0% 50%) 0 0 / 16px 16px;
  cursor: grab;
}
canvas.dragging { cursor: grabbing; }

.readout {
  display: flex;
  align-items: center;
  gap: var(--s5);
  height: 32px;
  padding: 0 var(--s4);
  border-top: 1px solid var(--line);
  background: var(--surface);
  font: 11px var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
}
.readout-item:empty { display: none; }
#readout-selection { color: var(--text); }
#readout-selection b { font-weight: 400; color: var(--accent); }
.readout-hint { margin-left: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--text-3); font-family: var(--font); }

/* ---------- 狭い画面：プレビューを上、操作を下 ---------- */
@media (max-width: 760px) {
  body { flex-direction: column; height: auto; }
  .stage { order: -1; flex: none; }
  .canvas-wrap { flex: none; padding: var(--s4); }
  canvas { width: 100%; height: auto; max-height: 60vh; object-fit: contain; }
  .panel { width: 100%; height: auto; border-right: 0; border-top: 1px solid var(--line); }
  .panel-body { overflow: visible; }
  .panel-foot { position: sticky; bottom: 0; }
  .readout-hint { display: none; }
}
