/* FM Studio — VGA text-mode look (layout per UI-LAYOUT.md v1). UI layer only. */
:root {
  --bg: #0B0F2A; --bg2: #121a45; --cyan: #55FFFF; --yellow: #FFFF55; --white: #FFFFFF; --grey: #C0C8E8;
  --green: #55FF55; --red: #FF5555; --sel: #55FFFF; --beat: #16205a; --bar: #1f2c78;
  --font: "Px437 IBM VGA8", "Px437 IBM VGA 8x16", "Perfect DOS VGA 437", ui-monospace, "Cascadia Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;
  --fs: 16px; --cellw: 14ch;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--white); font: var(--fs)/24px var(--font); overflow-x: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button, select, input[type=number], input:not([type]) {
  background: var(--bg2); color: var(--white); border: 1px solid var(--cyan); padding: 0 8px; min-height: 32px; border-radius: 0; cursor: pointer;
}
input:not([type]), input[type=number] { cursor: text; }
button:hover { background: #1d2a6e; }
button[aria-pressed=true], button[aria-selected=true] { background: var(--cyan); color: var(--bg); }
:focus-visible { outline: 2px solid var(--yellow); outline-offset: 1px; }
.k { color: var(--yellow); }
button[aria-pressed=true] .k, button[aria-selected=true] .k { color: var(--bg); }
code { color: var(--yellow); }

#app { display: grid; height: 100vh; height: 100dvh; gap: 8px; padding: 8px;
  grid-template-columns: minmax(0, 1fr) 480px; grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "top top" "main side" "status status"; }
.panel { position: relative; border: 2px solid var(--cyan); border-style: double; padding: 16px 8px 8px; min-width: 0; }
.panel::before { content: "┤ " attr(data-title) " ├"; position: absolute; top: -13px; left: 16px; background: var(--bg); color: var(--yellow); padding: 0 4px; white-space: nowrap; line-height: 24px; }
#topbar { grid-area: top; } #mainPanel { grid-area: main; display: flex; flex-direction: column; }
#side { grid-area: side; overflow: auto; } #status { grid-area: status; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; padding-top: 12px; }
.tb-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.songname input { width: 22ch; color: var(--yellow); }
.transport, .steppers { display: flex; gap: 8px; align-items: center; }
.steppers input { width: 8ch; text-align: center; }
.st { min-width: 32px; padding: 0; }
.lbl, .pos, .sub { color: var(--cyan); }
#orders { display: flex; gap: 4px; flex-wrap: wrap; }
#orders button { min-width: 4ch; padding: 0 4px; }
#orders button.cur { background: var(--cyan); color: var(--bg); }
#orders button.playing { outline: 2px solid var(--green); }
.pos { margin-left: auto; color: var(--white); }

#gridWrap, #rollWrap { flex: 1; overflow: auto; min-height: 0; }
#grid { border-collapse: collapse; white-space: pre; }
#grid th, #grid td { padding: 0 6px; border-right: 1px solid #2a3a8a; text-align: left; font-weight: normal; height: 24px; }
#grid thead th { position: sticky; top: 0; background: var(--bg); z-index: 2; border-bottom: 1px solid var(--cyan); vertical-align: top; }
#grid td.rn, #grid th.rn { position: sticky; left: 0; background: var(--bg); color: var(--cyan); z-index: 1; }
#grid thead th.rn { z-index: 3; }
#grid tr.beat td { background: var(--beat); } #grid tr.bar td { background: var(--bar); }
#grid tr.beat td.rn, #grid tr.bar td.rn { color: var(--yellow); }
#grid tr.play td { background: #3a3a00; }
#grid td.c { min-width: var(--cellw); color: var(--grey); cursor: pointer; }
#grid td.c .n { color: var(--white); } #grid td.c .i { color: var(--cyan); } #grid td.c .v { color: var(--green); } #grid td.c .f { color: var(--yellow); }
#grid td.c .e { color: #7f8ac0; }
#grid td.cur { outline: 2px solid var(--yellow); outline-offset: -2px; }
#grid td.cur .fsel { background: var(--white); color: var(--bg); }
#grid tr.currow td { background: #24306e; }
.chh { display: flex; flex-direction: column; gap: 2px; min-width: var(--cellw); }
.chh .nm { color: var(--yellow); cursor: pointer; overflow: hidden; text-overflow: ellipsis; max-width: 16ch; }
.chh .row { display: flex; gap: 4px; align-items: center; }
.chh button { min-height: 24px; padding: 0 6px; }
.meter { flex: 1; height: 8px; background: #1d2550; min-width: 32px; }
.meter i { display: block; height: 100%; width: 0; background: var(--green); }
th.muted .nm { color: var(--red); text-decoration: line-through; }
#roll { display: block; cursor: crosshair; }
body.editing #mainPanel { border-color: var(--red); }

.tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.tab label { display: block; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.list { list-style: none; margin: 0; padding: 0; max-height: 200px; overflow: auto; border: 1px solid #2a3a8a; }
.list li { padding: 0 6px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list li.sel { background: var(--cyan); color: var(--bg); }
.list li:hover:not(.sel) { background: #1d2a6e; }
.patch-lists { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.opcols { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; margin-top: 8px; }
.opcol { border: 1px solid #2a3a8a; padding: 4px; }
.opcol h4 { margin: 0; color: var(--yellow); font-weight: normal; }
.prm { display: grid; grid-template-columns: 5ch 1fr 5ch; gap: 4px; align-items: center; }
.prm input[type=range] { width: 100%; accent-color: var(--cyan); }
.prm input[type=number] { width: 5ch; padding: 0 2px; min-height: 24px; }
.flags { display: flex; gap: 8px; flex-wrap: wrap; }
.waves { display: flex; gap: 2px; flex-wrap: wrap; }
.waves button { padding: 0 2px; min-height: 24px; }
.waves button:disabled { opacity: .35; cursor: not-allowed; }
.waves svg { display: block; width: 24px; height: 16px; }
.global { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
#adsr { border: 1px solid #2a3a8a; margin-top: 8px; width: 100%; height: 64px; }
textarea#songText { width: 100%; height: calc(100vh - 300px); min-height: 240px; background: #070a1e; color: var(--white); border: 1px solid var(--cyan); font-size: 14px; line-height: 18px; resize: vertical; white-space: pre; }
#txtMsg { white-space: pre-wrap; color: var(--green); min-height: 24px; font-size: 14px; }
#txtMsg.err { color: var(--red); }
.filebtn { border: 1px solid var(--cyan); padding: 4px 8px; cursor: pointer; background: var(--bg2); }
.filebtn input { display: none; }
.note { font-size: 14px; color: var(--grey); }
progress { width: 100%; height: 16px; accent-color: var(--cyan); }
#wavOut a { color: var(--yellow); }
.hint { color: var(--grey); flex: 1; min-width: 20ch; }
dialog { background: transparent; border: 0; padding: 8px; color: var(--white); max-width: min(720px, 95vw); }
dialog::backdrop { background: rgba(0, 0, 20, .7); }
dialog .panel { background: var(--bg); }
dialog pre { white-space: pre-wrap; margin: 0; max-height: 70vh; overflow: auto; font: inherit; }
#mobileTabs { display: none; }

/* Medium screens: stack side under main */
@media (max-width: 1100px) and (min-width: 700px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto minmax(360px, 1fr) auto auto; grid-template-areas: "top" "main" "side" "status"; height: auto; min-height: 100vh; }
}
/* Phone: playback first */
@media (max-width: 699px) {
  :root { --fs: 16px; }
  html, body { font-size: 16px; }
  #app { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "top" "main" "nav"; padding: 6px 4px calc(4px + env(safe-area-inset-bottom)); gap: 10px; }
  #side { grid-area: main; display: none; } #status { display: none; }
  body[data-mtab=patch] #side, body[data-mtab=text] #side, body[data-mtab=export] #side { display: block; }
  body:not([data-mtab=pattern]) #mainPanel { display: none; }
  #side .tabs { display: none; }
  #mobileTabs { grid-area: nav; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
  #mobileTabs button { min-height: 48px; }
  .transport { width: 100%; } .transport .big { flex: 1; min-height: 56px; font-size: 18px; }
  .transport .k { display: none; }
  .songname input { width: 14ch; }
  #topbar .tb-row:last-child #ordAdd, #topbar #ordDel, #topbar #patNew, #btnMode .k { display: none; }
  .steppers { flex-wrap: wrap; }
  #gridWrap { scroll-snap-type: x mandatory; }
  :root { --cellw: calc((100vw - 4ch - 40px) / 4); }
  #grid td.c, .chh { min-width: var(--cellw); max-width: var(--cellw); overflow: hidden; scroll-snap-align: start; font-size: 16px; }
  #grid td.c .v, #grid td.c .f { display: none; }
  #grid th { scroll-snap-align: start; }
  .chh button.solo { display: none; }
  .desk { display: none; }
  textarea#songText { height: 50vh; }
  .patch-lists { grid-template-columns: 1fr; }
}
