/* SPDX-License-Identifier: GPL-3.0-only */
:root { --bg:#151517; --part:#2a2a2d; --part2:#323236; --edge:#3a3a3e; --fg:#ececee; --dim:#8e8e93;
  --lit:#fff4d6; --green:#5fe08a; --red:#ff453a; --amber:#ffd60a; --accent:#7ab8ff; color-scheme: dark; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 13px/1.4 -apple-system, system-ui, Roboto, sans-serif; overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#app { max-width: 560px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column;
  padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
button { font: inherit; color: inherit; }

/* the firmware, the CPU, the MIDI player and the settings: in the panel's spare corner under the left cluster */
.tools { grid-area: t; display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.fw { min-width: 0; display: flex; align-items: center; gap: 6px; background: #26282c; border: 1px solid #3d4045;
  border-radius: 9px; padding: 5px 8px; text-align: left; height: 32px; }
.fw span { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.fw small { display: none; }
.fw i { font-style: normal; color: var(--dim); }
.toolrow { display: flex; gap: 5px; align-items: center; }
.icon { background: #26282c; border: 1px solid #3d4045; border-radius: 9px; width: 36px; height: 30px; font-size: 16px; flex: none; }
.meter { flex: 1; min-width: 0; font-size: 10px; color: var(--dim); font-variant-numeric: tabular-nums; }
.meter b { display: block; height: 4px; background: #000; border-radius: 3px; overflow: hidden; margin-top: 2px; }
.meter i { display: block; height: 100%; width: 0; background: var(--green); transition: width .3s; }

/* The panel, laid out as the FM-1 is: on the left MASTER SELECT / PRESETS ALGORITHM and OCT − +, the screen beside them,
 * then KNOB 1..4 and the two rows of buttons, the keys along the bottom. Upright, the machine's right half (the knobs and
 * buttons) sits under its left; turned on its side, everything is where it is on the machine. */
.panel { display: grid; gap: 7px; grid-template-columns: minmax(0, 38fr) minmax(0, 62fr);
  grid-template-areas: "a s" "t s" "o s" "b b" "g g" "k k"; grid-template-rows: auto auto auto auto auto minmax(130px, 1fr);
  align-content: start;
  flex: 1; padding: 8px; border-radius: 22px; background: #2b2d31;
  box-shadow: inset 0 0 0 1px #3d4045; }
.screenwrap { grid-area: s; position: relative; aspect-ratio: 1; background: #000; border-radius: 10px; overflow: hidden;
  box-shadow: 0 0 0 5px #111214; margin: 5px; }
canvas { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.power { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; background: rgba(0,0,0,.72); padding: 12px; text-align: center; }
.power[hidden] { display: none; }
.power button { font-size: 17px; padding: 10px 24px; border: 0; border-radius: 10px; background: #fff; color: #000; }
.power button:disabled { opacity: .5; }
.power p { margin: 0; color: #ccc; font-size: 12px; }
.knobs.top { grid-area: a; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 6px; }
.knobs.four { grid-area: b; display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.knob { position: relative; border-radius: 12px; touch-action: none;
  display: flex; flex-direction: column-reverse; align-items: center; justify-content: center; min-height: 58px; }
.knob svg { width: 38px; height: 38px; background: #1f2124; border-radius: 50%; box-shadow: 0 0 0 4px #26282c, 0 0 0 5px #44474c; }
.knob span { font-size: 10px; color: #c9cacd; letter-spacing: .05em; margin-bottom: 7px; font-weight: 600; }
.knob.active { background: #34373c; }
.knob.active svg { box-shadow: 0 0 0 4px #26282c, 0 0 0 6px var(--accent); }
.octs { grid-area: o; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: #26282c; border-radius: 12px; padding: 6px; align-self: end; }
.grid { grid-area: g; display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; background: #26282c; border-radius: 14px; padding: 7px; }
.btn { height: 44px; background: #2e3135; border: 1px solid #4a4d52; border-radius: 9px; font-size: 11px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; touch-action: none; letter-spacing: .04em; color: #e8e8ea; }
.octs .btn { height: 34px; }
.btn.dim { background: #4a4336; } .btn.lit { background: var(--lit); color: #111; } .btn.green { background: var(--green); color: #111; }
.btn.rec { color: var(--red); } .btn.lit.rec { color: #a00; }
.btn.held { outline: 2px solid var(--accent); outline-offset: -2px; }
.keys { grid-area: k; position: relative; height: 100%; max-height: 440px; touch-action: none; background: #26282c;
  border-radius: 16px; }
/* the keys: rounded pads, the black ones a row above, as the FM-1's silicone keys */
.key { position: absolute; border-radius: 999px; background: #d9dadc; }
.key.w { top: 47%; height: 48%; } .key.b { top: 6%; height: 36%; background: #c9cacd; }
.key.dim { background: #e8c9b6; } .key.b.dim { background: #8ac6bf; }
.key.lit { background: #f6b48e; } .key.b.lit { background: #4cc3b6; }
.key.held { outline: 3px solid var(--accent); outline-offset: -3px; }

/* on its side: the machine as it is. Top: the left cluster and OCT, the screen, then KNOB 1..4 over the buttons;
 * the keys the whole width below */
/* the panel turned a quarter, when the layout chosen is against the phone's way up */
.rot-cw #app, .rot-ccw #app { position: fixed; top: 0; left: 0; width: 100vh; height: 100vw; max-width: none; min-height: 0;
  transform-origin: top left; overflow: hidden; }
.rot-cw #app { transform: translateX(100vw) rotate(90deg); }
.rot-ccw #app { transform: translateY(100vh) rotate(-90deg); }
html.rot-cw .screenwrap { max-height: 56vw; }
html.rot-cw .btn { height: clamp(28px, 7vw, 44px); }

/* on its side (Settings → Layout: by the phone's turn, or always one way): the machine as it is */
.lay-side #app { max-width: none; }
.lay-side .panel { flex: 1; grid-template-columns: minmax(0, 24fr) auto minmax(0, 44fr);
    grid-template-areas: "a s b" "t s b" "o s g" "k k k"; grid-template-rows: auto auto auto minmax(0, 1fr);
    align-items: stretch; column-gap: 14px; }
.lay-side .screenwrap { height: 100%; width: auto; aspect-ratio: 1; align-self: center; max-height: 56vh; }
.lay-side .knobs.top { grid-row: 1; }
.lay-side .knob { min-height: 0; padding: 2px 0; }
.lay-side .knobs.four .knob svg { width: 34px; height: 34px; }
.lay-side .grid { align-self: end; }
.lay-side .btn { height: clamp(28px, 7vh, 44px); }
.lay-side .keys { height: 100%; min-height: 110px; }
.lay-side .tools { flex-direction: row; align-items: center; }
.lay-side .tools .fw { flex: 1; }

dialog { border: 0; padding: 0; background: transparent; color: inherit; max-width: 560px; width: 100%; max-height: 100%;
  margin: auto auto 0; }
dialog::backdrop { background: rgba(0,0,0,.6); }
.sheet { background: #1f1f22; border-radius: 16px 16px 0 0; padding: 12px 14px max(14px, env(safe-area-inset-bottom));
  max-height: 86vh; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.sheethead { display: flex; justify-content: space-between; align-items: center; font-size: 16px; }
.sheet input[type=search], .sheet input:not([type]), .sheet select { width: 100%; font: inherit; font-size: 15px; padding: 9px 10px;
  border-radius: 9px; border: 1px solid var(--edge); background: #111; color: var(--fg); }
.sheet label { display: flex; flex-direction: column; gap: 4px; }
.sheet label.row { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; }
.sheet button:not(.icon) { padding: 10px; border-radius: 9px; border: 1px solid var(--edge); background: var(--part); }
.sheet button.danger { color: var(--red); }
#fwList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
#fwList li { background: var(--part); border: 1px solid var(--edge); border-radius: 10px; padding: 9px 10px; }
#fwList li.on { border-color: var(--accent); }
#fwList b { font-size: 15px; } #fwList small { color: var(--dim); margin-left: 6px; }
#fwList p { margin: 3px 0 0; color: #bbb; font-size: 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
#fwList .x { float: right; color: var(--dim); background: none; border: 0; padding: 0 0 0 8px; }
.addurl summary { color: var(--accent); }
.addurl { display: flex; flex-direction: column; gap: 6px; }
.addurl input { margin-top: 6px; }
.fine { color: var(--dim); font-size: 11px; margin: 0; }
.fine a { color: inherit; }
.filebtn { padding: 10px; border-radius: 9px; border: 1px solid var(--edge); background: var(--part); text-align: center; flex-direction: row !important; justify-content: center; }
#updateBar { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--accent); color: #0b1a2e; border-radius: 12px; padding: 8px 8px 8px 14px; display: flex; gap: 12px;
  align-items: center; font-weight: 600; box-shadow: 0 4px 18px rgba(0,0,0,.5); z-index: 20; }
#updateBar[hidden] { display: none; }
#updateBar button { border: 0; border-radius: 8px; padding: 7px 14px; background: #0b1a2e; color: #fff; font-weight: 600; }
.repo { display: flex; flex-direction: column; gap: 6px; }
.repo summary { color: var(--accent); font-size: 14px; }
.repo input { margin-top: 6px; }
.mrow { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; align-items: center; background: var(--part);
  border: 1px solid var(--edge); border-radius: 10px; padding: 7px 8px; }
.mrow + .mrow { margin-top: 6px; }
.mname { min-width: 0; } .mname b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mname small { color: var(--dim); font-size: 11px; }
.mrow select { width: auto !important; font-size: 13px !important; padding: 6px !important; }
.mctl { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.mctl label { flex-direction: row !important; align-items: center; gap: 6px !important; }
.mctl input[type=number] { width: 64px; font: inherit; padding: 6px; border-radius: 8px; border: 1px solid var(--edge); background: #111; color: var(--fg); }
#midiPlay { min-width: 90px; }
#midiTitle { margin: 0; font-weight: 600; }
