/* Layout: 3Dビューア＋平面マットキャップを左のステージに、レイヤー編集を右の作業パネルに。グレー判定がしやすい単一のダーク作業空間。 */
:root {
  color-scheme: dark;
  --bg: #121317;
  --panel: #1a1b21;
  --panel-2: #22232b;
  --line: #2e3039;
  --fg: #e9e7ef;
  --muted: #8e8f9c;
  --accent: #b6a3ff;
  --accent-ink: #17132b;
  --danger: #ff8a8a;
  --stage: #0d0e11;
  --font-display: "Dela Gothic One", "Zen Kaku Gothic New", system-ui, sans-serif;
  --font-body: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --r: 10px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font-family: var(--font-body); font-size: 14px; line-height: 1.55;
}
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; justify-content: space-between;
  padding-block: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { font-family: var(--font-display); font-weight: 400; font-size: 20px; margin: 0; letter-spacing: .02em; }
.brand small { color: var(--muted); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.export { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.export label { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }

select, .btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer;
}
select:hover, .btn:hover { border-color: #474a57; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.icon { padding: 4px 8px; line-height: 1; font-size: 13px; }

.studio {
  display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px;
  padding-block: 20px 32px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  max-width: 1400px; margin: 0 auto;
}
@media (max-width: 900px) { .studio { grid-template-columns: minmax(0, 1fr); } }

.stage { display: grid; gap: 16px; align-content: start; min-width: 0; }
.viewer {
  position: relative; background: var(--stage); border: 1px solid var(--line); border-radius: var(--r);
  aspect-ratio: 4 / 3; max-width: 100%; overflow: hidden; touch-action: none; cursor: grab;
}
.viewer:active { cursor: grabbing; }
.viewer canvas { display: block; width: 100%; height: 100%; }
.viewer-tools {
  position: absolute; left: 10px; right: 10px; bottom: 10px; display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center;
  pointer-events: none;
}
.viewer-tools > * { pointer-events: auto; }
.seg { display: inline-flex; background: rgba(20,21,26,.82); border: 1px solid var(--line); border-radius: 8px; padding: 2px; backdrop-filter: blur(6px); }
.seg button { background: none; border: 0; padding: 5px 9px; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 12px; }
.seg button[aria-pressed="true"] { background: var(--panel-2); color: var(--fg); }
.mix-tools { display: inline-flex; gap: 6px; align-items: center; background: rgba(20,21,26,.82); border: 1px solid var(--line); border-radius: 8px; padding: 3px 6px; font-size: 12px; color: var(--muted); }
.mix-tools select { padding: 3px 6px; font-size: 12px; }
.viewer-badge { position: absolute; top: 10px; left: 12px; font-size: 11px; color: var(--muted); letter-spacing: .06em; }

.flat { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 520px) { .flat { grid-template-columns: minmax(0, 1fr); } }
.mc-wrap {
  position: relative; width: 100%; max-width: 100%; aspect-ratio: 1; border-radius: 8px; overflow: hidden;
  background-color: #2a2b31;
  background-image: linear-gradient(45deg, #34353c 25%, transparent 25%), linear-gradient(-45deg, #34353c 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #34353c 75%), linear-gradient(-45deg, transparent 75%, #34353c 75%);
  background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  touch-action: none; cursor: crosshair; border: 1px solid var(--line);
}
.mc-wrap canvas { display: block; width: 100%; height: 100%; }
.handle {
  position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 0 0 1.5px rgba(0,0,0,.6); pointer-events: none;
}
.handle::after { content: ""; position: absolute; inset: 5px; border-radius: 50%; background: var(--accent); }
.flat-info { min-width: 0; color: var(--muted); font-size: 13px; display: grid; gap: 8px; }
.flat-info strong { color: var(--fg); font-weight: 700; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--font-mono); color: var(--fg); font-variant-numeric: tabular-nums; }

.panel { display: grid; gap: 14px; align-content: start; min-width: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; min-width: 0; }
.card h2 { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card h2 select { text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 12px; color: var(--fg); padding: 4px 8px; }

.presets { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.preset { background: none; border: 1px solid transparent; border-radius: 8px; padding: 4px; cursor: pointer; display: grid; gap: 4px; justify-items: center; color: var(--muted); font-size: 11px; }
.preset:hover { border-color: var(--line); color: var(--fg); }
.preset canvas { width: 100%; max-width: 64px; aspect-ratio: 1; border-radius: 50%; }

.layers { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.layer {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: center;
  padding: 6px 8px; border-radius: 8px; border: 1px solid transparent; cursor: pointer;
}
.layer:hover { background: var(--panel-2); }
.layer[aria-selected="true"] { background: var(--panel-2); border-color: var(--accent); }
.layer .eye { background: none; border: 0; cursor: pointer; width: 22px; height: 22px; border-radius: 6px; color: var(--fg); font-size: 13px; }
.layer.off .name { opacity: .4; text-decoration: line-through; }
.layer .name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layer .name small { color: var(--muted); font-size: 11px; margin-left: 6px; }
.layer .ops { display: flex; gap: 2px; }
.layer .ops button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 5px; border-radius: 5px; font-size: 12px; }
.layer .ops button:hover { color: var(--fg); background: var(--line); }
.layer .ops button.del:hover { color: var(--danger); }

.params { display: grid; gap: 10px; }
.prm { display: grid; grid-template-columns: 92px minmax(0, 1fr) 46px; gap: 8px; align-items: center; font-size: 12px; }
.prm label { color: var(--muted); }
.prm output { font-family: var(--font-mono); font-size: 11px; text-align: right; font-variant-numeric: tabular-nums; }
.prm input[type="range"] { width: 100%; accent-color: var(--accent); }
.prm input[type="color"] { width: 100%; height: 26px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); padding: 2px; cursor: pointer; }
.prm select { width: 100%; padding: 4px 6px; font-size: 12px; }
.prm input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
.params .sep { border-top: 1px solid var(--line); margin: 2px 0; }
.empty { color: var(--muted); font-size: 12px; }

.howto { font-size: 13px; color: var(--muted); }
.howto summary { cursor: pointer; color: var(--fg); font-weight: 700; }
.howto h3 { font-size: 12px; color: var(--fg); margin: 12px 0 4px; }
.howto ul { margin: 0; padding-left: 18px; display: grid; gap: 3px; }
.howto code { font-family: var(--font-mono); font-size: 11px; background: var(--panel-2); padding: 1px 4px; border-radius: 4px; color: var(--fg); }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--fg); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: 13px; font-weight: 700;
  opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 20;
}
.toast.show { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
.mix-tools .base-color { width: 28px; height: 22px; border: 0; background: none; padding: 0; cursor: pointer; }
.flat-info .lead { margin: 0; }
.prm output.hex { font-size: 10px; }
