/* CUTROOM — 落ち着いた編集室。映画が主役なので UI は暗く静かに、操作した所だけがはっきり反応する。 */

:root {
  /* 地 */
  --bg: #16171a;
  --bg-2: #1b1c20;
  --panel: #222328;
  --panel-2: #2a2b31;
  --line: #2e3036;
  --line-2: #3c3f46;

  /* 文字 */
  --text: #e8e6e0;
  --text-2: #a8a59d;
  --text-3: #75736c;

  /* トラック色：映像=青、音声=緑、劇伴=紫 */
  --v1: #4c87cc;
  --v1-bg: #1c2a3c;
  --v1-edge: #3f72ad;
  --v1-ink: #9fc4ee;
  --a1: #5c9d78;
  --a1-bg: #17291f;
  --a1-edge: #3f7a58;
  --a1-wave: #6db48a;
  --a1-ink: #9bd0b0;
  --m1: #8b75c9;
  --m1-bg: #221d34;
  --m1-edge: #5e4d93;
  --m1-wave: #9883d6;
  --m1-ink: #bfb0ef;

  /* 操作の色：選択・挿入位置は琥珀（タリーランプ）、再生位置は赤 */
  --sel: #f2b544;
  --sel-ink: #1d1505;
  --sel-soft: rgba(242, 181, 68, 0.14);
  --head: #ff5c50;

  /* 文字組 */
  --font: "Segoe UI Variable Text", "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  --mono: "Cascadia Mono", "Consolas", "SFMono-Regular", "Menlo", ui-monospace, monospace;

  /* 動き */
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-snap: cubic-bezier(0.3, 1.55, 0.5, 1);
  --t-fast: 120ms;
  --t-med: 200ms;
  --t-slide: 220ms;
  --nudge: 5px;

  /* タイムラインの縦寸法 */
  --ruler-h: 22px;
  --v1-top: 26px;
  --v1-h: 56px;
  --a1-top: 86px;
  --a1-h: 40px;
  --m1-top: 130px;
  --m1-h: 30px;
  --lanes-h: 160px;

  /* 映像の本当の縦横比（黒帯を除いたもの。main.js が素材から調べて上書き）。スマホの画面で使う */
  --pic-ar: 1.7778;
}

/* 背の低い画面（13〜14型ノートなど）：素材エリアとタイムラインを詰めて、プレビューを大きく残す */
@media (max-height: 800px) {
  :root {
    --v1-h: 46px;
    --a1-top: 76px;
    --a1-h: 32px;
    --m1-top: 112px;
    --m1-h: 24px;
    --lanes-h: 136px;
  }
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --t-fast: 1ms;
    --t-med: 1ms;
    --t-slide: 1ms;
    --nudge: 0px;
  }
  .clip.snap, .clip.snap .clip-v, .clip.snap .clip-a,
  .clip.ping .clip-v, .clip.ping .clip-a,
  .card.pulse, .card.pulse .card-thumb,
  .btn-check.arrive, .selchip { animation: none !important; }
  .clip.moving { --ly: 0px; }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: auto;
}
button { font: inherit; color: inherit; }
svg { display: block; }
[hidden] { display: none !important; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--sel); outline-offset: 2px; }

.app {
  display: grid;
  grid-template-rows: 44px minmax(0, 1fr) auto;
  height: 100vh;
  min-width: 1060px;
  min-height: 660px;
}

kbd {
  display: inline-block;
  font: 500 10.5px/1 var(--mono);
  padding: 2px 5px 3px;
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--text-2);
  background: var(--panel);
}

/* ---------------------------------------------------------------- ボタン */
.btn {
  height: 30px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--t-fast), border-color var(--t-fast), transform 80ms;
}
.btn svg { width: 14px; height: 14px; flex: none; }
@media (hover: hover) { .btn:hover { background: #31333a; border-color: #4b4e56; } }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; background: var(--panel-2); border-color: var(--line-2); }
.btn-quiet { background: transparent; }
.btn-primary { background: var(--sel); border-color: var(--sel); color: var(--sel-ink); font-weight: 650; }
@media (hover: hover) { .btn-primary:hover { background: #f7c35e; border-color: #f7c35e; } }
.btn-transport { min-width: 84px; justify-content: center; }
.btn-transport[data-state="stop"] { border-color: #6b5a33; background: #2e2a21; }

/* ---------------------------------------------------------------- 上部バー */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
}
.brand { flex: 1; display: flex; align-items: center; gap: 14px; min-width: 0; }
.logo { display: flex; align-items: center; gap: 8px; font: 700 12px/1 var(--font); letter-spacing: 0.24em; }
.logo svg { width: 16px; height: 16px; color: var(--sel); }
.scene { color: var(--text-3); font-size: 12px; white-space: nowrap; }
.status {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.st-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--v1); }
.st-dot.o { background: var(--text-2); }
.st-cmp { color: var(--sel); }
.top-right { flex: 1; display: flex; justify-content: flex-end; align-items: center; gap: 20px; min-width: 0; }
.prog { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.prog-num { color: var(--text); font-weight: 600; min-width: 3.4em; }
.prog-meter { width: 76px; height: 4px; border-radius: 2px; background: #2a2c31; overflow: hidden; }
.prog-meter i { display: block; height: 100%; width: 0; background: var(--v1); transition: width var(--t-med) var(--ease-out); }
.keys { display: flex; gap: 12px; color: var(--text-3); font-size: 11.5px; white-space: nowrap; }
.keys kbd + kbd { margin-left: 2px; }
@media (max-width: 1380px) { .keys { display: none; } }

/* ---------------------------------------------------------------- プレビュー（2画面） */
.stage {
  min-height: 0;
  container-type: size;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 22px;
  padding: 12px 18px 10px;
}
.monitor {
  flex: none;
  /* 2画面が横に並び、高さにも収まる最大の 16:9 */
  width: min(calc((100cqw - 22px) / 2), calc((100cqh - 70px) * 16 / 9));
  display: flex;
  flex-direction: column;
}
.mon-head { height: 28px; display: flex; align-items: center; gap: 8px; padding: 0 2px; }
.mon-dot { width: 8px; height: 8px; border-radius: 2px; background: var(--v1); }
.mon-r .mon-dot { background: var(--text-2); }
.mon-title { font-weight: 600; font-size: 13px; letter-spacing: 0.02em; }
.mon-tag { display: flex; align-items: center; gap: 10px; color: var(--text-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.mon-tag:empty { display: none; }
.mon-l .mon-tag:not(:empty) { color: var(--v1-ink); }
.aud { display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px 1px 5px; border-radius: 10px; background: var(--panel-2); color: var(--text-2); font-size: 11px; }
.aud svg { width: 13px; height: 13px; }
.aud.mute { color: var(--text-3); }

.screen {
  position: relative;
  aspect-ratio: 16 / 9;
  width: 100%;
  background: #060607;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 0 0 1px #000, 0 0 0 2px #26282d, 0 12px 30px rgba(0, 0, 0, 0.35);
}
.lane-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #060607;
  opacity: 0;
  pointer-events: none;
}
.lane-video.on { opacity: 1; } /* 切り替えは常にハードカット */

.screen-empty {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
  line-height: 1.8;
  z-index: 1;
}
.app:not(.has-cuts):not([data-play="solo"]) .screen-empty { display: grid; }
.app:not(.has-cuts) .mon-l .screen { cursor: default; }

.screen-badge {
  position: absolute;
  left: 10px;
  top: 10px;
  z-index: 2;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(10, 10, 12, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
  font-size: 11.5px;
  font-weight: 600;
}
.screen-badge:empty { display: none; }

.bigplay {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 3;
  width: 62px;
  height: 62px;
  margin: -31px 0 0 -31px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(14, 15, 17, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #fff;
  pointer-events: none;
  opacity: 0;
  transform: scale(0.92);
  transition: opacity var(--t-fast), transform var(--t-fast) var(--ease-out);
}
.bigplay svg { width: 24px; height: 24px; margin-left: 3px; }
/* 右：止まっている間は常に見せる。左：カットがあれば hover で（ホバーのない端末では常に） */
.app[data-mode="edit"]:not([data-play="original"]) #bigR { opacity: 1; transform: none; }
@media (hover: hover) {
  .app[data-mode="edit"][data-play="idle"].has-cuts .mon-l .screen:hover #bigL,
  .app[data-mode="edit"][data-play="original"].has-cuts .mon-l .screen:hover #bigL { opacity: 1; transform: none; }
  .screen:hover .bigplay { background: rgba(14, 15, 17, 0.78); }
}
@media (hover: none) {
  .app[data-mode="edit"][data-play="idle"].has-cuts #bigL,
  .app[data-mode="edit"][data-play="original"].has-cuts #bigL { opacity: 1; transform: none; }
}

.screen-loading {
  position: absolute;
  right: 10px;
  bottom: 8px;
  z-index: 3;
  color: var(--text-2);
  font-size: 11.5px;
  opacity: 0;
  transition: opacity var(--t-fast);
}
.app.loading-l .mon-l .screen-loading,
.app.loading-r .mon-r .screen-loading { opacity: 1; }


.monitor { container-type: inline-size; }
.mon-foot { height: 42px; display: flex; align-items: center; gap: 12px; padding: 0 2px; min-width: 0; }
@container (max-width: 560px) { .mon-note { display: none; } }
.tc { font: 500 13px/1 var(--mono); font-variant-numeric: tabular-nums; color: var(--text); letter-spacing: 0.02em; }
.tc-sep { color: var(--text-3); margin: 0 6px; }
.tc-dim { color: var(--text-3); }
.mon-note { margin-left: auto; min-width: 0; color: var(--text-3); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app[data-mode="compare"] .mon-foot .btn,
.app[data-mode="compare"] .mon-note { visibility: hidden; }
/* 置いたカットがない間は左の再生ボタンを出さない（試写中は停止ボタンとして出す） */
.app:not(.has-cuts):not([data-play="solo"]) #playL { visibility: hidden; }


/* ---------------------------------------------------------------- 素材エリア */
.bin {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  transition: opacity var(--t-med);
}
.bin-label {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  padding-left: 18px;
  border-right: 1px solid var(--line);
}
.bin-title { font-weight: 600; font-size: 13px; }
.bin-count { color: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bin-strip {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 16px 1px; /* 下はスクロールバー分。選択で浮くカード（-5px）が上で切れない余白 */
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: #3a3c43 transparent;
}
.bin-strip::-webkit-scrollbar { height: 8px; }
.bin-strip::-webkit-scrollbar-thumb { background: #34363c; border-radius: 4px; }
.bin-strip::-webkit-scrollbar-track { background: transparent; }

.card {
  position: relative;
  flex: none;
  width: 128px;
  border-radius: 6px;
  background: var(--panel);
  box-shadow: 0 0 0 1px var(--line);
  cursor: pointer;
  translate: 0 0;
  transition: translate var(--t-fast) var(--ease-out), box-shadow var(--t-fast) var(--ease-out), background-color var(--t-fast);
}
.card-thumb {
  position: relative;
  height: 72px;
  border-radius: 6px 6px 0 0;
  background: #0b0b0c center / cover no-repeat;
  overflow: hidden;
  transition: filter var(--t-med);
}
.card-meta { height: 24px; display: flex; align-items: center; justify-content: space-between; padding: 0 7px 0 4px; }
.card-dur { font: 500 11.5px/1 var(--mono); font-variant-numeric: tabular-nums; color: var(--text-2); }
.card-dur small { font: 10px var(--font); margin-left: 1px; color: var(--text-3); }

.card-play {
  width: 20px;
  height: 18px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text-2);
  cursor: pointer;
  transition: background-color var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.card-play svg { width: 9px; height: 9px; }
@media (hover: hover) {
  .card-play:hover { background: var(--v1-bg); border-color: var(--v1); color: #fff; }
  .card:hover:not(:has(.card-play:hover)) { box-shadow: 0 0 0 1px #50535b; translate: 0 -1px; }
}
.card:active:not(:has(.card-play:active)) { translate: 0 1px; }

/* 選択中：浮く＋太い琥珀の輪郭＋「選択中」 */
.card.is-sel,
.card.is-sel:hover:not(:has(.card-play:hover)) {
  translate: 0 -5px;
  background: #2c2a25;
  box-shadow: 0 0 0 2px var(--sel), 0 10px 20px rgba(0, 0, 0, 0.5);
}

.tag {
  position: absolute;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 10.5px;
  font-weight: 650;
  line-height: 1.3;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-fast), transform var(--t-fast) var(--ease-out);
}
.tag svg { width: 11px; height: 11px; }
.tag-sel { left: 5px; top: 5px; background: var(--sel); color: var(--sel-ink); transform: translateY(-3px); }
.card.is-sel .tag-sel { opacity: 1; transform: none; }
.tag-placed { left: 50%; top: 50%; transform: translate(-50%, -50%) scale(0.94); background: rgba(18, 19, 22, 0.86); color: var(--text); border: 1px solid var(--line-2); }

/* 配置済み：位置はそのまま、薄く・点線の輪郭・「配置済み」 */
.card.is-placed { background: transparent; box-shadow: none; outline: 1px dashed #464950; outline-offset: -1px; }
@media (hover: hover) { .card.is-placed:hover:not(:has(.card-play:hover)) { box-shadow: none; outline-color: #6a6d75; } }
.card.is-placed .card-thumb { filter: grayscale(0.85) brightness(0.4); }
.card.is-placed .tag-placed { opacity: 1; transform: translate(-50%, -50%); }
.card.is-placed .card-dur { color: var(--text-3); }
.card.is-linked { outline: 1px dashed var(--sel); }
.card:focus-visible { outline: 2px solid var(--sel); outline-offset: -2px; } /* 内側に描いて素材エリアで切れないように */

.card.pulse { animation: card-pulse 380ms var(--ease-snap); }
.card.pulse .card-thumb { animation: card-flash 520ms ease-out; }
@keyframes card-pulse { 0% { scale: 1; } 35% { scale: 1.05; } 100% { scale: 1; } }
@keyframes card-flash { 0% { box-shadow: inset 0 0 0 2px var(--sel); } 100% { box-shadow: inset 0 0 0 2px rgba(242, 181, 68, 0); } }

.card-prog { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(0, 0, 0, 0.55); opacity: 0; }
.card-prog i { display: block; height: 100%; width: 0; background: var(--v1-ink); }
.card.is-solo .card-prog { opacity: 1; }
.card.is-solo .card-play { background: var(--v1); border-color: var(--v1); color: #fff; }

.app[data-mode="compare"] .bin { opacity: 0.4; pointer-events: none; }

/* ---------------------------------------------------------------- タイムライン */
.timeline { padding: 0 18px 14px; }
.tl-bar { height: 50px; }
.tl-row {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 14px;
}
.tl-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tl-right { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.tl-hint { color: var(--text-2); font-size: 12.5px; white-space: nowrap; display: flex; align-items: center; gap: 4px; }
.tl-hint kbd { margin-left: 6px; }

.selchip {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 4px 0 4px;
  border-radius: 6px;
  background: var(--sel-soft);
  box-shadow: inset 0 0 0 1px rgba(242, 181, 68, 0.45);
  animation: chip-in var(--t-med) var(--ease-out);
}
.selchip-thumb { width: 38px; height: 22px; border-radius: 3px; background: #000 center / cover; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5); }
.selchip-text { display: flex; gap: 6px; align-items: baseline; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--text-2); padding-right: 6px; }
.selchip-text b { color: var(--sel); font-weight: 650; }
.selchip .btn { height: 24px; padding: 0 9px; font-size: 12px; border-color: rgba(242, 181, 68, 0.45); }
@media (hover: hover) { .selchip .btn:hover { background: rgba(242, 181, 68, 0.18); } }
@keyframes chip-in { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.remain {
  height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border: 1px dashed var(--line-2);
  border-radius: 6px;
  color: var(--text-3);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.remain b { color: var(--text-2); font-weight: 600; }
.btn-check svg { width: 12px; height: 12px; }
.btn-check.arrive { animation: cta-in 340ms var(--ease-snap); }
@keyframes cta-in { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: none; } }

/* 答え合わせの進み */
.cmp-track { position: relative; display: flex; align-items: center; gap: 2px; width: min(46vw, 720px); height: 12px; }
.cmp-seg {
  flex: 1 1 0;
  min-width: 4px;
  height: 12px;
  padding: 0;
  border: 0;
  border-radius: 2px;
  position: relative;
  overflow: hidden;
  background: #2a2c32;
  cursor: pointer;
  transition: background-color var(--t-fast), transform var(--t-fast) var(--ease-out);
}
@media (hover: hover) { .cmp-seg:hover { background: #3a3d44; transform: scaleY(1.25); } }
.cmp-seg i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--sel); }
.cmp-seg.done { background: #4b4d54; }
.cmp-seg.done i { background: #6e7078; }
.cmp-seg.cur { background: #3d3524; }
.cmp-count { font: 600 13px/1 var(--font); font-variant-numeric: tabular-nums; color: var(--text); }

.tl-body { display: grid; grid-template-columns: 82px minmax(0, 1fr); gap: 0 8px; }
.tl-heads { position: relative; height: var(--lanes-h); }
.th {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 8px;
  border-radius: 4px;
  font-size: 11.5px;
  color: var(--text-2);
  background: var(--panel);
  white-space: nowrap;
}
.th b { font: 650 11px/1 var(--mono); padding: 3px 4px; border-radius: 3px; }
.th-v1 { top: var(--v1-top); height: var(--v1-h); }
.th-v1 b { background: var(--v1-bg); color: var(--v1-ink); box-shadow: inset 0 0 0 1px var(--v1-edge); }
.th-a1 { top: var(--a1-top); height: var(--a1-h); }
.th-a1 b { background: var(--a1-bg); color: var(--a1-ink); box-shadow: inset 0 0 0 1px var(--a1-edge); }
.th-m1 { top: var(--m1-top); height: var(--m1-h); }
.th-m1 b { background: var(--m1-bg); color: var(--m1-ink); box-shadow: inset 0 0 0 1px var(--m1-edge); }
.lock { display: block; width: 12px; height: 12px; color: var(--text-3); margin-left: -1px; }
.lock svg { width: 12px; height: 12px; }

.lanes { position: relative; height: var(--lanes-h); user-select: none; -webkit-user-select: none; }
.lanes.no-anim *, .lanes.no-anim { transition: none !important; }

.ruler {
  position: absolute;
  left: 0;
  width: var(--canvas-w, 100%);
  top: 0;
  height: var(--ruler-h);
  border-bottom: 1px solid var(--line);
  cursor: col-resize;
}
.tick { position: absolute; bottom: 0; width: 1px; height: 5px; background: #45474e; }
.tick.minor { height: 3px; background: #393b41; }
.tick.major { height: 9px; background: #6a6c73; }
.tick-label { position: absolute; top: 3px; padding-left: 4px; font: 10px/1 var(--mono); color: var(--text-3); pointer-events: none; }

.row { position: absolute; left: 0; width: var(--canvas-w, 100%); border-radius: 4px; }
.row-v1 { top: var(--v1-top); height: var(--v1-h); background: #1b1c20; box-shadow: inset 0 0 0 1px #24262b; }
.row-a1 { top: var(--a1-top); height: var(--a1-h); background: #1b1c20; box-shadow: inset 0 0 0 1px #24262b; }
.row-m1 { top: var(--m1-top); height: var(--m1-h); background: #18191c; }
.lanes.placing .row-v1, .lanes.placing .row-a1 { box-shadow: inset 0 0 0 1px #2f3036; }

.music {
  position: absolute;
  top: var(--m1-top);
  height: var(--m1-h);
  border-radius: 3px;
  background: var(--m1-bg);
  border: 1px solid var(--m1-edge);
  overflow: hidden;
  cursor: default;
}
.music .wave { position: absolute; inset: 2px 0; width: 100%; height: calc(100% - 4px); fill: var(--m1-wave); opacity: 0.75; }
.music-label {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  padding: 1px 6px;
  border-radius: 3px;
  background: rgba(24, 20, 38, 0.82);
  color: var(--m1-ink);
  font-size: 10.5px;
}

.end-mark { position: absolute; top: 0; height: var(--lanes-h); border-left: 1px dashed #3d3f46; pointer-events: none; }
.end-mark span { position: absolute; top: 4px; left: 4px; font-size: 10px; color: var(--text-3); white-space: nowrap; }

.empty-hint {
  position: absolute;
  top: var(--v1-top);
  height: calc(var(--a1-top) + var(--a1-h) - var(--v1-top));
  display: none;
  place-items: center;
  border: 1px dashed #3d4047;
  border-radius: 6px;
  color: var(--text-3);
  font-size: 13px;
  letter-spacing: 0.04em;
  pointer-events: none;
  transition: color var(--t-fast), border-color var(--t-fast), background-color var(--t-fast);
}
.lanes.is-empty .empty-hint { display: grid; }
.lanes.is-empty.placing .empty-hint { border-color: rgba(242, 181, 68, 0.6); color: var(--sel); background: rgba(242, 181, 68, 0.04); }

/* ---- カット（V1 + A1 で1組） */
.clips { position: absolute; left: 0; top: 0; bottom: 0; width: var(--canvas-w, 100%); pointer-events: none; }
.clip {
  --nx: 0px;
  --ly: 0px;
  position: absolute;
  top: var(--v1-top);
  height: calc(var(--a1-top) + var(--a1-h) - var(--v1-top));
  pointer-events: auto;
  cursor: pointer;
  translate: var(--nx) var(--ly);
  transition: left var(--t-slide) var(--ease-out), translate var(--t-fast) var(--ease-out);
}
.clip-v, .clip-a { position: absolute; left: 0; right: 0; border-radius: 3px; transition: box-shadow var(--t-fast), border-color var(--t-fast), filter var(--t-fast); }
.clip-v {
  top: 0;
  height: var(--v1-h);
  background: var(--v1-bg) left center / auto 100% repeat-x;
  border: 1px solid var(--v1-edge);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.45);
}
.clip.narrow .clip-v { background-position: center; }
.clip-a { top: calc(var(--a1-top) - var(--v1-top)); height: var(--a1-h); background: var(--a1-bg); border: 1px solid var(--a1-edge); overflow: hidden; }
.clip-a .wave { width: 100%; height: 100%; fill: var(--a1-wave); }
@media (hover: hover) {
  .clip:hover { --ly: -1px; }
  .clip:hover .clip-v, .clip:hover .clip-a { filter: brightness(1.18); }
}
.clip:active { --ly: 1px; }

/* 選択中：V1・A1 の両方が浮いて琥珀の輪郭 */
.clip.is-sel { --ly: -4px; z-index: 3; }
.clip.is-sel .clip-v, .clip.is-sel .clip-a { border-color: var(--sel); box-shadow: 0 0 0 1px var(--sel), 0 8px 18px rgba(0, 0, 0, 0.55); filter: none; }
.clip.is-sel::after {
  /* V1 と A1 をつなぐ印（同じ組） */
  content: "";
  position: absolute;
  left: 50%;
  top: var(--v1-h);
  width: 2px;
  height: calc(var(--a1-top) - var(--v1-top) - var(--v1-h));
  margin-left: -1px;
  background: var(--sel);
}

/* 置ける場所に乗ると、両隣が少し避ける */
.clip.nudge-l { --nx: calc(var(--nudge) * -1); }
.clip.nudge-r { --nx: var(--nudge); }

/* 移動中は持ち上がる */
.clip.moving { --ly: -12px; z-index: 5; }
.clip.moving .clip-v, .clip.moving .clip-a { border-color: var(--sel); box-shadow: 0 0 0 1px var(--sel), 0 12px 24px rgba(0, 0, 0, 0.6); }

/* 飛んできたサムネイルが着くまで隠す */
.clip.incoming { opacity: 0; transition: left var(--t-slide) var(--ease-out); }

/* 着地：吸い付くように収まる */
.clip.snap { animation: clip-settle 280ms var(--ease-snap); }
.clip.snap .clip-v, .clip.snap .clip-a { animation: clip-flash 360ms ease-out; }
@keyframes clip-settle { from { transform: translateY(-6px); } to { transform: none; } }
@keyframes clip-flash {
  from { box-shadow: 0 0 0 2px rgba(242, 181, 68, 0.95); filter: brightness(1.3); }
  to { box-shadow: 0 0 0 2px rgba(242, 181, 68, 0); filter: none; }
}
.clip.ping .clip-v, .clip.ping .clip-a { animation: clip-ping 700ms ease-out; }
@keyframes clip-ping {
  0%, 45% { box-shadow: 0 0 0 2px var(--sel); }
  100% { box-shadow: 0 0 0 2px rgba(242, 181, 68, 0); }
}

/* 答え合わせ中：いま比べている自分のカットだけを残す */
.app[data-mode="compare"] .clips { pointer-events: none; }
.app[data-mode="compare"] .clip { pointer-events: none; }
.clips.comparing .clip { opacity: 0.35; transition: left var(--t-slide) var(--ease-out), opacity var(--t-med); }
.clips.comparing .clip.is-cmp { opacity: 1; }
.clips.comparing .clip.is-cmp .clip-v, .clips.comparing .clip.is-cmp .clip-a { border-color: var(--sel); box-shadow: 0 0 0 1px var(--sel); }
.app[data-mode="compare"] .ruler { pointer-events: none; }

/* ---- 置ける場所 */
.slots { position: absolute; left: 0; top: 0; bottom: 0; width: var(--canvas-w, 100%); pointer-events: none; opacity: 0; transition: opacity var(--t-fast); }
.slots.show { opacity: 1; }
/* 当たり判定は「カット間の隙間＋端の少し」（V1/A1 帯）と、ルーラー帯の幅広のつまみ。カット中央には重ねない */
.slot {
  --x: 50%;
  --tab: 20px;
  position: absolute;
  top: var(--ruler-h);
  height: calc(var(--a1-top) + var(--a1-h) - var(--ruler-h));
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  z-index: 4;
}
.slots:not(.show) .slot { pointer-events: none; }
.slot-tab {
  position: absolute;
  left: var(--x);
  top: calc(var(--ruler-h) * -1);
  width: var(--tab);
  height: var(--ruler-h);
  transform: translateX(-50%);
}
.slot-line {
  position: absolute;
  left: var(--x);
  top: 0;
  bottom: 0;
  width: 0;
  border-left: 1px dashed rgba(242, 181, 68, 0.55);
  pointer-events: none;
  transform: translateX(-0.5px) scaleY(0.55);
  transform-origin: top;
  transition: transform var(--t-med) var(--ease-out), border-color var(--t-fast);
}
.slots.show .slot-line { transform: translateX(-0.5px); }
.slot-chip {
  position: absolute;
  left: 50%;
  top: 6px;
  width: 0;
  height: 0;
  margin-left: -5px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 7px solid rgba(242, 181, 68, 0.6);
  transition: border-top-color var(--t-fast), transform var(--t-fast) var(--ease-out);
}
.slot::before {
  content: "";
  position: absolute;
  left: calc(var(--x) - 7px);
  width: 14px;
  top: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, var(--sel-soft), transparent);
  pointer-events: none; /* 飾り。当たり判定をカット側へ広げない */
  opacity: 0;
  transition: opacity var(--t-fast);
}
.slot.hot .slot-line { border-left: 2px solid var(--sel); transform: translateX(-1px); }
.slot.hot .slot-chip { border-top-color: var(--sel); transform: translateY(2px); }
.slot.hot::before { opacity: 1; }
@media (hover: hover) {
  .slot:hover .slot-line { border-left: 2px solid var(--sel); transform: translateX(-1px); }
  .slot:hover .slot-chip { border-top-color: var(--sel); transform: translateY(2px); }
  .slot:hover::before { opacity: 1; }
}
.lanes.is-empty .slot .slot-line, .lanes.is-empty .slot .slot-tab, .lanes.is-empty .slot::before { display: none; }
/* 置ける場所を開いている間、カットは時間軸から少しずれる：目盛りの数字は控えめにし、ルーラーでの移動は止める */
.lanes.placing .ruler { cursor: default; }
.lanes.placing .tick-label { opacity: 0.35; }

/* 末尾に置くときの大きさの予告 */
.ghost { position: absolute; top: var(--v1-top); height: calc(var(--a1-top) + var(--a1-h) - var(--v1-top)); pointer-events: none; opacity: 0; transition: opacity var(--t-fast); z-index: 3; }
.ghost.on { opacity: 1; }
.ghost i { position: absolute; left: 0; right: 0; border: 1px dashed rgba(242, 181, 68, 0.75); border-radius: 3px; background: rgba(242, 181, 68, 0.06); }
.ghost .g-v { top: 0; height: var(--v1-h); }
.ghost .g-a { top: calc(var(--a1-top) - var(--v1-top)); height: var(--a1-h); }
.ghost span { position: absolute; left: 8px; top: 8px; font-size: 11px; color: var(--sel); white-space: nowrap; }
.ghost.narrow span { display: none; }

/* ---- 再生位置 */
.playhead {
  position: absolute;
  left: 0;
  top: 0;
  height: var(--lanes-h);
  width: 0;
  border-left: 1px solid var(--head);
  z-index: 6;
  pointer-events: none;
}
.playhead::before {
  content: "";
  position: absolute;
  top: 0;
  left: -6px;
  border-left: 5.5px solid transparent;
  border-right: 5.5px solid transparent;
  border-top: 8px solid var(--head);
}

/* ---------------------------------------------------------------- 飛ぶサムネイル */
.flyers { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.flyer {
  position: fixed;
  border-radius: 4px;
  background: #000 center / cover no-repeat;
  outline: 1.5px solid var(--sel);
  will-change: left, top, width, height;
}
.flyer.back { outline: 1px solid rgba(255, 255, 255, 0.3); opacity: 0.9; }

@media (max-height: 800px) {
  .app { grid-template-rows: 40px minmax(0, 1fr) auto; min-height: 600px; }
  .stage { padding-top: 8px; padding-bottom: 6px; }
  .bin-strip { padding-top: 9px; }
  .card { width: 103px; }
  .card-thumb { height: 58px; }
  .card-meta { height: 22px; }
  .tl-bar { height: 44px; }
  .timeline { padding-bottom: 10px; }
}

.fatal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 40px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  text-align: center;
  line-height: 1.8;
  z-index: 100;
}

/* ================================================================ スマホ・タブレット */

/* ---- 新しい部品（PC では基本的に出さない） */
.mon-live { display: none; align-items: center; gap: 4px; color: var(--v1-ink); font-size: 10.5px; font-weight: 600; white-space: nowrap; }
.mon-live::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.mon-r .mon-live { color: var(--text-2); }

.selchip-x {
  display: none;
  place-items: center;
  width: 30px;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--sel);
  cursor: pointer;
}
.selchip-x svg { width: 14px; height: 14px; }

.lanes-wrap { position: relative; min-width: 0; }
/* ---- ルーラーは指でなぞって再生位置を動かす（ページのスクロールにしない） */
.ruler { touch-action: none; }

/* 答え合わせの進み：吹き出し */
.cmp-bubble {
  position: absolute;
  bottom: calc(50% + 12px);
  transform: translateX(-50%);
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--sel);
  color: var(--sel-ink);
  font-size: 11.5px;
  font-weight: 650;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--t-fast);
}
.cmp-bubble.on { opacity: 1; }
.cmp-bubble { z-index: 2; } /* 区切りの上の ✓／✕ より手前に */

/* ---- 指で操作する端末（スマホ・タブレット共通） */
@media (pointer: coarse) {
  .app {
    min-width: 0;
    min-height: 0;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
  * { -webkit-tap-highlight-color: transparent; }
  button, .card, .clip, .slot, .screen { touch-action: manipulation; }
  .keys { display: none; }
  .selchip-x { display: grid; }
  .card-play { position: relative; }
  .card-play::before { content: ""; position: absolute; inset: -10px -10px -6px -6px; } /* 小さな ▶ も指で押せるように */
  .cmp-track { height: 40px; touch-action: none; }
  .cmp-seg { pointer-events: none; } /* 指ではバー全体をなぞって選ぶ（main.js） */
}
/* 幅の狭いタブレット（PC と同じ配置）：タイムライン上の帯が重ならないよう、案内文を縮める */
@media (pointer: coarse) and (max-width: 1099px) {
  .selchip-text { display: none; }
  .tl-row { grid-template-columns: auto minmax(0, 1fr) auto; }
  .tl-hint { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; text-align: center; }
  .cmp-track { width: 100%; }
}
/* ホーム画面から開いた iPad など：上端のステータスバーの下から始める（スマホ横向きの配置では下で 0 に戻す） */
.app { padding-top: env(safe-area-inset-top); }

/* ---- 最初の画面（タップで音と映像を有効にする） */
.gate {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(12, 13, 15, 0.88);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.gate-card {
  width: min(440px, 100%);
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 22px 24px 18px;
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 0 0 1px var(--line-2), 0 20px 50px rgba(0, 0, 0, 0.5);
  text-align: center;
}
.gate-card p { margin: 0; }
.gate-logo { display: flex; align-items: center; gap: 10px; font: 700 15px/1 var(--font); letter-spacing: 0.24em; }
.gate-logo svg { width: 22px; height: 22px; color: var(--sel); }
.gate-scene { color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.gate-how { color: var(--text-2); font-size: 13px; line-height: 1.7; }
.gate-go { height: 48px; padding: 0 24px; font-size: 15px; margin-top: 4px; }
.gate-go svg { width: 14px; height: 14px; }

/* ---- 縦向きのスマホ：横にしてもらう（条件は util.js の MQ.portraitPhone と同じ） */
.rotate {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  place-items: center;
  padding: 24px;
  background: var(--bg);
  text-align: center;
}
.rotate-card { max-width: 320px; display: grid; justify-items: center; gap: 12px; color: var(--text-2); font-size: 13.5px; line-height: 1.7; }
.rotate-card p { margin: 0; text-wrap: balance; word-break: auto-phrase; }
.rotate-ico svg { width: 56px; height: 56px; color: var(--text); animation: rotate-hint 900ms var(--ease-out) 400ms both; }
@keyframes rotate-hint { from { transform: rotate(0deg); } to { transform: rotate(-90deg); } }
.rotate-title { color: var(--text); font-size: 17px; font-weight: 650; }
.rotate .btn { height: 48px; padding: 0 22px; font-size: 14.5px; margin-top: 6px; }
.rotate .btn svg { width: 16px; height: 16px; }
/* html.portrait-phone は layout.js が付ける（縦向きのスマホで、回転表示にしていないとき） */
html.portrait-phone .rotate { display: grid; }
html.portrait-phone .app, html.portrait-phone .gate { display: none; } /* 裏の画面が横にはみ出して、案内がずれないように */

/* ---- お知らせ */
.notice {
  position: fixed;
  left: 50%;
  top: max(env(safe-area-inset-top), 10px);
  z-index: 70;
  max-width: min(520px, calc(100vw - 32px));
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(34, 35, 40, 0.97);
  box-shadow: 0 0 0 1px var(--line-2), 0 10px 26px rgba(0, 0, 0, 0.45);
  color: var(--text);
  font-size: 12.5px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -8px);
  transition: opacity 200ms, transform 200ms var(--ease-out);
}
.notice.on { opacity: 1; transform: translate(-50%, 0); }

/* ---- スマホ横向きの画面配置 ------------------------------------------------
   上：2画面（左右）／中：［ボタン］素材［ボタン］／下：タイムライン（横スクロール）
   html.phone-ui（と高さの段 tier-s / tier-l）は layout.js が付ける：スマホを横にしたとき、
   または縦のまま［横向きにする］で画面ごと回したとき（html.rotated） */
html.phone-ui {
  --ruler-h: 20px;
  --v1-top: 22px;
  --v1-h: 36px;
  --a1-top: 60px;
  --a1-h: 22px;
  --m1-top: 86px;
  --m1-h: 14px;
  --lanes-h: 102px;
  --deck-h: 56px;
  --card-h: 44px;
  --mon-head: 18px;
}
html.phone-ui, html.phone-ui body { overflow: hidden; overscroll-behavior: none; }
html.phone-ui .app {
  min-width: 0;
  min-height: 0;
  height: 100vh;
  height: 100dvh;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: minmax(0, 1fr) var(--deck-h) auto;
  grid-template-areas:
    "stage stage stage"
    "dl bin dr"
    "tl tl tl";
  column-gap: 8px;
  padding: 0 max(env(safe-area-inset-right), 10px) 0 max(env(safe-area-inset-left), 10px);
}
html.phone-ui .topbar { display: none; }

/* 2画面：黒帯を切り落とした本当の比率で、横幅いっぱいに */
html.phone-ui .stage { grid-area: stage; padding: 4px 0 2px; gap: 12px; }
html.phone-ui .monitor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: var(--mon-head) auto;
  width: min(calc((100cqw - 12px) / 2), calc((100cqh - var(--mon-head)) * var(--pic-ar)));
}
html.phone-ui .mon-head { grid-area: 1 / 1; height: var(--mon-head); gap: 6px; min-width: 0; overflow: hidden; }
html.phone-ui .mon-foot { grid-area: 1 / 2; height: var(--mon-head); gap: 0; }
html.phone-ui .mon-foot .btn, html.phone-ui .mon-note, html.phone-ui .tc-sep, html.phone-ui .tc-dim { display: none; }
html.phone-ui .screen { grid-area: 2 / 1 / 3 / 3; aspect-ratio: var(--pic-ar); border-radius: 3px; }
html.phone-ui .lane-video { object-fit: cover; }
html.phone-ui .mon-dot { width: 6px; height: 6px; }
html.phone-ui .mon-title { font-size: 11.5px; white-space: nowrap; }
html.phone-ui .mon-tag { font-size: 10.5px; gap: 6px; white-space: nowrap; }
html.phone-ui .aud { font-size: 10px; padding: 0 6px 0 4px; }
html.phone-ui .aud svg { width: 11px; height: 11px; }
html.phone-ui .tc { font-size: 10.5px; color: var(--text-2); }
html.phone-ui .app[data-play="edit"] .mon-l .mon-live,
html.phone-ui .app[data-play="original"] .mon-r .mon-live { display: inline-flex; }
html.phone-ui .screen-empty { font-size: 11.5px; line-height: 1.6; }
html.phone-ui .screen-badge { left: 6px; top: 6px; padding: 2px 6px; font-size: 10.5px; }
html.phone-ui .screen-loading { right: 6px; bottom: 4px; font-size: 10.5px; }
html.phone-ui .bigplay { width: 44px; height: 44px; margin: -22px 0 0 -22px; }
html.phone-ui .bigplay svg { width: 18px; height: 18px; margin-left: 2px; }

/* 素材：横一列。左に試写の ▶、右にサムネイル（秒数は右下に重ねる） */
html.phone-ui .bin { grid-area: bin; display: block; min-width: 0; background: none; border: 0; }
html.phone-ui .app[data-mode="compare"] .bin { display: none; }
html.phone-ui .bin-label { display: none; }
html.phone-ui .bin-strip {
  height: var(--deck-h);
  align-items: center;
  gap: 6px;
  padding: 0 6px;
  scrollbar-width: none; /* スクロールのスナップは付けない（左右のボタンの出入りで位置を補正するため） */
  touch-action: pan-x;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 8px, #000 calc(100% - 12px), transparent);
  mask-image: linear-gradient(90deg, transparent, #000 8px, #000 calc(100% - 12px), transparent);
}
html.phone-ui .bin-strip::-webkit-scrollbar { display: none; }
html.phone-ui .card {
  width: auto;
  height: var(--card-h);
  display: grid;
  grid-template-columns: 36px calc(var(--card-h) * var(--pic-ar));
}
html.phone-ui .card-thumb { grid-area: 1 / 2; height: var(--card-h); border-radius: 0 6px 6px 0; }
html.phone-ui .card-meta { display: contents; }
html.phone-ui .card-play {
  grid-area: 1 / 1;
  width: 36px;
  height: var(--card-h);
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 6px 0 0 6px;
  background: var(--panel-2);
}
html.phone-ui .card-play::before { content: none; }
html.phone-ui .card-play svg { width: 11px; height: 11px; }
html.phone-ui .card-dur {
  grid-area: 1 / 2;
  align-self: end;
  justify-self: end;
  z-index: 2;
  margin: 0 4px 3px 0;
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(10, 10, 12, 0.72);
  color: var(--text);
  font-size: 10.5px;
  pointer-events: none;
}
html.phone-ui .card-dur small { font-size: 9px; }
html.phone-ui .card.is-sel, html.phone-ui .card.is-sel:hover:not(:has(.card-play:hover)) { translate: 0 -3px; } /* タップ後に残る :hover に負けないように */
html.phone-ui .card.is-placed .card-dur { background: transparent; }
html.phone-ui .tag { padding: 1px 5px; font-size: 9.5px; }
html.phone-ui .tag-sel { left: 3px; top: 3px; }

/* ボタン：素材の左右に置く（タイムラインの上の帯は使わない） */
html.phone-ui .timeline, html.phone-ui .tl-bar, html.phone-ui .tl-row { display: contents; }
html.phone-ui .tl-hint {
  grid-area: bin;
  align-self: center;
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  font-size: 11.5px;
}
html.phone-ui .tl-left { grid-area: dl; gap: 6px; }
html.phone-ui .tl-right { grid-area: dr; gap: 6px; }
html.phone-ui .tl-left .btn, html.phone-ui .tl-right .btn { height: 44px; }
html.phone-ui #undoBtn, html.phone-ui #returnBtn, html.phone-ui #cmpToggle, html.phone-ui #cmpRestart {
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  min-width: 48px;
  padding: 0 6px;
  font-size: 9.5px;
}
html.phone-ui #undoBtn svg, html.phone-ui #returnBtn svg, html.phone-ui #cmpToggle svg, html.phone-ui #cmpRestart svg { width: 16px; height: 16px; }
html.phone-ui .selchip { height: 44px; gap: 6px; padding: 0 4px 0 0; }
html.phone-ui .selchip-text { display: none; }
html.phone-ui .selchip-thumb { width: calc(28px * var(--pic-ar)); height: 28px; }
html.phone-ui .selchip .btn { height: 36px; }
html.phone-ui .remain { height: 44px; padding: 0 10px; font-size: 11px; }
html.phone-ui .rm-pre { display: none; }
html.phone-ui .btn-check { padding: 0 14px; }
html.phone-ui .cmp-track { grid-area: bin; width: auto; height: 44px; align-self: center; }
html.phone-ui .cmp-count { font-size: 11.5px; white-space: nowrap; }
html.phone-ui #cmpExit { padding: 0 12px; }

/* タイムライン：見出しは V1/A1/M1 だけ */
html.phone-ui .tl-body { grid-area: tl; grid-template-columns: 30px minmax(0, 1fr); gap: 0 6px; padding-bottom: max(env(safe-area-inset-bottom), 4px); }
html.phone-ui .th { justify-content: center; padding-left: 0; }
html.phone-ui .th span, html.phone-ui .th .lock { display: none; }
html.phone-ui .th b { padding: 2px 3px; font-size: 9.5px; }
html.phone-ui .tick-label { font-size: 9px; top: 2px; }
html.phone-ui .music-label { font-size: 9.5px; padding: 0 5px; }
html.phone-ui .end-mark span { font-size: 9px; }
html.phone-ui .empty-hint { font-size: 12px; }
html.phone-ui .ghost span { top: 4px; left: 6px; font-size: 10px; }

/* 背の低いスマホ（iPhone SE の横向きなど） */
html.phone-ui.tier-s {
  --ruler-h: 18px;
  --v1-top: 20px;
  --v1-h: 32px;
  --a1-top: 54px;
  --a1-h: 20px;
  --m1-top: 77px;
  --m1-h: 12px;
  --lanes-h: 90px;
  --deck-h: 52px;
  --card-h: 42px;
  --mon-head: 16px;
}

/* 背の高いスマホ（ホーム画面から開いたとき・Android の全画面など） */
html.phone-ui.tier-l {
  --ruler-h: 24px;
  --v1-top: 26px;
  --v1-h: 42px;
  --a1-top: 70px;
  --a1-h: 26px;
  --m1-top: 98px;
  --m1-h: 16px;
  --lanes-h: 116px;
  --deck-h: 62px;
  --card-h: 48px;
  --mon-head: 20px;
}

/* ---- 縦のまま［横向きにする］：画面ごと 90° 回して表示する（iPhone は画面の向きを変えられないため）
   回すのは .root（ゲーム本体・最初の画面・お知らせ・飛ぶサムネイル）。座標の変換は layout.js */
.root { display: contents; }
html.rotated .root {
  display: block;
  position: fixed;
  left: 0;
  top: 0;
  width: 100vh;
  width: 100dvh;
  height: 100vw;
  overflow: hidden;
  transform-origin: 0 0;
  transform: rotate(90deg) translateY(-100%);
}
html.rotated .app {
  height: 100%;
  /* 回した画面の左右＝端末の上下（ノッチ・ホームバー側） */
  padding: 0 max(env(safe-area-inset-bottom), 10px) 0 max(env(safe-area-inset-top), 10px);
}
html.rotated .tl-body { padding-bottom: 4px; }
html.rotated .notice { top: 10px; }
/* 回した表示では指の向きと画面の向きがずれるので、横スクロールの向きの制限は外す（ドラッグの判定は drag.js） */
html.rotated .lanes.scroll { touch-action: manipulation; }

/* ---- 素材をドラッグしているとき */
.drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 55;
  border-radius: 4px;
  background: #000 center / cover no-repeat;
  outline: 1.5px solid var(--sel);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.55);
  opacity: 0.94;
  pointer-events: none;
  will-change: transform;
}
html.dragging, html.dragging * { cursor: grabbing !important; -webkit-user-select: none; user-select: none; }

/* 画面の種類が決まるまでは出さない（PC 用の配置が一瞬見えないように） */
html:not(.layout-ready) .app { visibility: hidden; }

/* ---- 擬似全画面（iPhone のブラウザ。html.pfs / pfs-need は layout.js）
   ページを少し縦に長くしておき、ひと撫でスクロールしてもらうとブラウザのバーが隠れる。
   ゲームの画面は position: fixed で見えている範囲いっぱい（100dvh はバーが隠れると広がる） */
html.pfs, html.pfs body { height: auto; overflow-x: hidden; overflow-y: auto; overscroll-behavior: none; }
html.pfs body { min-height: 100%; }
html.pfs body::after { content: ""; display: block; height: calc(100vh + 320px); }
html.pfs:not(.rotated) .app {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  touch-action: pan-x; /* 遊んでいる間の縦のスワイプでページが動いて、バーが戻ってこないように */
}
.pfs-hint {
  position: fixed;
  inset: 0;
  z-index: 58;
  display: none;
  place-items: center;
  background: rgba(12, 13, 15, 0.8);
  touch-action: auto; /* ここでのスワイプでページをスクロールさせる */
}
html.pfs-need .pfs-hint { display: grid; }
html.portrait-phone .pfs-hint { display: none; }
.pfs-card { display: grid; justify-items: center; gap: 10px; text-align: center; }
.pfs-card p { margin: 0; }
.pfs-arrow svg { width: 44px; height: 44px; color: var(--sel); animation: pfs-swipe 1400ms var(--ease-out) infinite; }
@keyframes pfs-swipe { 0% { transform: translateY(18px); opacity: 0; } 30% { opacity: 1; } 80% { transform: translateY(-14px); opacity: 0; } 100% { opacity: 0; } }
.pfs-text { color: var(--text); font-size: 15px; font-weight: 650; }
.pfs-dir-left { display: none; }
/* 縦のまま回して表示しているとき：ページのスクロールは端末の上方向＝回した画面では左 */
html.rotated .pfs-dir-up { display: none; }
html.rotated .pfs-dir-left { display: inline; }
html.rotated .pfs-arrow { transform: rotate(-90deg); }
.pfs-card .btn { height: 40px; margin-top: 4px; color: var(--text-2); }

/* ================================================================ 塊を並べ替える遊び方
   オリジナルは答え合わせまで出さない：編集中は自分の画面だけを大きく */
.app[data-mode="edit"] .mon-r { display: none; }
.app[data-mode="edit"] .monitor { width: min(100cqw, calc((100cqh - 70px) * 16 / 9)); }
html.phone-ui .app[data-mode="edit"] .monitor { width: min(100cqw, calc((100cqh - var(--mon-head)) * var(--pic-ar))); }

/* 塊：中のカットのサムネイルを長さの割合で並べる（細い線がカットの切れ目） */
.clip-v { display: flex; overflow: hidden; }
.clip-v i { flex: 0 1 0; min-width: 0; background: #0b0b0c center / cover no-repeat; box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.6); }
.clip-v i:last-child { box-shadow: none; }

/* 塊をつかんで動かす */
.clip { touch-action: none; translate: calc(var(--nx) + var(--dx, 0px)) var(--ly); }
.clip.dragging { --ly: -8px; z-index: 7; transition: none; cursor: grabbing; }
.clip.dragging .clip-v, .clip.dragging .clip-a { border-color: var(--sel); box-shadow: 0 0 0 1px var(--sel), 0 14px 26px rgba(0, 0, 0, 0.6); }
.clip.no-slide, .clip.no-slide * { transition: none !important; }

/* 塊のつなぎ目：そこだけ再生するボタン（ルーラー帯） */
.seams { position: absolute; left: 0; top: 0; width: var(--canvas-w, 100%); height: var(--ruler-h); pointer-events: none; z-index: 5; }
.seam {
  position: absolute;
  top: 0;
  width: 26px;
  height: var(--ruler-h);
  margin-left: -13px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-2);
  display: grid;
  place-items: center;
  pointer-events: auto;
  cursor: pointer;
}
.seam::before { content: ""; position: absolute; inset: -6px -8px 0; } /* 指で押しやすく（下の塊には重ねない） */
.seam i { width: 18px; height: 18px; display: grid; place-items: center; border-radius: 50%; background: var(--panel-2); box-shadow: 0 0 0 1px var(--line-2); }
.seam svg { width: 8px; height: 8px; margin-left: 1px; }
@media (hover: hover) { .seam:hover i { background: var(--v1-bg); color: #fff; box-shadow: 0 0 0 1px var(--v1); } }
.lanes.placing .seams, .app[data-mode="compare"] .seams { display: none; }
html.phone-ui .seam i { width: 16px; height: 16px; }

/* 塊が細くなりすぎる画面だけ横スクロール */
.lanes.scroll { overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scrollbar-width: thin; touch-action: pan-x; }

/* ================================================================ 答え合わせの演出（進みバー）
   1組見終わるごとに：当たり＝金色＋光が横切る＋✓ が飛び出す＋光の粒／はずれ＝赤みの灰色＋✕。
   続けて当たると、区切りどうしが金の帯でつながる（main.js の reveal） */
.cmp-seg { overflow: visible; }
.cmp-seg i { border-radius: 2px; }
.cmp-mark {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 4px);
  z-index: 1;
  width: 16px;
  height: 16px;
  margin-left: -8px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 200ms, transform 200ms var(--ease-out);
  pointer-events: none;
}
.cmp-mark svg { width: 10px; height: 10px; }
.cmp-seg.hit { background: #7a5c1f; }
.cmp-seg.hit i { background: var(--sel); }
.cmp-seg.hit:not(.cur) i { width: 100% !important; }
.cmp-seg.hit .cmp-mark { opacity: 1; transform: none; background: var(--sel); color: var(--sel-ink); }
.cmp-seg.miss { background: #4a3536; }
.cmp-seg.miss i { background: #6a4647; }
.cmp-seg.miss:not(.cur) i { width: 100% !important; }
.cmp-seg.miss .cmp-mark { opacity: 0.85; transform: none; background: #33292a; color: #d8a5a5; box-shadow: inset 0 0 0 1px #6a4647; }

/* 続けて当たり：前の区切りと金の帯でつなぐ */
.cmp-seg.link::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  right: 100%;
  width: 3px;
  background: var(--sel);
  transform-origin: right;
}
.cmp-seg.pop.link::before { animation: link-grow 320ms var(--ease-out) both; }
.cmp-seg.hit.link, .cmp-seg.hit.link i { border-top-left-radius: 0; border-bottom-left-radius: 0; }
@keyframes link-grow { from { transform: scaleX(0); } to { transform: none; } }

/* 当たった瞬間 */
.cmp-seg.pop i { animation: seg-pop 420ms var(--ease-snap); }
@keyframes seg-pop { 0% { transform: scaleY(1); } 40% { transform: scaleY(1.7); } 100% { transform: scaleY(1); } }
.cmp-seg.pop::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, rgba(255, 244, 210, 0.95), transparent) no-repeat;
  background-size: 45% 100%;
  animation: seg-sweep 560ms ease-out both;
  pointer-events: none;
}
@keyframes seg-sweep { from { background-position: -90% 0; } to { background-position: 190% 0; } }
.cmp-seg.pop .cmp-mark { animation: mark-pop 460ms var(--ease-snap); }
@keyframes mark-pop {
  0% { transform: translateY(6px) scale(0.3); opacity: 0; }
  60% { transform: translateY(-3px) scale(1.25); opacity: 1; }
  100% { transform: none; opacity: 1; }
}
.spark {
  position: absolute;
  left: var(--sx);
  top: 50%;
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: #ffd98a;
  box-shadow: 0 0 6px rgba(255, 200, 90, 0.9);
  pointer-events: none;
  animation: spark 650ms ease-out both;
}
@keyframes spark { from { transform: translate(0, 0) scale(1); opacity: 1; } to { transform: translate(var(--dx), var(--dy)) scale(0.2); opacity: 0; } }

/* ================================================================ リザルト */
.result {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 10, 12, 0.62);
}
.result-card {
  position: relative;
  width: min(640px, 100%);
  max-height: 100%;
  overflow: auto;
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 22px 24px 18px;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 0 0 1px var(--line-2), 0 24px 60px rgba(0, 0, 0, 0.55);
  text-align: center;
}
.result-card.in { animation: result-in 380ms var(--ease-snap); }
@keyframes result-in { from { opacity: 0; transform: translateY(10px) scale(0.96); } to { opacity: 1; transform: none; } }
.result-card p { margin: 0; }
.result-label { color: var(--text-2); font-size: 15px; font-weight: 650; letter-spacing: 0.04em; }
.result-score { font: 700 52px/1 var(--font); font-variant-numeric: tabular-nums; color: var(--text); }
.result-score span { margin-left: 4px; color: var(--text-3); font-size: 22px; font-weight: 600; }
.result-sub { color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; }

/* サムネイル：自分の並び → 正しい並びへ滑って入れ替わる（--home＝自分の並びでの位置、--i＝表示する位置） */
.result-strip { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 6px; width: 100%; margin-top: 8px; }
.rt {
  position: relative;
  aspect-ratio: var(--pic-ar);
  transform: translateX(calc((var(--i) - var(--home)) * (100% + 6px)));
  transition: transform 640ms var(--ease-out);
  transition-delay: calc(var(--home) * 45ms);
}
.rt i { position: absolute; inset: 0; border-radius: 4px; background: #0b0b0c center / cover no-repeat; box-shadow: 0 0 0 1px var(--line-2); }
.rt.ok i { box-shadow: 0 0 0 1.5px var(--sel); }
.rt b { position: absolute; right: -5px; top: -7px; width: 18px; height: 18px; display: grid; place-items: center; border-radius: 50%; }
.rt b svg { width: 11px; height: 11px; }
.rt.ok b { background: var(--sel); color: var(--sel-ink); }
.rt.ng b { background: #4a3434; color: #e0b0b0; box-shadow: 0 0 0 1px #6b4545; }
.result-toggle { padding: 4px 8px; border: 0; background: transparent; color: var(--text-3); font: inherit; font-size: 12px; cursor: pointer; }
.result-toggle b { color: var(--text); font-weight: 650; }
.result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 4px; }
.result-actions .btn { height: 40px; padding: 0 14px; }

/* 全部一致：金色の輪郭と、光がカードを一周する */
.result-card.perfect { box-shadow: 0 0 0 1.5px var(--sel), 0 24px 60px rgba(0, 0, 0, 0.55), 0 0 44px rgba(242, 181, 68, 0.22); }
.result-card.perfect .result-label, .result-card.perfect .result-score b { color: var(--sel); }
.result-card.perfect::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(105deg, transparent 38%, rgba(255, 226, 150, 0.2) 50%, transparent 62%) no-repeat;
  background-size: 250% 100%;
  animation: card-shine 1.6s ease-out 0.25s 2 both;
  pointer-events: none;
}
@keyframes card-shine { from { background-position: 130% 0; } to { background-position: -30% 0; } }

html.phone-ui .result { padding: 8px; }
/* iPhone の擬似全画面：結果の上でのスワイプでページが動いて、ブラウザのバーが戻ってこないように */
html.pfs:not(.rotated) .result { touch-action: pan-x; }
html.pfs:not(.rotated) .result-card { touch-action: pan-y; }
html.phone-ui .result-card { width: min(580px, 100%); gap: 4px; padding: 12px 16px; }
html.phone-ui .result-label { font-size: 13px; }
html.phone-ui .result-score { font-size: 38px; }
html.phone-ui .result-score span { font-size: 18px; }
html.phone-ui .result-sub { font-size: 11px; }
html.phone-ui .result-strip { margin-top: 6px; }

@media (prefers-reduced-motion: reduce) {
  .cmp-seg.pop i, .cmp-seg.pop::after, .cmp-seg.pop .cmp-mark, .cmp-seg.link::before, .spark,
  .result-card.in, .result-card.perfect::after { animation: none !important; }
  .rt, .cmp-mark { transition: none; }
}

/* 最初の画面：素材の準備の進み（準備できたら琥珀に） */
.gate-load { margin: 0; color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.gate-load.done { color: var(--sel); }
