/* Übernome styles. Light design first; the dark palette is one @media screen block at the end,
   so print never sees it. Beat levels are told apart by shape and text, never colour alone. */
:root {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --bg: #ffffff;
  --fg: #1d1d1f;
  --muted: #5c5c66;
  --border: #c8c8cc;
  --surface: #f4f4f6;
  --raised: #ffffff;
  --control-bg: #ffffff;
  --control-fg: #1d1d1f;
  --control-border: #8e8e96;
  --control-hover: #ebebef;
  --disabled-fg: #8e8e96;
  --disabled-border: #cfcfd4;
  --pressed-bg: #1d1d1f;
  --pressed-fg: #ffffff;
  --accent: #1a5fb4;
  --focus: #1a5fb4;
  --warn: #8a4b00;
  --error: #b00020;
  --play: #1a5fb4;
  --tooltip-bg: #222226;
  --tooltip-fg: #ffffff;
  --backdrop: rgba(0, 0, 0, 0.3);
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  line-height: 1.4;
}
a { color: var(--accent); }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Controls */
button, select, input, textarea { font: inherit; font-size: 0.95rem; }
button {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: var(--control-bg);
  color: var(--control-fg);
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--control-hover); }
button:disabled { color: var(--disabled-fg); border-color: var(--disabled-border); cursor: default; }
select, input[type="text"], textarea {
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: var(--control-bg);
  color: var(--control-fg);
}
input[type="range"] { accent-color: var(--accent); }
input[type="radio"], input[type="checkbox"] { accent-color: var(--accent); width: 1.05rem; height: 1.05rem; margin: 0; }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible,
summary:focus-visible, a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.theme-toggle[aria-pressed="true"],
.theme-toggle[aria-pressed="true"]:hover:not(:disabled) { background: var(--pressed-bg); color: var(--pressed-fg); border-color: var(--pressed-bg); }

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.25rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.toolbar-group { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
.title-input { width: min(22rem, 70vw); font-size: 1.05rem; font-weight: 600; }
.dirty { font-size: 0.8rem; color: var(--warn); font-style: italic; }
/* Quiet same-tab links to the sibling sites, at the end of the toolbar. */
.toolbar-links { display: flex; gap: 1rem; margin-left: auto; }
.toolbar-link { color: var(--muted); font-size: 0.85rem; text-decoration: none; white-space: nowrap; }
.toolbar-link:visited { color: var(--muted); }
.toolbar-link:hover, .toolbar-link:focus-visible { color: var(--fg); text-decoration: underline; }

/* Browser storage notice */
.storage-hint {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin: 0.75rem 1rem 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-left: 4px solid var(--warn);
  border-radius: 4px;
  background: var(--surface);
  font-size: 0.9rem;
}
.storage-hint p { flex: 1 1 20rem; margin: 0; }

/* Main layout */
main { padding: 0.75rem 1rem 1rem; max-width: 64rem; }
.notes { margin-bottom: 0.75rem; }
.notes summary { cursor: pointer; color: var(--muted); width: max-content; }
.notes-input { display: block; width: min(40rem, 100%); margin-top: 0.4rem; resize: vertical; }
.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr)); gap: 0.75rem; }
.panel {
  margin: 0;
  padding: 0.6rem 0.9rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--raised);
  min-width: 0;
}
.panel-title { margin: 0 0 0.4rem; padding: 0; font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.panel-hint { margin: 0 0 0.5rem; font-size: 0.85rem; color: var(--muted); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.6rem; margin: 0.35rem 0; }

/* Transport */
.btn-transport { min-width: 6rem; font-weight: 600; font-size: 1.05rem; padding: 0.45rem 1rem; }
.btn-transport[aria-pressed="true"],
.btn-transport[aria-pressed="true"]:hover:not(:disabled) { background: var(--pressed-bg); color: var(--pressed-fg); border-color: var(--pressed-bg); }

/* Tempo */
.tempo-unit { font-size: 1.15rem; min-width: 3.5rem; }
.tempo-equals { font-size: 1.15rem; color: var(--muted); }
.tempo-input { width: 6ch; font-size: 1.15rem; text-align: center; font-variant-numeric: tabular-nums; }
.step { min-width: 2.25rem; font-size: 1.1rem; padding: 0.3rem 0.5rem; }
.tempo-readout { margin-left: 0.5rem; font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.field-error { margin: 0.2rem 0; color: var(--error); font-size: 0.9rem; }

/* Meter */
.meter { border: 1px solid var(--border); }
.meter legend { float: left; width: 100%; }
.meter-row { clear: both; }
.meter-option, .toggle { display: inline-flex; align-items: center; gap: 0.35rem; cursor: pointer; }
.meter-option { min-width: 3.75rem; font-size: 1.05rem; }

/* Beat indicator. Shapes: accent = large filled circle, normal = outlined circle,
   mute = dashed, dimmed and struck through. The playing beat gets a thick outer ring. */
.beats { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; min-height: 6rem; }
.beat {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 4.25rem;
  height: 4.25rem;
  padding: 0;
  border: 2px solid var(--fg);
  border-radius: 50%;
  background: var(--control-bg);
  color: var(--fg);
  line-height: 1.1;
  transition: box-shadow 80ms linear, transform 80ms linear;
}
.beat:hover:not(:disabled) { background: var(--control-hover); }
.beat-num { font-size: 1.35rem; font-weight: 700; }
.beat-level { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; }
.beat.level-accent,
.beat.level-accent:hover:not(:disabled) {
  width: 5.25rem;
  height: 5.25rem;
  border-width: 3px;
  background: var(--fg);
  color: var(--bg);
}
.beat.level-mute {
  border-style: dashed;
  color: var(--muted);
  border-color: var(--muted);
}
.beat.level-mute .beat-num { text-decoration: line-through; text-decoration-thickness: 2px; }
.beat.level-mute::after {
  content: "";
  position: absolute;
  left: 12%;
  right: 12%;
  top: 50%;
  border-top: 2px solid var(--muted);
  transform: rotate(-45deg);
}
.beat.playing { box-shadow: 0 0 0 4px var(--bg), 0 0 0 9px var(--play); }
.beat.flash { transform: scale(1.06); }

/* Status line and footer */
.status { min-height: 1.4em; margin: 0.75rem 0 0; color: var(--muted); font-size: 0.95rem; }
.status.error { color: var(--error); }
.site-footer { padding: 0 1rem 1rem; color: var(--muted); font-size: 0.85rem; }

/* Dialogs */
dialog {
  border: 1px solid var(--border);
  border-radius: 6px;
  min-width: min(22rem, 92vw);
  max-width: 92vw;
  background: var(--raised);
  color: var(--fg);
}
dialog::backdrop { background: var(--backdrop); }
dialog h2 { margin-top: 0; font-size: 1.2rem; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: flex-end; margin-top: 1rem; }
.open-dialog { width: min(40rem, 92vw); }
.open-list { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow-y: auto; }
.open-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.75rem; padding: 0.45rem 0.25rem; border-bottom: 1px solid var(--border); }
.open-row-text { flex: 1 1 14rem; min-width: 0; }
.open-title { display: block; font-weight: 600; overflow-wrap: anywhere; }
.open-meta { display: block; font-size: 0.85rem; color: var(--muted); }
.open-empty { color: var(--muted); }
.open-damaged { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; margin-top: 0.75rem; font-size: 0.9rem; color: var(--warn); }
.import-errors-list { max-height: 50vh; overflow-y: auto; font: 0.85rem ui-monospace, monospace; }

/* Help dialog */
.help-dialog { width: min(52rem, 92vw); max-height: 88vh; padding: 0; }
.help-dialog[open] { display: flex; flex-direction: column; }
.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--raised);
}
.help-head h2 { margin: 0; }
.help-body { overflow-y: auto; padding: 0 1.25rem 1.25rem; line-height: 1.5; }
.help-body:focus { outline: none; }
.help-body h3 { margin: 1.5rem 0 0.5rem; font-size: 1.1rem; }
.help-body [tabindex="-1"]:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.help-body table { border-collapse: collapse; margin: 0.5rem 0; }
.help-body th, .help-body td { border: 1px solid var(--border); padding: 0.25rem 0.5rem; text-align: left; vertical-align: top; }
.help-body th { background: var(--surface); }
.help-body ol ol { margin: 0.15rem 0; }
kbd {
  padding: 0 0.3rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--surface);
  font: 0.85rem ui-monospace, monospace;
}

/* Tooltip (visual only; the same text is each control's accessible description) */
.tooltip {
  position: fixed;
  z-index: 100;
  max-width: 22rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  background: var(--tooltip-bg);
  color: var(--tooltip-fg);
  font-size: 0.8rem;
  line-height: 1.3;
  pointer-events: none;
}

/* Room for four beats in a row once there are at least two grid columns. */
@media (min-width: 40rem) {
  .beats-panel { grid-column: span 2; }
}
@media (max-width: 40rem) {
  .toolbar-links { margin-left: 0; }
  .beats { gap: 0.6rem; }
}

/* No movement for people who ask for less: no flash, no transitions. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .beat.flash { transform: none; }
}

/* Dark palette: screen only, keyed on the theme chosen by theme-boot.js / the toggle.
   Keep this the last block in the file. */
@media screen {
  [data-theme="dark"] {
    --bg: #18181b;
    --fg: #ececf1;
    --muted: #a1a1aa;
    --border: #4a4a52;
    --surface: #222226;
    --raised: #1f1f23;
    --control-bg: #2a2a2f;
    --control-fg: #ececf1;
    --control-border: #8c8c96;
    --control-hover: #3a3a40;
    --disabled-fg: #75757e;
    --disabled-border: #44444b;
    --pressed-bg: #ececf1;
    --pressed-fg: #18181b;
    --accent: #78aeed;
    --focus: #7cb1ff;
    --warn: #f2b766;
    --error: #ff8a80;
    --play: #7cb1ff;
    --tooltip-bg: #ececf1;
    --tooltip-fg: #18181b;
    --backdrop: rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}
