:root {
  --bg: #03040a; --panel: rgba(10, 12, 20, .86); --line: rgba(255, 255, 255, .09);
  --text: #e8ecf5; --dim: #8a91a6; --accent: #35e0ff; --accent2: #ff3df2;
}
* { box-sizing: border-box }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  overflow: hidden; user-select: none; -webkit-user-select: none;
}

/* 3D表示：YouTube用のCSS3Dレイヤーを後ろ、WebGLを前に重ねる */
#view { position: fixed; inset: 0; background: #000 }
#view canvas { position: absolute; inset: 0; z-index: 1; display: block }
#css3d { position: absolute !important; inset: 0; z-index: 0; pointer-events: none }
#ytWrap { width: 1280px; height: 576px; overflow: hidden; background: #000; position: relative }
#ytWrap iframe { position: absolute; left: 0; top: -72px; width: 1280px; height: 720px; border: 0; pointer-events: none }

.overlay-flash { position: fixed; inset: 0; opacity: 0; pointer-events: none; z-index: 2 }
#flash { background: #fff }
#blind { background: radial-gradient(ellipse at 50% 20%, #fff6e0 0%, #ffcf80 45%, rgba(255, 160, 60, 0) 100%) }

/* top bar */
#top {
  position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 6px; padding: 8px 12px;
  background: linear-gradient(rgba(0, 0, 0, .85), rgba(0, 0, 0, 0)); flex-wrap: wrap; z-index: 5;
}
.logo {
  font-weight: 900; letter-spacing: .14em; font-size: 14px; white-space: nowrap; margin-right: 6px;
  background: linear-gradient(90deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent;
}
button, .btnlike {
  font: inherit; color: var(--text); background: rgba(255, 255, 255, .06); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 9px; cursor: pointer; font-size: 12px; transition: background .12s, box-shadow .12s;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button:hover, .btnlike:hover { background: rgba(255, 255, 255, .13) }
button.on, .btnlike.on {
  background: linear-gradient(135deg, rgba(53, 224, 255, .38), rgba(255, 61, 242, .3));
  border-color: rgba(53, 224, 255, .75); box-shadow: 0 0 12px rgba(53, 224, 255, .35);
}
button.hot {
  background: linear-gradient(135deg, rgba(255, 120, 40, .5), rgba(255, 40, 80, .4));
  border-color: rgba(255, 140, 60, .9); box-shadow: 0 0 14px rgba(255, 120, 40, .5);
}
kbd {
  font-family: ui-monospace, Menlo, monospace; font-size: 10px; color: var(--dim); border: 1px solid var(--line);
  border-radius: 4px; padding: 0 4px; background: rgba(0, 0, 0, .3);
}
input[type=text] {
  font: inherit; font-size: 12px; color: var(--text); background: rgba(0, 0, 0, .35); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; flex: 1; min-width: 0; outline: none; user-select: text; -webkit-user-select: text;
}
input[type=text]:focus { border-color: var(--accent) }
#track { font-size: 12px; color: var(--dim); max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
#seek { width: 120px }
#time { font-size: 11px; color: var(--dim); font-variant-numeric: tabular-nums; min-width: 78px }
.meter { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--dim) }
#beatLamp { width: 12px; height: 12px; border-radius: 50%; background: #222; box-shadow: 0 0 0 1px var(--line) }
#bpm { font-variant-numeric: tabular-nums; color: var(--text); min-width: 28px; display: inline-block }
#level { width: 40px; height: 6px; border-radius: 3px; background: #1a1d28; overflow: hidden }
#level > div { height: 100%; width: 0; background: linear-gradient(90deg, #35e0ff, #ff3df2) }
.spacer { flex: 1 }
input[type=range] { accent-color: var(--accent); height: 16px }

/* deck */
#deck {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; flex-wrap: wrap; align-items: stretch; gap: 8px; padding: 8px;
  background: var(--panel); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); max-height: 44vh; overflow: auto; z-index: 5; transition: transform .25s;
}
#deck.hidden { transform: translateY(105%) }
/* ブロックの幅は --grow（卓の配置で変更）。狭い画面では自動で折り返す */
#deck > .sec { flex: var(--grow, 1) 1 250px }
@media (max-width: 640px) { #seek { width: 110px } }
.sec { border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: rgba(255, 255, 255, .02); min-width: 0 }
.sec h3 { margin: 0 0 6px; font-size: 11px; letter-spacing: .16em; color: var(--dim); display: flex; align-items: center; gap: 6px; flex-wrap: wrap }
.sec h3 .t { color: var(--text); font-weight: 800 }
.sec h3 .grow { flex: 1 }
.sec h3 .src { letter-spacing: 0; font-size: 10px; color: var(--accent) }
.row { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 6px }
.label { font-size: 10px; color: var(--dim); margin: 2px 0 4px; letter-spacing: .08em }
.sw { width: 30px; height: 24px; padding: 0; border-radius: 6px; justify-content: center; position: relative }
.sw i { position: absolute; inset: 4px; border-radius: 4px }
.sw kbd { position: absolute; bottom: -1px; right: -1px; font-size: 8px; padding: 0 2px; border: none; background: rgba(0, 0, 0, .6) }
.sw.on { box-shadow: 0 0 0 2px #fff, 0 0 12px rgba(255, 255, 255, .5) }
.fxgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-bottom: 6px }
.fxgrid button { flex-direction: column; padding: 8px 4px; gap: 2px; font-size: 12px; min-width: 0; white-space: normal; text-align: center }
.fxgrid button .em { font-size: 18px; line-height: 1 }
.slider { display: grid; grid-template-columns: 76px 1fr; align-items: center; gap: 6px; font-size: 11px; color: var(--dim); margin-bottom: 3px }
.slider input { width: 100% }

/* overlays */
.modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, .6); z-index: 20; padding: 16px }
.modal.hide { display: none }
.card {
  max-width: 640px; width: 100%; background: rgba(14, 16, 26, .95); border: 1px solid var(--line); border-radius: 16px;
  padding: 24px; box-shadow: 0 20px 80px rgba(0, 0, 0, .6); max-height: 90vh; overflow: auto;
}
.card h1 {
  margin: 0 0 4px; font-size: 30px; letter-spacing: .08em;
  background: linear-gradient(90deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.card p { color: var(--dim); font-size: 13px; line-height: 1.7 }
.card p b { color: var(--text) }
.card .big { font-size: 15px; padding: 12px 18px; border-radius: 12px }
.card .actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0 }
.ytstart { display: flex; gap: 10px; margin: 0 0 6px }
.ytstart input { font-size: 14px; padding: 10px 12px }
button:disabled { opacity: .35; cursor: not-allowed; box-shadow: none }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 12px; color: var(--dim) }
.keys b { color: var(--text); font-weight: 600; font-family: ui-monospace, Menlo, monospace }
#drop {
  position: fixed; inset: 12px; border: 3px dashed var(--accent); border-radius: 20px; display: none; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 800; background: rgba(0, 20, 30, .6); z-index: 30; pointer-events: none;
}
#drop.show { display: flex }
#toast {
  position: fixed; top: 56px; left: 50%; transform: translateX(-50%); background: rgba(0, 0, 0, .75); border: 1px solid var(--line);
  padding: 6px 14px; border-radius: 999px; font-size: 13px; opacity: 0; transition: opacity .3s; z-index: 10; pointer-events: none;
}

/* 小さめのパターンボタン */
button.sm { padding: 4px 7px; font-size: 11px; gap: 4px }
button.sm kbd { font-size: 9px; padding: 0 3px }
button.custom { border-style: dashed }

/* シーンメモリー */
.slot { width: 30px; justify-content: center; padding: 5px 0; position: relative }
.slot.filled::after { content: ''; position: absolute; top: 3px; right: 3px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent) }
button.saving { background: rgba(255, 170, 0, .3); border-color: #ffaa00; box-shadow: 0 0 10px rgba(255, 170, 0, .4) }

/* カスタム編集パネル */
#editor {
  position: fixed; top: 56px; right: 12px; width: 320px; bottom: calc(var(--dock-bottom, 44vh) + 10px); overflow: auto; z-index: 6;
  background: rgba(12, 14, 24, .92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}
#editor.hide { display: none }
.ed-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; font-size: 13px }
.ed-head .grow, .ed-sec h4 .grow { flex: 1 }
.ed-sec { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 6px }
.ed-sec h4 { margin: 0 0 6px; font-size: 11px; letter-spacing: .14em; display: flex; align-items: center; gap: 6px }
.ed-sec h4 button { font-size: 10px; padding: 3px 7px; letter-spacing: 0 }
.ed-opts { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px }
.ed-opts button { padding: 3px 7px; font-size: 11px }
.ed-note { font-size: 10px; color: var(--dim); line-height: 1.6; margin: 8px 0 0 }
@media (max-width: 640px) { #editor { left: 12px; right: 12px; width: auto } }

/* 保存したカスタム */
.preset-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px }
.preset-list .item { display: flex; gap: 4px }
.preset-list .item button:first-child { flex: 1; justify-content: flex-start; overflow: hidden; text-overflow: ellipsis }
.preset-list .empty { font-size: 11px; color: var(--dim) }

/* タイマー：選んだパターンのボタンに残り時間のバー */
#deck button { position: relative; overflow: hidden }
button.shooting::after {
  content: ''; position: absolute; left: 0; bottom: 0; height: 3px; width: calc(var(--p, 0) * 100%);
  background: linear-gradient(90deg, #ffaa00, #ff3df2); box-shadow: 0 0 6px #ffaa00;
}
.shot-row.off { display: none }
.shot-row { grid-template-columns: 110px 1fr }
.shot-row .val { color: var(--text); font-variant-numeric: tabular-nums }

/* チュートリアル */
#tutLayer.hide { display: none }
#tutBlock { position: fixed; inset: 0; z-index: 40 } /* 説明中は後ろを触れないように */
#tutHole {
  position: fixed; z-index: 41; pointer-events: none; border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .62), 0 0 0 2px var(--accent), 0 0 24px rgba(53, 224, 255, .6);
  transition: left .25s, top .25s, width .25s, height .25s;
}
#tutBox {
  position: fixed; z-index: 42; width: min(380px, calc(100vw - 24px)); padding: 14px 16px 12px;
  background: rgba(14, 16, 28, .97); border: 1px solid rgba(53, 224, 255, .5); border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .6); transition: left .25s, top .25s;
}
#tutBox h3 { margin: 2px 0 6px; font-size: 16px }
#tutBox p { margin: 0 0 12px; font-size: 13px; line-height: 1.7; color: #cdd3e3 }
#tutBox b { color: var(--accent) }
.tut-count { font-size: 10px; color: var(--dim); letter-spacing: .1em }
.tut-btns { display: flex; gap: 6px; align-items: center }
.tut-btns .grow { flex: 1 }

/* どちらの音を使うかの選択 */
.choice { display: flex; flex-direction: column; gap: 10px; margin: 14px 0 }
.choice button { justify-content: flex-start; text-align: left; white-space: normal; gap: 12px; line-height: 1.5 }
.choice .em { font-size: 26px }
.choice small { color: var(--dim); font-size: 11px }

/* タイムライン（操作パネルのすぐ上） */
#timeline {
  position: fixed; left: 0; right: 0; z-index: 5; background: rgba(8, 10, 18, .95);
  border-top: 1px solid rgba(53, 224, 255, .35); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
#timeline.hide { display: none }
.tl-head { display: flex; align-items: center; gap: 6px; padding: 5px 10px; font-size: 12px; flex-wrap: wrap; border-bottom: 1px solid var(--line) }
.tl-head button { padding: 3px 8px; font-size: 11px }
.tl-head .grow { flex: 1 }
.tl-time { font-variant-numeric: tabular-nums; color: var(--accent); min-width: 110px }
.tl-song { color: var(--dim); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.tl-info { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 11px }
.tl-info b { color: #ffaa00 }
.tl-hint { color: var(--dim) }
.tl-chips { display: inline-flex; gap: 3px; flex-wrap: wrap }
.tl-dur { display: inline-flex; align-items: center; gap: 4px; color: var(--dim) }
.tl-dur input { width: 52px; flex: none; padding: 3px 6px; font-size: 11px }
.tl-body { display: flex }
.tl-labels { width: 116px; flex: none; border-right: 1px solid var(--line) }
.tl-ruler-label { height: 22px; font-size: 10px; color: var(--dim); padding: 4px 8px; background: #0b0d16 }
.tl-label { height: 30px; display: flex; align-items: center; justify-content: space-between; padding: 0 6px 0 8px; font-size: 11px; font-weight: 700 }
.tl-label:nth-child(odd) { background: #10131f }
.tl-label button { padding: 1px 7px; font-size: 11px; color: #ffaa00 }
.tl-canvas { flex: 1; min-width: 0; height: 112px; touch-action: none }
.tl-canvas canvas { display: block }

/* 全消灯ボタン */
button.alloff { border-color: rgba(255, 80, 80, .6); color: #ffb3b3 }
button.alloff:hover { background: rgba(255, 60, 60, .25) }

/* 卓の配置の編集 */
#deckEditBar { display: none; flex-basis: 100%; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; padding: 4px 6px;
  border: 1px dashed rgba(53, 224, 255, .5); border-radius: 8px; background: rgba(53, 224, 255, .06) }
#deck.editing #deckEditBar { display: flex }
#deckEditBar .grow { flex: 1 }
#deckEditBar button { padding: 4px 9px; font-size: 11px }
#deckHiddenList { display: inline-flex; gap: 4px; flex-wrap: wrap }
.hint { color: var(--dim); font-size: 11px }
.sec-handle { display: none; cursor: grab; color: var(--accent); font-size: 14px; letter-spacing: 0; touch-action: none; padding: 0 2px }
.sec-ctrl { display: none; align-items: center; gap: 4px; flex-wrap: wrap; margin: -2px 0 8px }
.sec-ctrl button { padding: 2px 7px; font-size: 10px }
#deck.editing .sec-handle { display: inline }
#deck.editing .sec-ctrl { display: flex }
#deck.editing > .sec { outline: 1px dashed rgba(53, 224, 255, .45); outline-offset: -1px }
#deck > .sec.dragging { opacity: .45; outline: 2px solid var(--accent) }
#deck > .sec.sec-hidden { display: none }
