:root {
  --bg: #0b0d0c;
  --bg2: #10130f;
  --panel: #12150f;
  --line: #2a2f24;
  --line-hi: #3d4433;
  --ink: #e8e6df;
  --ink-dim: #8b917e;
  --acid: #c8ff00;
  --magenta: #ff3ea5;
  --cyan: #35e0ff;
  --font-dot: "DotGothic16", monospace;
  --font-mono: "IBM Plex Mono", monospace;
  --font-body: "Zen Kaku Gothic New", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background:
    radial-gradient(1200px 600px at 70% -10%, #1a2012 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #1b1020 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.6;
  overflow-x: hidden;
}

.file-mode-warning {
  position: relative;
  z-index: 1000;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px 16px;
  padding: 10px 22px;
  border-bottom: 1px solid #785f00;
  background: #2b2408;
  color: #fff4b8;
  font-family: var(--font-mono);
}
.file-mode-warning[hidden] { display: none; }
.file-mode-warning strong { color: var(--acid); }
.file-mode-warning code {
  padding: 3px 7px;
  border: 1px solid #64551a;
  background: #171304;
  color: #fff;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .file-mode-warning { grid-template-columns: 1fr; }
  .file-mode-warning code { width: max-content; max-width: 100%; overflow-x: auto; }
}

/* 画面全体にうっすらCRT走査線 */
.crt-overlay {
  position: fixed; inset: 0; z-index: 999; pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0, transparent 2px,
    rgba(0, 0, 0, 0.13) 3px, rgba(0, 0, 0, 0.13) 4px
  );
  mix-blend-mode: multiply;
}

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: baseline; gap: 14px;
  padding: 14px 22px 12px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(to bottom, #151910, #0e100c);
  position: sticky; top: 0; z-index: 20;
}

.logo {
  font-family: var(--font-dot);
  font-size: 26px;
  font-weight: 400;
  letter-spacing: 2px;
  color: var(--acid);
  white-space: nowrap;
  position: relative;
  text-shadow: 0 0 12px rgba(200, 255, 0, 0.45);
  user-select: none;
}
.logo::before, .logo::after {
  content: attr(data-text);
  position: absolute; inset: 0;
  overflow: hidden;
}
.logo::before {
  color: var(--magenta);
  animation: glitch-a 3.1s infinite steps(1);
  clip-path: inset(0 0 55% 0);
}
.logo::after {
  color: var(--cyan);
  animation: glitch-b 2.7s infinite steps(1);
  clip-path: inset(60% 0 0 0);
}
@keyframes glitch-a {
  0%, 91%, 100% { transform: none; opacity: 0; }
  92% { transform: translate(-3px, 1px); opacity: 0.9; }
  94% { transform: translate(2px, -1px); opacity: 0.9; }
  96% { transform: none; opacity: 0; }
}
@keyframes glitch-b {
  0%, 87%, 100% { transform: none; opacity: 0; }
  88% { transform: translate(3px, 0); opacity: 0.9; }
  90% { transform: translate(-2px, 1px); opacity: 0.9; }
  93% { transform: none; opacity: 0; }
}

.logo-sub {
  font-family: var(--font-dot);
  color: var(--ink-dim);
  font-size: 13px;
  letter-spacing: 1px;
}

.topbar-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* ---- buttons ---- */
.btn {
  font-family: var(--font-dot);
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--ink);
  background: #1a1e15;
  border: 1px solid var(--line-hi);
  padding: 7px 14px;
  cursor: pointer;
  white-space: nowrap;
  clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 8px 100%, 0 calc(100% - 8px));
  transition: background 0.12s, color 0.12s, box-shadow 0.12s;
}
.btn:hover { background: #242a1b; box-shadow: 0 0 10px rgba(200, 255, 0, 0.15); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--acid); color: #0b0d0c; border-color: var(--acid); font-weight: 600; }
.btn-primary:hover { background: #d9ff3d; box-shadow: 0 0 16px rgba(200, 255, 0, 0.4); }
.btn-primary:disabled { opacity: 0.5; cursor: wait; }
.btn-alt { color: var(--magenta); border-color: #4a2038; }
.btn-alt:hover { background: #251320; box-shadow: 0 0 10px rgba(255, 62, 165, 0.25); }

/* ---- layout ---- */
.layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  min-height: calc(100vh - 60px);
}

/* ---- stage ---- */
.stage {
  display: flex; flex-direction: column;
  padding: 26px;
  gap: 10px;
  background-image:
    linear-gradient(rgba(200, 255, 0, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(200, 255, 0, 0.025) 1px, transparent 1px);
  background-size: 28px 28px;
}
.stage-inner {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  min-height: 320px;
}
#view {
  max-width: 100%;
  max-height: calc(100vh - 190px);
  border: 1px solid var(--line-hi);
  box-shadow:
    0 0 0 1px #000,
    0 0 40px rgba(200, 255, 0, 0.07),
    0 24px 60px rgba(0, 0, 0, 0.55);
  background: #000;
}
.stage.dragging .stage-inner::after {
  content: "";
  position: absolute; inset: -10px;
  border: 2px dashed var(--acid);
  background: rgba(200, 255, 0, 0.06);
  pointer-events: none;
}
.drop-hint {
  position: absolute;
  bottom: -4px; left: 50%;
  transform: translateX(-50%);
  text-align: center;
  color: var(--ink-dim);
  pointer-events: none;
  white-space: nowrap;
}
.drop-hint-en { font-family: var(--font-dot); letter-spacing: 3px; font-size: 11px; color: #5a6150; }
.drop-hint p:last-child { font-size: 11px; }

.stage-status {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-dim);
}
.stage-status > span, .stage-status > label { white-space: nowrap; }
.anim-toggle { display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.anim-toggle input { accent-color: var(--acid); }

.ratio-label { margin-left: auto; }
.ratio-seg { display: inline-flex; gap: 3px; }
.ratio-seg button {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 3px 8px;
  background: #10130b;
  color: var(--ink-dim);
  border: 1px solid var(--line);
  cursor: pointer;
}
.ratio-seg button.sel { color: var(--acid); border-color: var(--acid); background: #1c2210; }
.share-btn {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 3px 10px;
  white-space: nowrap;
  background: #10130b;
  color: var(--ink);
  border: 1px solid var(--line-hi);
  cursor: pointer;
}
.share-btn:hover { color: var(--acid); border-color: var(--acid); }

#crop-guide {
  position: absolute;
  border: 1.5px dashed var(--magenta);
  pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(5, 6, 4, 0.45);
}

/* ---- panel ---- */
.panel {
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  max-height: calc(100vh - 60px);
  position: sticky; top: 60px;
}
.panel-section { padding: 16px 16px 14px; border-bottom: 1px solid var(--line); }
.section-title {
  font-family: var(--font-dot);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 2px;
  color: var(--ink);
  margin-bottom: 10px;
}
.section-title .jp { color: var(--ink-dim); font-size: 11px; letter-spacing: 0; }

/* ---- AI box ---- */
.ai-box { background: linear-gradient(to bottom, #171a10, var(--panel)); }
.ai-row { display: flex; gap: 6px; }
.ai-row .btn { white-space: nowrap; }
#ai-prompt {
  flex: 1;
  background: #0c0e09;
  border: 1px solid var(--line-hi);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 12px;
  padding: 7px 10px;
  outline: none;
}
#ai-prompt:focus { border-color: var(--acid); box-shadow: 0 0 8px rgba(200, 255, 0, 0.2); }
.ai-note { margin-top: 7px; font-size: 10.5px; color: var(--ink-dim); }
.ai-note.error { color: var(--magenta); }

/* ---- presets ---- */
.preset-row { display: flex; flex-wrap: wrap; gap: 6px; }
.preset-chip {
  font-family: var(--font-dot);
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--ink-dim);
  background: #171b12;
  border: 1px solid var(--line);
  padding: 5px 10px;
  cursor: pointer;
  transition: all 0.12s;
}
.preset-chip:hover { color: var(--acid); border-color: var(--acid); box-shadow: 0 0 8px rgba(200, 255, 0, 0.2); }

/* ---- text tool ---- */
#text-input {
  width: 100%;
  background: #0c0e09;
  border: 1px solid var(--line-hi);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 12px;
  padding: 7px 10px;
  outline: none;
  margin-bottom: 4px;
}
#text-input:focus { border-color: var(--acid); box-shadow: 0 0 8px rgba(200, 255, 0, 0.2); }
.panel-section .seg { margin-top: 6px; }
.text-hint { margin-top: 7px; font-size: 10.5px; color: #5a6150; }
.stage-tabs { display: flex; gap: 6px; }
.stage-tabs button {
  font-family: var(--font-dot);
  font-size: 12px;
  letter-spacing: 1px;
  padding: 5px 14px;
  background: #10130b;
  color: var(--ink-dim);
  border: 1px solid var(--line);
  border-bottom: none;
  cursor: pointer;
}
.stage-tabs button.sel {
  color: var(--acid);
  border-color: var(--acid);
  background: #1a2010;
  box-shadow: 0 0 10px rgba(200, 255, 0, 0.15);
}

.bpm-row { align-items: stretch; }
#bpm-input {
  width: 64px;
  background: #0c0e09;
  border: 1px solid var(--line-hi);
  color: var(--acid);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 4px 8px;
  outline: none;
}
.bpm-beats { flex: 1; margin-top: 0 !important; }

.transition-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  margin-top: 8px;
}
.transition-grid button {
  min-width: 0;
  padding: 7px 4px;
  border: 1px solid var(--line-hi);
  background: #0c0e09;
  color: var(--text-dim);
  font: 600 10px/1.2 var(--font-mono);
  cursor: pointer;
  transition: border-color .12s, color .12s, background .12s, box-shadow .12s;
}
.transition-grid button:hover {
  border-color: var(--acid);
  color: var(--acid);
}
.transition-grid button.sel {
  border-color: var(--acid);
  background: rgba(200, 255, 0, .1);
  color: var(--acid);
  box-shadow: inset 0 -2px 0 var(--acid), 0 0 8px rgba(200, 255, 0, .12);
}
.transition-hint { margin-top: 6px; }

.quick-flow {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr auto;
  align-items: center;
  gap: 7px;
  margin: 2px 0 12px;
  padding: 9px 10px;
  border: 1px solid #39412a;
  background: repeating-linear-gradient(90deg, #10130c 0 13px, #13170e 13px 14px);
  color: #c6cbb9;
  font: 600 10px/1 var(--font-mono);
  letter-spacing: .04em;
}
.quick-flow span { white-space: nowrap; }
.quick-flow b {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-right: 3px;
  border: 1px solid var(--acid);
  color: var(--acid);
  font-size: 10px;
}
.quick-flow i { height: 1px; background: linear-gradient(90deg, var(--acid), #39412a); }

.slide-strip { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.slide-item { position: relative; width: 96px; cursor: grab; }
.slide-item.selected img { border-color: var(--acid); box-shadow: 0 0 0 1px var(--acid); }
.slide-item img {
  width: 96px; height: 64px; object-fit: cover; display: block;
  border: 1px solid var(--line-hi); background: #000;
}
.slide-item .work-del {
  position: absolute; top: 1px; right: 1px;
  background: rgba(5,6,4,0.75);
}
.slide-num {
  position: absolute; bottom: 2px; left: 4px;
  font-family: var(--font-mono); font-size: 10px; color: var(--acid);
  text-shadow: 0 0 4px #000;
}
.slide-kind {
  position: absolute; right: 3px; bottom: 3px;
  padding: 2px 3px;
  background: rgba(5,6,4,.82);
  color: #fff;
  font: 8px/1 var(--font-mono);
}
.clip-trim {
  margin: 8px 0;
  padding: 9px;
  border: 1px dashed #4d5937;
  background: #0a0c08;
}
.clip-trim-head, .clip-trim-fields { display: flex; justify-content: space-between; gap: 8px; }
.clip-trim-head { margin-bottom: 7px; color: var(--acid); font: 10px/1.3 var(--font-mono); }
.clip-trim-fields label { flex: 1; color: var(--text-dim); font: 10px/1.3 var(--font-mono); }
.clip-trim-fields input { width: 100%; margin-top: 4px; }
.project-row { margin-top: 9px; }
.project-row .btn { flex: 1; }
.trans-export { width: 100%; margin-top: 10px; }
.trans-export:disabled { opacity: 0.45; cursor: not-allowed; }
#view.text-drag { cursor: move; }

/* ---- rack modules ---- */
.module {
  border: 1px solid var(--line);
  background: linear-gradient(to bottom, #161a11, #101308);
  margin-bottom: 8px;
  clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 0 100%);
}
.module-head {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
}
.led {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #2c3123;
  border: 1px solid #000;
  flex-shrink: 0;
  transition: all 0.15s;
}
.module.on .led {
  background: var(--acid);
  box-shadow: 0 0 8px var(--acid), 0 0 2px #fff inset;
}
.module-name {
  font-family: var(--font-dot);
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--ink-dim);
}
.module.on .module-name { color: var(--ink); }
.module-name .jp { font-size: 11px; color: var(--ink-dim); margin-left: 6px; }
.module-body {
  display: none;
  padding: 2px 12px 12px 30px;
}
.module.on .module-body { display: block; }

/* ---- controls ---- */
.ctl { margin-top: 8px; }
.ctl-label {
  display: flex; justify-content: space-between;
  font-size: 11px;
  color: var(--ink-dim);
  margin-bottom: 3px;
}
.ctl-label .val { font-family: var(--font-mono); color: var(--acid); }
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: #2b301f;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  margin-top: -4.5px;
  background: var(--acid);
  box-shadow: 0 0 6px rgba(200, 255, 0, 0.5);
  transform: rotate(45deg);
}
input[type="range"]::-moz-range-track { height: 3px; background: #2b301f; }
input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px; border: none; border-radius: 0;
  background: var(--acid);
  transform: rotate(45deg);
}
.seg { display: flex; gap: 4px; margin-top: 4px; }
.seg button {
  flex: 1;
  font-family: var(--font-dot);
  font-size: 11px;
  padding: 4px 2px;
  background: #10130b;
  color: var(--ink-dim);
  border: 1px solid var(--line);
  cursor: pointer;
}
.seg button.sel {
  background: #232a12;
  color: var(--acid);
  border-color: var(--acid);
}

/* 書体の選択肢は、その書体自身で描いて見分けられるようにする。
   8つあって1行に収まらないので折り返す（app.js の TEXT_FONTS と同じ並び） */
.seg-font { flex-wrap: wrap; }
.seg-font button { flex: 1 1 22%; font-size: 12px; padding: 5px 2px; }
.seg-font button[data-font="0"] { font-family: "DotGothic16", monospace; }
.seg-font button[data-font="1"] { font-family: "Zen Kaku Gothic New", sans-serif; font-weight: 500; }
.seg-font button[data-font="2"] { font-family: "IBM Plex Mono", monospace; font-weight: 600; }
.seg-font button[data-font="3"] { font-family: "Zen Kaku Gothic New", sans-serif; font-weight: 900; }
.seg-font button[data-font="4"] { font-family: "Shippori Mincho", serif; font-weight: 800; }
.seg-font button[data-font="5"] { font-family: "Zen Maru Gothic", sans-serif; font-weight: 900; }
.seg-font button[data-font="6"] { font-family: "RocknRoll One", sans-serif; }
.seg-font button[data-font="7"] { font-family: "Reggae One", cursive; }
.dice {
  margin-top: 8px;
  font-family: var(--font-dot);
  font-size: 11px;
  background: none;
  border: 1px dashed var(--line-hi);
  color: var(--ink-dim);
  padding: 4px 10px;
  cursor: pointer;
}
.dice:hover { color: var(--acid); border-color: var(--acid); }

.panel-footer {
  padding: 14px 16px 20px;
  font-size: 10.5px;
  color: #5a6150;
}
.about-link {
  display: inline-block;
  margin-top: 8px;
  color: var(--ink-dim);
  font-family: var(--font-dot);
  font-size: 11.5px;
  letter-spacing: 1px;
  text-decoration: none;
  border-bottom: 1px solid var(--line-hi);
}
.about-link:hover { color: var(--acid); border-color: var(--acid); }

/* ---- gallery ---- */
.gallery-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5, 6, 4, 0.88);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 4vh 4vw;
}
.gallery-overlay[hidden] { display: none; }
.gallery-panel {
  width: min(1100px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line-hi);
  box-shadow: 0 0 60px rgba(200, 255, 0, 0.08), 0 30px 80px rgba(0, 0, 0, 0.7);
  padding: 18px 20px 22px;
  clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 0 100%);
}
.gallery-head { display: flex; align-items: center; gap: 10px; }
.gallery-head .section-title { flex: 1; margin-bottom: 0; }
#gallery-key {
  width: 170px;
  background: #0c0e09;
  border: 1px solid var(--line-hi);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 6px 10px;
  outline: none;
}
#gallery-key:focus { border-color: var(--acid); }
.gallery-note { margin: 8px 0 14px; font-size: 11px; color: var(--ink-dim); }
.gallery-note.error { color: var(--magenta); }
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}
.work {
  border: 1px solid var(--line);
  background: #0d100a;
  cursor: pointer;
  position: relative;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.work:hover { border-color: var(--acid); box-shadow: 0 0 12px rgba(200, 255, 0, 0.2); }
.work img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; background: #000; }
.work-meta {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-dim);
}
.work-del {
  background: none; border: none;
  color: var(--ink-dim); font-size: 13px;
  cursor: pointer; padding: 0 2px;
}
.work-del:hover { color: var(--magenta); }
.work-share {
  background: none; border: none;
  color: var(--ink-dim); font-size: 12px;
  cursor: pointer; padding: 0 2px; opacity: 0.55;
}
.work-share:hover { opacity: 1; }
.work-share.on { opacity: 1; filter: drop-shadow(0 0 5px var(--acid)); }

.gallery-grid[hidden], #graph-wrap[hidden] { display: none !important; }

/* ---- knowledge graph ---- */
.graph-controls {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 8px;
  min-height: 30px;
}
.graph-hint { margin-left: auto; font-size: 10.5px; color: #5a6150; }
.graph-actions { display: flex; gap: 6px; }
.graph-actions .btn { font-size: 11px; padding: 4px 10px; }
#graph-canvas {
  width: 100%;
  height: 62vh;
  display: block;
  background:
    radial-gradient(600px 400px at 50% 40%, rgba(200, 255, 0, 0.03), transparent 70%),
    #07080a;
  border: 1px solid var(--line);
  cursor: grab;
  touch-action: none;
}
#graph-canvas:active { cursor: grabbing; }

/* ---- suggestions (graph gaps) ---- */
#suggest-panel { margin-top: 14px; display: grid; gap: 10px; }
#suggest-panel[hidden] { display: none; }
.sg-head {
  font-family: var(--font-dot); font-size: 12px; letter-spacing: 1px;
  color: var(--ink-dim);
}
.sg-card {
  border: 1px solid var(--line-hi);
  background: linear-gradient(to bottom, #171b12, #101308);
  padding: 12px 14px;
  clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 0 100%);
}
.sg-kind {
  font-family: var(--font-dot); font-size: 11px; letter-spacing: 1px;
  color: var(--magenta); margin-bottom: 4px;
}
.sg-title { font-size: 14px; font-weight: 500; color: var(--ink); }
.sg-why { font-size: 11.5px; color: var(--ink-dim); margin-top: 3px; }
.sg-actions { display: flex; gap: 6px; margin-top: 9px; flex-wrap: wrap; }
.sg-actions .btn { font-size: 11px; padding: 4px 10px; }
.sg-loading { font-size: 11px; color: #5a6150; }

/* ---- responsive ---- */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .panel { position: static; max-height: none; border-left: none; border-top: 1px solid var(--line); }
  #view { max-height: 52vh; }
  .topbar { flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
  .logo { font-size: 20px; }
  .logo-sub { display: none; }
  .topbar-actions { width: 100%; margin-left: 0; gap: 6px; display: grid; grid-template-columns: repeat(3, 1fr); }
  .topbar-actions .btn { font-size: 12px; padding: 8px 4px; }
  .ai-row { flex-wrap: wrap; }
  .stage { padding: 12px; }
  .stage-status { flex-wrap: wrap; gap: 8px; }
  .ratio-label { margin-left: 0; }
  .gallery-overlay { padding: 2vh 2vw; }
}

/* タッチ端末はスライダーのつまみとタップ領域を大きく。
   指で押すものは44px角を下限にする（iOSのガイドラインに合わせる）。 */
@media (pointer: coarse) {
  input[type="range"] { height: 28px; }
  input[type="range"]::-webkit-slider-thumb { width: 20px; height: 20px; margin-top: -8.5px; }
  input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; }
  .module-head { padding: 12px; }

  .btn,
  .preset-chip,
  .seg button,
  .stage-tabs button,
  .transition-grid button,
  .cloud-item button {
    min-height: 44px;
    padding-top: 10px;
    padding-bottom: 10px;
  }
  .seg button { padding-left: 2px; padding-right: 2px; }
  .cloud-item button { min-height: 40px; }

  /* ステージ下の小さなボタン列（比率・共有・言語）と、モジュールのサイコロ */
  .ratio-seg button,
  .share-btn,
  .dice { min-height: 40px; padding-top: 8px; padding-bottom: 8px; }

  /* リンクは文字だけだと指で狙えないので、上下に余白を持たせる */
  .topbar-links { align-items: center; }
  .topbar-links a { padding: 12px 4px; }

  /* チェックボックスと、その文字ごとタップできるように */
  input[type="checkbox"] { width: 22px; height: 22px; }
  .anim-toggle { min-height: 44px; display: inline-flex; align-items: center; gap: 6px; }

  /* カット削除の✕。押しやすくはするが、誤爆しないようサムネの角に留める */
  .work-del { padding: 6px 8px; font-size: 15px; }

  /* テキスト入力もタップしてから狙い直さずに済む高さにする */
  #caption-input, #caption-theme, #bible-negative, #bible-seed, #text-input, #ai-prompt {
    min-height: 40px;
  }
}

/* スライダーはつまみの分だけ親からはみ出していたので、内側に収める */
.ctl, .ctl input[type="range"] { box-sizing: border-box; max-width: 100%; }

/* ---- embed mode (about ページ内のライブプレビュー用) ---- */
body.embed { overflow: hidden; }
body.embed .topbar,
body.embed .panel,
body.embed .stage-tabs,
body.embed .stage-status,
body.embed .drop-hint,
body.embed .crt-overlay { display: none; }
body.embed .layout { grid-template-columns: 1fr; min-height: 100vh; }
body.embed .stage { padding: 0; background-image: none; }
body.embed .stage-inner { min-height: 100vh; }
body.embed #view { max-height: 100vh; border: none; box-shadow: none; }

/* ---- topbar links (About / GitHub) ---- */
.topbar-links { display: flex; gap: 12px; align-items: baseline; }
.topbar-links a {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-dim);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  white-space: nowrap;
}
.topbar-links a:hover { color: var(--acid); border-bottom-color: var(--acid); }

/* ---- collapsible panel sections ---- */
.panel-section.collapsible > .section-title {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.panel-section.collapsible > .section-title::before {
  content: "▾";
  font-size: 10px;
  color: var(--ink-dim);
  transition: transform 0.15s;
}
.panel-section.collapsed > .section-title::before { transform: rotate(-90deg); }
.panel-section.collapsed > .section-title { margin-bottom: 0; }
.panel-section.collapsed > *:not(.section-title) { display: none; }

/* ---- 適用順（ドラッグで並び替え） ---- */
.order-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.order-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  background: #161a11;
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink);
  cursor: grab;
  user-select: none;
}
.order-list li:hover { border-color: var(--line-hi); }
.order-list li.dragging { opacity: 0.4; }
.order-list li.over { border-color: var(--acid); }
.order-list .ord-num {
  font-family: var(--font-mono); font-size: 10px; color: var(--ink-dim);
  min-width: 14px;
}
.order-list .ord-grip { color: var(--ink-dim); font-size: 11px; margin-left: auto; }
.order-list li.off { color: var(--ink-dim); opacity: 0.55; }

/* ---- 動画レビュー ---- */
#review-panel { margin-top: 10px; display: grid; gap: 6px; }
#review-panel[hidden] { display: none; }
.review-head { font-family: var(--font-mono); font-size: 11.5px; color: var(--acid); }
.review-ok { font-size: 12px; color: var(--ink-dim); }
.review-item {
  display: grid; grid-template-columns: 54px 1fr; gap: 8px;
  font-size: 11.5px; line-height: 1.7;
  padding: 6px 8px; background: #12160e; border-left: 2px solid var(--line-hi);
}
.review-item .review-sev {
  font-family: var(--font-dot); font-size: 10.5px; letter-spacing: 1px;
}
.review-item.sev-error { border-left-color: var(--magenta); }
.review-item.sev-error .review-sev { color: var(--magenta); }
.review-item.sev-warn { border-left-color: #e0b264; }
.review-item.sev-warn .review-sev { color: #e0b264; }
.review-item.sev-info .review-sev { color: var(--cyan); }
.review-item .review-msg { color: var(--ink); }

/* ---- カット字幕 ---- */
.clip-caption {
  margin-top: 8px; padding: 8px; background: #12160e;
  border: 1px solid var(--line); display: grid; gap: 6px;
}
.clip-caption[hidden] { display: none; }
#caption-input {
  width: 100%; box-sizing: border-box; padding: 5px 7px;
  background: #0a0d07; border: 1px solid var(--line); color: var(--ink);
  font-family: var(--font-mono); font-size: 12px;
}
#caption-input:focus { outline: none; border-color: var(--acid); }
#caption-preview {
  position: absolute; left: 5%; right: 5%; bottom: 7%;
  text-align: center; pointer-events: none;
  font-family: var(--font-jp, inherit); font-weight: 800;
  font-size: clamp(13px, 3.4vw, 26px); line-height: 1.35;
  color: #fff; text-shadow: 0 0 6px #000, 2px 2px 0 #000, -2px 2px 0 #000, 2px -2px 0 #000, -2px -2px 0 #000;
  white-space: pre-line;
}
#caption-preview[hidden] { display: none; }

.caption-ai { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin-top: 6px; }
#caption-theme {
  min-width: 0; padding: 5px 7px; background: #0a0d07;
  border: 1px solid var(--line); color: var(--ink);
  font-family: var(--font-mono); font-size: 11.5px;
}
#caption-theme:focus { outline: none; border-color: var(--acid); }
#clip-split { padding: 3px 8px; font-size: 10.5px; align-self: end; }

/* ---- スタイルバイブル ---- */
.bible-swatches { display: flex; gap: 4px; margin: 8px 0 4px; min-height: 22px; }
.bible-swatches span {
  flex: 1; height: 22px; border: 1px solid var(--line);
  font-size: 0; 
}
.bible-swatches:empty::after {
  content: "参照画像なし"; font-family: var(--font-mono); font-size: 11px; color: var(--ink-dim);
}
.bible-field {
  display: grid; grid-template-columns: 68px 1fr; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 11px; color: var(--ink-dim); margin-top: 6px;
}
.bible-field input {
  min-width: 0; padding: 4px 6px; background: #0a0d07;
  border: 1px solid var(--line); color: var(--ink);
  font-family: var(--font-mono); font-size: 11.5px;
}
.bible-field input:focus { outline: none; border-color: var(--acid); }

/* ---- クラウド保存したプロジェクト ---- */
.cloud-list { display: grid; gap: 4px; margin-top: 6px; }
.cloud-list[hidden] { display: none; }
.cloud-item {
  display: grid; grid-template-columns: 1fr auto auto; gap: 6px; align-items: center;
  padding: 5px 7px; background: #12160e; border-left: 2px solid var(--line-hi);
  font-family: var(--font-mono); font-size: 11px;
}
.cloud-item b { font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cloud-item small { color: var(--ink-dim); display: block; font-size: 10px; }
.cloud-item button { padding: 2px 7px; font-size: 10.5px; }

/* レイヤー一覧。上が手前（配列とは逆順に並べている） */
.layer-list { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.layer-row {
  display: flex; align-items: center; gap: 2px;
  border: 1px solid var(--line); background: #10130b; padding: 2px;
}
.layer-row.sel { border-color: var(--acid); background: #1a2012; }
.layer-row button {
  font-family: var(--font-dot); font-size: 11px; background: none; border: none;
  color: var(--ink-dim); cursor: pointer; padding: 3px 4px;
}
.layer-row .layer-name {
  flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.layer-row.sel .layer-name, .layer-row.sel .layer-eye { color: var(--acid); }
.layer-row button:hover:not(:disabled) { color: var(--acid); }
.layer-row button:disabled { opacity: .3; cursor: default; }
.layer-row .layer-del:hover { color: #ff3ea5; }
.layer-sub {
  font-family: var(--font-dot); font-size: 10px; color: var(--ink-dim);
  margin: 10px 0 0; letter-spacing: 1px;
}

/* 動画の切り出し区間。数値入力だけだと尺の見当がつかないのでスライダーを添える */
.trim-range { margin-top: 6px; }
.trim-range input[type="range"] { margin-bottom: 4px; }
.trim-used {
  font-family: var(--font-dot); font-size: 10px; color: var(--ink-dim);
  margin: 4px 0 0; letter-spacing: 1px;
}
.trim-used b { font-family: var(--font-mono); color: var(--acid); font-weight: 400; }
