:root {
  --bg: #f7f5f2;
  --fg: #1d1d1f;
  --muted: #6e6e73;
  --faint: #b8b8bd; /* decoration only; text uses --muted (AA) */
  --line: #d9d6d0;
  --control: #9a968f; /* control borders */
  --accent: #3a6df0;
  --link: #2f5fd8;
  --key-label: #65625c;
  --accent2: #8b4ee8;
  --white-key: #ffffff;
  --white-key-edge: #c9c6c0;
  --black-key: #1f1f23;
  --lit: #3a6df0;
  --error: #c62828;
  --overlay: rgba(247, 245, 242, 0.96);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416;
    --fg: #f2f2f4;
    --muted: #a1a1a8;
    --faint: #55555c;
    --line: #2e2e33;
    --control: #8d8a85;
    --link: #7aa2ff;
    --key-label: #5c5952;
    --white-key: #e9e7e3;
    --white-key-edge: #8d8a85;
    --black-key: #0a0a0c;
    --lit: #3a6df0;
    --error: #ff6b6b;
    --overlay: rgba(20, 20, 22, 0.96);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h1 { margin: 0; }
h1:focus { outline: none; }
.muted { color: var(--muted); }

.logo {
  display: block;
  width: min(60vw, 260px);
  height: auto;
  border-radius: 18%;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.logo.small { width: min(34vw, 150px); margin: 16px auto 0; }

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: max(24px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background: var(--bg);
  text-align: center;
}
.overlay.dim { background: var(--overlay); }
.tagline { font-size: 1.15rem; margin: 8px 0 4px; }
.primary {
  min-width: 200px;
  min-height: 52px;
  padding: 12px 28px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(58, 109, 240, 0.35);
}
.primary:disabled { opacity: 0.5; cursor: default; }
.primary:focus-visible, button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.progress { width: min(80vw, 320px); }
.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
#progressFill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width 0.1s; }
.error { color: var(--error); max-width: 28rem; }
.error p { margin: 0 0 12px; }

/* Main layout */
main {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right))
    env(safe-area-inset-bottom) max(16px, env(safe-area-inset-left));
}
.display {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 150px;
  text-align: center;
}
.label { font-size: clamp(2.2rem, 9vw, 3.4rem); font-weight: 800; line-height: 1.1; text-shadow: 0 0 18px rgba(58, 109, 240, 0.3); }
.label:empty { display: none; }
.detail { font-size: 0.95rem; color: var(--muted); font-weight: 500; }
.display.idle .detail { font-size: 1.3rem; color: var(--muted); }
.badge {
  margin-top: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
}

.message { text-align: center; font-size: 0.9rem; color: var(--muted); margin: 4px auto 10px; max-width: 34rem; }
.link { background: none; border: 0; padding: 0 2px; color: var(--link); text-decoration: underline; font-weight: 600; }

/* On-screen keyboard */
.kb-section { margin-bottom: 12px; }
.kb-controls { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.octave { display: flex; align-items: center; gap: 8px; }
.octave button, .toggle, .small-btn, .transpose button {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--control);
  border-radius: 12px;
  background: transparent;
  font-weight: 600;
}
.octave button:active, .toggle:active, .small-btn:active, .transpose button:active { background: var(--line); }
.octave span { min-width: 2.5em; text-align: center; font-variant-numeric: tabular-nums; }
.toggle { padding: 0 18px; }
.toggle[aria-pressed="true"] { background: linear-gradient(90deg, var(--accent), var(--accent2)); color: #fff; border-color: transparent; }
.hint { font-size: 0.75rem; text-align: center; margin: 8px 0 0; }
@media (pointer: coarse) { .hint { display: none; } }

.kb {
  --black-w: calc(100% / var(--whites) * 0.62);
  position: relative;
  display: flex;
  height: clamp(140px, 30vh, 230px);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.key { box-sizing: border-box; }
.key.white {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 6px;
  background: var(--white-key);
  border: 1px solid var(--white-key-edge);
  border-radius: 0 0 8px 8px;
  margin-right: -1px;
  color: var(--key-label);
  font-size: 0.65rem;
}
.key.black {
  position: absolute;
  top: 0;
  width: var(--black-w);
  height: 62%;
  background: var(--black-key);
  border-radius: 0 0 6px 6px;
  z-index: 1;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
}
.key.lit { background: var(--lit) !important; color: #fff; }

/* Bottom */
.bottom { display: flex; flex-direction: column; align-items: center; gap: 10px; padding-bottom: 12px; }
.volume { display: flex; align-items: center; gap: 8px; width: min(100%, 420px); }
.volume input { flex: 1; accent-color: var(--accent); min-height: 32px; }
.vol-icon { font-size: 0.8rem; opacity: 0.6; }
hr { width: min(100%, 420px); border: 0; border-top: 1px solid var(--line); margin: 0; }
.devices { display: flex; flex-direction: column; gap: 6px; width: min(100%, 520px); }
.device { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; flex-wrap: wrap; }
.device.empty { justify-content: center; }
.device .dot { width: 7px; height: 7px; border-radius: 50%; background: #34c759; box-shadow: 0 0 5px rgba(52, 199, 89, 0.6); }
.device .dot.off { background: rgba(255, 59, 48, 0.6); box-shadow: none; }
.device .name { flex: 1; min-width: 8em; overflow-wrap: anywhere; }
.device .notes { width: 100%; padding-left: 15px; color: var(--muted); font-weight: 600; }
.transpose { display: flex; align-items: center; gap: 4px; }
.transpose span { min-width: 2.2em; text-align: center; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.8rem; }
.transpose button { border-radius: 50%; }
.small-btn { padding: 0 16px; font-size: 0.85rem; min-height: 40px; }
footer { font-size: 0.72rem; color: var(--muted); text-align: center; line-height: 1.8; }
footer a { color: var(--link); }
.credits { font-size: 0.68rem; }

/* Landscape phone: the keyboard must be on screen without scrolling. */
@media (orientation: landscape) and (max-height: 500px) {
  .logo.small { display: none; }
  .display { min-height: 0; flex: 0 0 auto; padding-block: 4px; }
  .label { font-size: 1.8rem; }
  .kb { height: max(140px, calc(100dvh - 200px)); }
  .hint { display: none; }
}
