/* app.css — W1 の画面。色は colors.json から app.js が --ui-* に入れる。幅が 640px 未満ならスマホの並び */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--ui-bg); color: var(--ui-fg); font: 14px/1.4 system-ui, sans-serif; display: flex; flex-direction: column; overflow: hidden; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
.grow { flex: 1; }
.dim { color: var(--ui-dim); }

/* ---- 上の帯: 再生のボタン・パート・曲の情報 ---- */
#top { position: relative; background: var(--ui-panel); border-bottom: 1px solid var(--ui-line); display: flex; align-items: center; gap: 6px 10px; padding: 6px 10px; flex: none; }
.transport { display: flex; align-items: center; gap: 6px; flex: none; }
.tb { border: 1px solid var(--ui-line); background: var(--ui-bg); border-radius: 6px; height: 32px; padding: 0 12px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.tb .ic { font-size: 13px; }
.tb:disabled { opacity: .35; }
.tb:not(:disabled):hover, .icon:hover { border-color: var(--ui-accent); }
#time { color: var(--ui-dim); font-variant-numeric: tabular-nums; padding: 0 4px; white-space: nowrap; min-width: 6.5em; }
.icon { width: 32px; height: 32px; border: 1px solid var(--ui-line); background: var(--ui-bg); border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.tools { display: flex; gap: 6px; flex: none; }

/* パート 1 つ: 上から 9 段のメーター（閉じているときは一番下の段だけ）・鳴らすかの四角・名前 */
#parts { display: flex; align-items: flex-end; gap: 4px; flex: none; }
#parts .gap { width: 8px; }
.pt { display: flex; flex-direction: column; align-items: center; gap: 3px; width: 24px; border: none; background: none; padding: 0; }
.pt .m { display: flex; flex-direction: column-reverse; gap: 1px; }
.pt .m i { width: 14px; height: 4px; background: var(--ui-line); border-radius: 1px; }
.pt .m i.on { background: var(--ui-meter, var(--ui-accent)); }
.pt .m i:not(:first-child) { display: none; }
body.top-open .pt .m i:not(:first-child) { display: block; }
.pt .sw { display: block; width: 13px; height: 13px; border: 1.5px solid var(--ui-fg); border-radius: 2px; background: var(--ui-fg); }
.pt.muted .sw { background: transparent; }
.pt b { font: 600 13px/16px ui-monospace, monospace; padding: 0 3px 1px; }
.pt.here b { box-shadow: inset 0 -2px 0 var(--ui-accent); }
.pt.none { cursor: default; }
.pt .sw-hit { border: none; background: none; padding: 5px 6px; margin: -5px -6px; line-height: 0; }
.pt.none .sw-hit, .pt.pcm .sw-hit { visibility: hidden; }
.pt.none b, .pt.none .m { opacity: .3; }

#song { min-width: 0; flex: 1; text-align: right; line-height: 1.35; white-space: nowrap; overflow: hidden; }
#song .tt { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
#song .by { color: var(--ui-dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
#song .by span + span { margin-left: 10px; }
#song .by em { font-style: normal; opacity: .75; margin-right: 4px; }

/* メニュー（⋯） */
#menu { position: absolute; right: 10px; top: 100%; margin-top: 4px; z-index: 5; background: var(--ui-panel); border: 1px solid var(--ui-line); border-radius: 8px;
	box-shadow: 0 6px 20px rgba(0,0,0,.18); padding: 6px; display: flex; flex-direction: column; gap: 2px; min-width: 240px; }
#menu > a { padding: 7px 10px; border-radius: 5px; color: var(--ui-dim); text-decoration: none; font-size: 13px; }
#menu > a:hover { background: var(--ui-activeLine); }
#menu > button, #menu > label { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 10px; border-radius: 5px; border: none; background: none; text-align: left; }
#menu > button:hover, #menu > label:hover { background: var(--ui-activeLine); }
#menu select { border: 1px solid var(--ui-line); background: var(--ui-bg); border-radius: 4px; padding: 2px 4px; }
#menu .check { justify-content: flex-start; }

/* ---- 本文（CodeMirror）。1 行は最長 80 桁、画面からあふれたら折り返す ---- */
#ed { flex: 1; min-height: 0; display: flex; background: var(--ui-panel); }
#ed .cm-editor { flex: 1; min-width: 0; background: var(--ui-panel); color: var(--ui-fg); }
#ed .cm-editor.cm-focused { outline: none; }
#ed .cm-scroller { font: 16px/1.5 ui-monospace, "Noto Sans Mono CJK JP", monospace; }
#ed .cm-content { max-width: calc(80ch + 12px); caret-color: var(--ui-cursor); }
#ed .cm-gutters { background: var(--ui-gutter); color: var(--ui-dim); border-right: 1px solid var(--ui-line); }
#ed .cm-activeLine, #ed .cm-activeLineGutter { background: var(--ui-activeLine); }
#ed .cm-cursor { border-left-color: var(--ui-cursor); }
#ed .cm-selectionBackground, #ed .cm-focused .cm-selectionBackground { background: var(--ui-selection) !important; }
#ed .cm-selectionLayer { z-index: 1 !important; pointer-events: none; mix-blend-mode: var(--ui-selectionBlend); }
/* 小節の塗り（試作と同じ。空白なしで隣の小節と接する端は 1 ドット空ける）、小節線をまたぐ音は薄く */
#ed .bar { background-image: linear-gradient(var(--ui-bar), var(--ui-bar)); background-repeat: no-repeat; background-size: 100% 100%; }
#ed .bar-start { background-position: 1px 0; background-size: calc(100% - 1px) 100%; }
#ed .bar-end { background-size: calc(100% - 1px) 100%; }
#ed .bar-start.bar-end { background-size: calc(100% - 2px) 100%; }
#ed .bar-cross { background-color: var(--ui-barCross); }
/* 鳴っている小節は下線、鳴っている音符は塗る */
#ed .cm-playing-bar, #ed .cm-playing { background-image: linear-gradient(var(--ui-playingBar), var(--ui-playingBar)); background-repeat: no-repeat; background-position: 0 100%; background-size: 100% 2px; }
#ed .cm-playing { background-color: var(--ui-playing); }
#ed .cm-bars .cm-gutterElement { color: var(--ui-dim); font-size: 12px; padding: 0 6px 0 4px; }
#ed .cm-bars .bn { display: inline-grid; grid-template-columns: 3ch 1ch 3ch; font-variant-numeric: tabular-nums; }
#ed .cm-bars .lo { text-align: right; } #ed .cm-bars .hy { text-align: center; } #ed .cm-bars .hi { text-align: left; }
#ed .cm-lineNumbers .cm-gutterElement { color: var(--ui-dim); font-size: 12px; padding: 0 4px 0 8px; opacity: .7; }
#ed .cm-voice-sel { outline: 1.5px solid var(--ui-accent); border-radius: 2px; }
#ed .cm-lintRange-warning { background-image: none; text-decoration: underline wavy var(--ui-warn); text-underline-offset: 3px; }
#ed .cm-lintRange-error { background-image: none; text-decoration: underline wavy var(--ui-err); text-underline-offset: 3px; }
#ed .cm-lintRange-info { background-image: none; text-decoration: underline dotted var(--ui-accent); text-underline-offset: 3px; }

/* ---- 詳細情報（キャレットの所の意味） ---- */
#det { flex: none; background: var(--ui-panel); border-top: 1px solid var(--ui-line); }
#dh { display: flex; align-items: center; gap: 10px; padding: 0 10px; height: 30px; background: var(--ui-gutter); font: 13px ui-monospace, "Noto Sans Mono CJK JP", monospace; white-space: nowrap; overflow: hidden; }
#dh-text { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
#dh .d { color: var(--ui-dim); font-family: system-ui, sans-serif; }
#dh .sel { color: var(--ui-accent); }
#dh .err { color: var(--ui-err); font-family: system-ui, sans-serif; }
#dh .car { color: var(--ui-carrier); } #dh .mod { color: var(--ui-modulator); }
#caret { color: var(--ui-dim); font-variant-numeric: tabular-nums; flex: none; font-family: system-ui, sans-serif; font-size: 12px; }
#db { padding: 6px 12px 10px; font-size: 13px; line-height: 1.6; height: 132px; overflow: auto; }
#db .row { max-width: 920px; }
#db .warning { color: var(--ui-warn); }
#db .error, #db .odd { color: var(--ui-err); }
#db .info { color: var(--ui-accent); }
#db .ok { color: var(--ui-ok); }
#db pre { margin: 4px 0 0; font: 13px/1.45 ui-monospace, "Noto Sans Mono CJK JP", monospace; white-space: pre; overflow-x: auto; }
#db pre .mk { color: var(--ui-err); }
#db pre.raw { color: var(--ui-dim); font-size: 12px; }
.vband { display: flex; gap: 14px; align-items: center; max-width: 920px; }
.vband .alg { flex: none; }
.vband .env { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; min-width: 0; }
.vband canvas, #vm canvas { display: block; width: 100%; height: 74px; background: var(--ui-bg); border: 1px solid var(--ui-line); border-radius: 4px; }
.vbtn { flex: none; border: 1px solid var(--ui-accent); color: var(--ui-accent); background: var(--ui-bg); border-radius: 6px; padding: 6px 14px; font-size: 13px; }
svg rect.car { fill: var(--ui-carrier); } svg rect.mod { fill: var(--ui-panel); stroke: var(--ui-modulator); stroke-width: 1.5; }
svg text { font: 11px ui-monospace, monospace; text-anchor: middle; fill: var(--ui-fg); }
svg text.car { fill: var(--ui-panel); font-weight: 600; } svg text.mod { fill: var(--ui-modulator); }
svg text.out { text-anchor: start; fill: var(--ui-dim); }
svg .e { fill: none; stroke: var(--ui-dim); stroke-width: 1.2; } svg .ah { fill: var(--ui-dim); }

/* ---- 音色のモーダル ---- */
#shade { position: fixed; inset: 0; z-index: 10; background: rgba(20,22,26,.42); display: flex; align-items: center; justify-content: center; }
#vm { background: var(--ui-panel); border-radius: 10px; box-shadow: 0 8px 32px rgba(0,0,0,.28); width: min(900px, 94vw); max-height: 92vh; display: flex; flex-direction: column; overflow: hidden; outline: none; }
#vm .hd { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--ui-line); flex-wrap: wrap; }
#vm .hd .nm { font-weight: 700; font-size: 15px; white-space: nowrap; }
#vm .hd button, #vm .hd select { border: 1px solid var(--ui-line); background: var(--ui-bg); border-radius: 6px; height: 30px; padding: 0 10px; font-size: 13px; }
#vm .hd button:disabled { opacity: .35; }
#vm .hd .x { margin-left: auto; width: 30px; padding: 0; }
#vm .pv { padding: 8px 12px; background: var(--ui-activeLine); border-bottom: 1px solid var(--ui-line); display: flex; align-items: center; gap: 10px; font-size: 13px; flex-wrap: wrap; }
#vm .pv button { border: 1px solid var(--ui-line); background: var(--ui-bg); border-radius: 6px; height: 28px; padding: 0 12px; }
#vm .pv button.apply { border-color: var(--ui-accent); color: var(--ui-accent); font-weight: 600; }
#vm .bd { padding: 12px; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px 18px; overflow: auto; }
#vm .af { font: 13px ui-monospace, monospace; display: flex; gap: 6px; margin-top: 6px; align-items: center; }
#vm .af .lbl { color: var(--ui-dim); }
#vm .af [data-i] { padding: 1px 6px; border-radius: 3px; cursor: pointer; }
#vm .af [data-i].sel { background: var(--ui-accent); color: var(--ui-panel); }
#vm.preview .af [data-i].sel { background: var(--ui-selection); color: var(--ui-fg); }
#vm .cur .car { color: var(--ui-carrier); } #vm .cur .mod { color: var(--ui-modulator); }
#vm .cur { font-size: 13px; margin-top: 8px; min-height: 1.4em; }
#vm .cur .sel { color: var(--ui-accent); font-weight: 600; }
#vm table { border-collapse: collapse; font: 13px ui-monospace, monospace; }
#vm th { color: var(--ui-dim); font-weight: 400; padding: 2px 6px; }
#vm td { padding: 3px 7px; text-align: right; border-radius: 3px; cursor: pointer; font-variant-numeric: tabular-nums; }
#vm td:hover { background: var(--ui-activeLine); }
#vm td.sel { background: var(--ui-accent); color: var(--ui-panel); }
#vm td.missing { color: var(--ui-dim); cursor: default; }
#vm th.car { color: var(--ui-carrier); font-weight: 700; } #vm th.mod { color: var(--ui-modulator); font-weight: 700; }
#vm.preview td { cursor: default; } #vm.preview td.sel { background: var(--ui-selection); color: var(--ui-fg); }
#vm .edit { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
#vm .edit button { min-width: 40px; height: 32px; border: 1px solid var(--ui-line); background: var(--ui-bg); border-radius: 6px; font-size: 15px; }
#vm .edit input { width: 4.5em; height: 32px; border: 1px solid var(--ui-line); background: var(--ui-bg); border-radius: 6px; padding: 0 6px; text-align: right; font: 14px ui-monospace, monospace; }
#vm.preview .edit { visibility: hidden; }
#vm .envs { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
#vm .envs canvas { height: 80px; }
#vm .short { grid-column: 1 / -1; color: var(--ui-warn); font-size: 13px; }
#vm .kb { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; }
#vm .oct { display: flex; align-items: center; gap: 4px; font: 13px ui-monospace, monospace; }
#vm .oct button { width: 30px; height: 30px; border: 1px solid var(--ui-line); background: var(--ui-bg); border-radius: 6px; }
#vm .keys { position: relative; height: 96px; flex: 1; max-width: 560px; touch-action: none; user-select: none; }
#vm .keys .w { position: absolute; bottom: 0; height: 100%; border: 1px solid var(--ui-line); background: #fff; border-radius: 0 0 4px 4px; display: flex; align-items: flex-end; justify-content: center; font: 11px ui-monospace, monospace; color: #888; padding-bottom: 4px; }
#vm .keys .b { position: absolute; top: 0; height: 60%; background: #2b2d31; border-radius: 0 0 3px 3px; z-index: 1; display: flex; align-items: flex-end; justify-content: center; font: 10px ui-monospace, monospace; color: #bbb; padding-bottom: 3px; }
#vm .keys .on { background: var(--ui-accent) !important; color: #fff; }
#vm .kbhint { color: var(--ui-dim); font-size: 12px; line-height: 1.5; }
#vm .msg { grid-column: 1 / -1; color: var(--ui-warn); font-size: 13px; min-height: 1em; }

/* ---- スマホ ---- */
@media (max-width: 639px) {
	#top { flex-wrap: wrap; padding: 6px 8px; row-gap: 6px; }
	.tb { padding: 0 10px; }
	.tb .lb { display: none; }
	#time { min-width: 0; }
	#song { display: none; }
	.tools { margin-left: auto; }
	#parts { order: 10; width: 100%; justify-content: space-between; }
	#parts .gap { width: 2px; }
	#ed .cm-scroller { font-size: 14px; }
	#ed .cm-lineNumbers { display: none !important; }
	/* 詳細情報は下から引き出す（閉じていても見出しの 1 行は見える） */
	#det { border-top: none; box-shadow: 0 -2px 8px rgba(0,0,0,.12); border-radius: 12px 12px 0 0; }
	#dh { background: var(--ui-panel); border-radius: 12px 12px 0 0; height: 40px; cursor: pointer; position: relative; }
	#dh::before { content: ''; position: absolute; left: 50%; top: 4px; margin-left: -18px; width: 36px; height: 4px; border-radius: 2px; background: var(--ui-line); }
	#det:not(.open) #db { display: none; }
	#db { height: 40vh; }
	.vband .env { display: none; }
	.vband { justify-content: space-between; }
	#vm { width: 100vw; max-height: none; height: 100%; border-radius: 0; }
	#vm .bd { grid-template-columns: minmax(0, 1fr); }
	#vm .envs { grid-template-columns: repeat(2, 1fr); }
	#vm .envs canvas { height: 64px; }
	#vm .kb { flex-wrap: wrap; }
	#vm .keys { flex-basis: 100%; max-width: none; height: 120px; }
	#vm .keys .w span, #vm .keys .b span, #vm .kbhint { display: none; }
}
