/* style.css - the shell of the tracker: colours, header, panes, dialogs.
   The pattern editor and the instrument panel have their own files (ui/*.css) and can
   use the colour variables below: --bg --panel --panel-2 --fg --muted --border --accent
   --accent-fg --accent-soft --good --bad --warn --focus --mono --radius.

   Part of the WebSidTracker web app, GPL version 3 or later (see ./LICENSE). */

:root {
  color-scheme: light dark;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 0.429rem;

  /* light */
  --bg: #eeece6;
  --panel: #fbfaf7;
  --panel-2: #e4e1d8;
  --fg: #1c2027;
  --muted: #5d6471;
  --border: #c9c5b8;
  --accent: #0a62b8;
  --accent-fg: #ffffff;
  --accent-soft: #0a62b822;
  --good: #1a7f4b;
  --bad: #b3261e;
  --warn: #8a5a00;
  --focus: #0a62b8;
  --shadow: 0 1px 2px #0002, 0 0.429rem 1.429rem #0001;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101319;
    --panel: #181c24;
    --panel-2: #232937;
    --fg: #e5e8ee;
    --muted: #9aa2b3;
    --border: #2f3646;
    --accent: #5cb6ff;
    --accent-fg: #06121f;
    --accent-soft: #5cb6ff26;
    --good: #55d494;
    --bad: #ff7b72;
    --warn: #f0b84a;
    --focus: #8fd0ff;
    --shadow: 0 1px 2px #0006, 0 0.571rem 1.714rem #0006;
  }
}

* { box-sizing: border-box; }

/* The one scale of the whole interface. Everything else is in rem (or em), so changing this one
   number resizes fonts, rows, buttons, gaps and icons together.
     width-based:  1.094vw = 14 px at 1280 px wide
     height-based: 1.75vh  = 14 px at 800 px high
   The smaller of the two wins, so a wide but short window does not blow the layout up. The lower
   bound is 0.875rem (14 px with the default browser font size), the upper bound 1.75rem (28 px).
   Because the bounds are in rem they follow the user's own font-size setting, and the vw/vh part
   follows browser zoom (zooming in shrinks the viewport in CSS pixels). Reference points:
   1280x800 -> 14 px, 1440x900 -> 15.8, 1920x1080 -> 18.9, 2560x1300 -> 22.8, 3440x1440 -> 25.2,
   3840x2160 -> 28. */
html {
  height: 100%;
  font-size: clamp(0.875rem, min(1.094vw, 1.75vh), 1.75rem);
  -webkit-text-size-adjust: 100%;
}

body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 1rem/1.4 var(--sans);
}

code, kbd { font-family: var(--mono); font-size: 0.92em; }
kbd {
  display: inline-block; min-width: 1.6em; padding: 0 0.4em; text-align: center;
  background: var(--panel-2); border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 0.286rem;
}

a { color: var(--accent); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---- header ------------------------------------------------------------ */

.topbar {
  flex: none;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 0.571rem 1rem 0.714rem;
  display: grid;
  gap: 0.571rem;
}

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.571rem 1rem; }
.grow { flex: 1 1 auto; }
.spacer { flex: 1; }

.brand {
  display: flex; align-items: center; gap: 0.571rem;
  font: 700 1.214rem/1 var(--mono); letter-spacing: 0.02em; color: var(--accent);
}
.brand b { color: var(--fg); font-weight: 700; }

.group { display: inline-flex; gap: 0.286rem; }

.field { display: inline-flex; align-items: center; gap: 0.429rem; }
.field .label { color: var(--muted); font-size: 0.857rem; text-transform: uppercase; letter-spacing: 0.06em; }
.field .unit { color: var(--muted); font-size: 0.857rem; min-width: 4.5em; }
.field.grow { max-width: 22rem; min-width: 12rem; }
.field.grow input { width: 100%; }

svg { width: 1em; height: 1em; flex: none; }
.brand svg { width: 1.57rem; height: 1.57rem; }

button, select, input[type="text"], input[type="number"] {
  font: inherit;
  color: var(--fg);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.286rem 0.714rem;
  min-height: 2.143rem;
}

input[type="text"], input[type="number"] { background: var(--bg); }
input[type="number"] { width: 4.6em; font-family: var(--mono); }

button { cursor: pointer; display: inline-flex; align-items: center; gap: 0.429rem; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: default; }

button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }

button.play svg { color: var(--good); }
button.stop svg { color: var(--bad); }
button.play.active { background: var(--good); color: var(--bg); border-color: var(--good); }
button.play.active svg { color: currentColor; }

button.mute { font-family: var(--mono); font-weight: 600; min-width: 2.8em; justify-content: center; padding: 0.286rem 0.429rem; }
button.mute[aria-pressed="true"] { background: var(--bad); color: var(--bg); border-color: var(--bad); }

input[type="range"] { width: 5.5rem; accent-color: var(--accent); }

.transport { padding-top: 0.571rem; border-top: 1px solid var(--border); }

.meter { width: 4rem; height: 0.714rem; background: var(--bg); border: 1px solid var(--border); border-radius: 0.357rem; overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--good); transition: width 60ms linear; }

.readout { flex: 1 1 0; min-width: 11rem; color: var(--muted); font: 0.857rem/1.3 var(--mono); text-align: right; }
.readout span { display: inline-block; white-space: nowrap; margin-left: 0.9em; }
.readout b { color: var(--fg); font-weight: 600; }
.readout .low { color: var(--warn); }

/* ---- messages ------------------------------------------------------------ */

.messages { flex: none; display: grid; }
.messages:empty { display: none; }

.message {
  display: flex; gap: 0.714rem; align-items: flex-start;
  padding: 0.571rem 1rem; border-bottom: 1px solid var(--border);
  border-left: 0.286rem solid var(--muted); background: var(--panel);
}
.message.error { border-left-color: var(--bad); }
.message.warn { border-left-color: var(--warn); }
.message.info { border-left-color: var(--good); }
.message strong { display: block; }
.message ul { margin: 2px 0 0; padding-left: 1.2em; }
.message .body { flex: 1; min-width: 0; }
.message button.dismiss { min-height: 1.714rem; padding: 0 0.571rem; }

/* ---- workspace ----------------------------------------------------------- */

.workspace {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(28.571rem, 34%);
  gap: 0.714rem;
  padding: 0.714rem 1rem;
}

.pane {
  min-width: 0; min-height: 0;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.571rem;
}

.pane-failed { padding: 1.143rem; color: var(--bad); }

/* The instrument panel lays itself out by the width of this pane (see ui/instruments.css). */
#instrument-pane { container: inst / inline-size; }

/* ---- footer -------------------------------------------------------------- */

.footer {
  flex: none; display: flex; flex-wrap: wrap; gap: 0.286rem 1.143rem; align-items: baseline;
  padding: 0.429rem 1rem; font-size: 0.857rem; color: var(--muted);
  border-top: 1px solid var(--border); background: var(--panel);
}

/* ---- dialogs ------------------------------------------------------------- */

dialog {
  width: min(46rem, calc(100vw - 2rem)); max-height: calc(100vh - 2.857rem);
  padding: 0; color: var(--fg); background: var(--panel);
  border: 1px solid var(--border); border-radius: 0.714rem; box-shadow: var(--shadow);
}
dialog::backdrop { background: #0008; }
dialog form { padding: 1.143rem 1.429rem; }
dialog h2 { margin: 0 0 0.571rem; font-size: 1.286rem; }
dialog h3 { margin: 1.286rem 0 0.429rem; font-size: 0.929rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 1.143rem; }
.hint { color: var(--muted); margin: 0 0 0.857rem; }
.upgrade-actions { flex-wrap: wrap; gap: 0.571rem; }
#upgrade-reasons { padding-left: 1.2rem; }
.release { margin-left: 0.5rem; font-weight: 400; color: var(--muted); }
.dev-bar { padding: 0.286rem 1rem; text-align: center; font-weight: 600; color: #000; background: #e0b030; }

.keys { display: grid; grid-template-columns: max-content 1fr; gap: 0.286rem 1rem; margin: 0; }
.keys dt { text-align: right; white-space: nowrap; }
.keys dd { margin: 0; color: var(--fg); }

.file-row { display: flex; flex-wrap: wrap; gap: 0.571rem; align-items: center; padding: 0.571rem 0; border-top: 1px solid var(--border); }
.file-row:first-child { border-top: 0; }
.file-row .name { font-family: var(--mono); font-weight: 600; }
.file-row .size { color: var(--muted); font-size: 0.857rem; }
.file-row .what { flex-basis: 100%; color: var(--muted); font-size: 0.857rem; margin-top: -0.286rem; }
.file-row .spacer { flex: 1; }
.file-preview {
  flex-basis: 100%; margin: 0.286rem 0 0; padding: 0.571rem 0.714rem; max-height: 14rem; overflow: auto;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  font: 0.857rem/1.35 var(--mono); white-space: pre;
}

.noscript { padding: 1.429rem; }

/* ---- wide windows ---------------------------------------------------------- */

/* The header is two tidy rows (file and demo controls, then transport). All its controls need
   about 145rem for one row, more than any window reaches since the root size grows with the
   window, so it never merges into one row. */

/* More room for the instrument panel, which has a two-column form of its own when wide. */
@media (min-width: 1700px) {
  .workspace { grid-template-columns: minmax(0, 1fr) minmax(28.571rem, 40%); }
}
@media (min-width: 2300px) {
  .workspace { grid-template-columns: minmax(0, 1fr) minmax(28.571rem, 50%); }
}

/* ---- narrower windows ------------------------------------------------------ */

@media (max-width: 1100px) {
  .workspace { grid-template-columns: minmax(0, 1fr) 27.143rem; }
}

/* One column: the page itself scrolls. The pattern editor gets a tall pane of its own, the
   instrument panel its natural height below it. */
@media (max-width: 900px) {
  html, body { height: auto; min-height: 100%; }
  .workspace { flex: none; grid-template-columns: minmax(0, 1fr); grid-auto-rows: auto; }
  #editor-pane { height: max(31.429rem, 70vh); }
  #instrument-pane { overflow: visible; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---- demo menu ---------------------------------------------------------- */

.demo-select { max-width: 13rem; }
