/* Melogen. Mobile first; colours are tokens so dark mode is one block. */

:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #ecebe5;
  --text: #1c1d20;
  --muted: #62656c;
  --line: #d6d4cb;
  --accent: #2b59c3;
  --accent-text: #ffffff;
  --play: #17803d;
  --play-text: #ffffff;
  --up: #17803d;
  --down: #b3261e;
  --focus: #2b59c3;
  --radius: 12px;
  --gutter: 16px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181c;
    --surface: #202328;
    --surface-2: #2b2f36;
    --text: #ececf0;
    --muted: #a0a4ad;
    --line: #3a3e47;
    --accent: #8fb0ff;
    --accent-text: #0e1626;
    --play: #3ecf7a;
    --play-text: #08210f;
    --up: #5fdc92;
    --down: #ff8a80;
    --focus: #8fb0ff;
  }
}

:root[data-theme="dark"] {
  --bg: #16181c;
  --surface: #202328;
  --surface-2: #2b2f36;
  --text: #ececf0;
  --muted: #a0a4ad;
  --line: #3a3e47;
  --accent: #8fb0ff;
  --accent-text: #0e1626;
  --play: #3ecf7a;
  --play-text: #08210f;
  --up: #5fdc92;
  --down: #ff8a80;
  --focus: #8fb0ff;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app {
  max-width: 40rem;
  margin: 0 auto;
  padding: 0 var(--gutter) 3rem;
}

button, input, select { font: inherit; color: inherit; }

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

[hidden] { display: none !important; }

/* ---- masthead and tabs ---- */

.masthead { padding: 1.25rem 0 0.75rem; }
.masthead h1 { margin: 0; font-size: 1.6rem; letter-spacing: 0.01em; }
.masthead .subtitle { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.masthead p { margin: 0; color: var(--muted); font-size: 0.95rem; }
.masthead a { color: var(--muted); font-size: 0.95rem; padding: 0.25rem 0; }
.masthead a:hover { color: var(--text); }

.tablist {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: var(--radius);
  position: sticky;
  top: 0;
  z-index: 2;
}

.tab {
  flex: 1;
  min-width: 0;
  padding: 0;
  white-space: nowrap;
  /* Four tabs share the width; the text shrinks to fit a narrow phone rather than being clipped. */
  font-size: clamp(0.74rem, 3.4vw, 0.95rem);
  min-height: 44px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab[aria-selected="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / 0.15); }

.panel { padding-top: 1rem; }

/* ---- interact ---- */

.intro { margin: 0 0 1rem; color: var(--muted); font-size: 0.95rem; }
.run-title { margin: 0; font-size: 1.15rem; }
.run-progress { margin: 0.1rem 0 0.9rem; color: var(--muted); font-size: 0.9rem; }

.notice { margin: 0 0 0.9rem; padding: 0.6rem 0.8rem; border-radius: 8px; background: var(--surface-2); font-size: 0.92rem; }
.interact .notice { min-height: 2.6rem; display: flex; align-items: center; }
.interact .notice.idle { visibility: hidden; }
.notice.error { background: color-mix(in srgb, var(--down) 18%, var(--surface)); }

.rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.row {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: 56px 1fr auto;
  grid-template-areas: "play info download" "play votes votes";
  align-items: center;
  gap: 6px 12px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.row.playing { border-color: var(--play); }
.row.carried { border-style: dashed; }
/* A vote carried over from the last generation is outlined, not filled like one you just cast. */
.row.carried .vote[aria-pressed="true"] { background: transparent; border: 2px solid currentColor; }
.row.carried .vote-up[aria-pressed="true"] { color: var(--up); }

.play {
  grid-area: play;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--play);
  color: var(--play-text);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.play svg { width: 28px; height: 28px; }

.info { grid-area: info; display: flex; align-items: baseline; gap: 0.6rem; min-width: 0; }
.number { font-weight: 700; font-size: 1.1rem; }
.origin { color: var(--muted); font-size: 0.85rem; }

.votes { grid-area: votes; display: flex; gap: 6px; }

.vote {
  flex: 1;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 1.25rem;
  font-weight: 600;
  cursor: pointer;
}

.vote[aria-pressed="true"] { color: var(--accent-text); border-color: transparent; }
.vote-up[aria-pressed="true"] { background: var(--up); }
.vote-down[aria-pressed="true"] { background: var(--down); }
.vote-zero[aria-pressed="true"] { background: var(--accent); }

.download {
  grid-area: download;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.sweep {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 100%;
  background: var(--play);
  transform-origin: left;
  transform: scaleX(0);
}

.row.playing .sweep { animation: sweep var(--duration, 8s) linear forwards; }
.row.looping .sweep { animation-iteration-count: infinite; }

@keyframes sweep { to { transform: scaleX(1); } }

@media (prefers-reduced-motion: reduce) {
  .row.playing .sweep { animation: none; transform: scaleX(1); }
}

.actions { display: flex; gap: 10px; margin-top: 1rem; flex-wrap: wrap; }

.action {
  flex: 1;
  min-height: 48px;
  padding: 0 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.action.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
.action.quiet { background: transparent; color: var(--muted); }
.action svg { width: 20px; height: 20px; }
.action:disabled, .vote:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---- settings and instrument ---- */

.field { padding: 0.7rem 0; border-bottom: 1px solid var(--line); }
.field label { display: block; font-weight: 600; margin-bottom: 0.35rem; }
.control { display: flex; align-items: center; gap: 10px; }
.control select, .control input[type="number"], .control input[type="url"] {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.control input[type="range"] { flex: 1; min-width: 0; min-height: 44px; accent-color: var(--accent); }
.readout { min-width: 4.5rem; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.help { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.88rem; }

.segment { display: flex; flex: 1; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 10px; }
.segment button { flex: 1; min-height: 40px; border: 0; border-radius: 7px; background: transparent; cursor: pointer; }
.segment button[aria-pressed="true"] { background: var(--surface); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / 0.15); }

.switch { width: 3rem; height: 1.7rem; accent-color: var(--accent); }

.confirm { margin-bottom: 0.8rem; padding: 0.8rem; border-radius: var(--radius); background: color-mix(in srgb, var(--accent) 16%, var(--surface)); }
.confirm p { margin: 0; }

.about h3 { margin: 1rem 0 0.2rem; }
.about p { margin: 0 0 0.5rem; color: var(--muted); }
.about details { margin-bottom: 0.5rem; color: var(--muted); font-size: 0.92rem; }
.about li { margin-bottom: 0.4rem; }

.group { margin: 1rem 0 0; padding: 0 0 0.3rem; border: 0; border-top: 2px solid var(--line); }
.group legend { padding: 0 0.5rem 0 0; font-weight: 700; color: var(--muted); }

.mini { width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer; }
.mini svg { width: 18px; height: 18px; }

@media (min-width: 34rem) {
  .row { grid-template-columns: 56px 7rem 1fr auto; grid-template-areas: "play info votes download"; }
}

.diagnostics { margin-top: 1.5rem; color: var(--muted); font-size: 0.92rem; }
.diagnostics summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; }
.level-label { display: flex; align-items: center; gap: 0.6rem; }
.level-label meter { flex: 1; height: 1rem; }
.diagnostics-text { white-space: pre-wrap; overflow-wrap: anywhere; padding: 0.7rem; border-radius: 8px; background: var(--surface-2); font-size: 0.8rem; user-select: all; }
.beep-status { min-height: 1.4rem; margin: 0.4rem 0; color: var(--text); }

/* ---- about ---- */

.about-page h2 { margin: 1.5rem 0 0.4rem; font-size: 1.1rem; }
.about-page p, .about-page li { margin: 0 0 0.6rem; }
.about-page ol, .about-page ul { padding-left: 1.3rem; margin: 0; }
.about-page .lead { font-size: 1.05rem; }
.about-page a { color: var(--accent); }
