:root {
  --bg: #000;
  --fg: #fff;
  --accent: #6200EE;
  --accent-dark: #3700B3;
  --accent-2: #03DAC5;
  --highlight-key: #A9DF91;
  --button-bg: #1E1E1E;
  --button-bg-active: #4A2FBD;
  --tick-line: rgba(255, 255, 255, 0.27);
  --modal-overlay: rgba(0, 0, 0, 0.75);
  --tabbar-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  color: inherit;
  background: transparent;
  border: none;
  cursor: pointer;
}

#phone-frame {
  position: fixed;
  inset: 0;
  overflow: hidden;
  container-type: inline-size;
  container-name: app;
}

#app {
  position: absolute;
  inset: 0;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom));
  overflow: hidden;
}

.view {
  position: absolute;
  inset: 0;
  display: none;
  overflow: hidden;
}
.view.active { display: flex; }

/* ---------- Bottom tab bar ---------- */
#tabbar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: #111;
  border-top: 1px solid #222;
  z-index: 50;
}

/* ---------- Top-right action button (install) ---------- */
#topbar-actions {
  position: fixed;
  top: 8px;
  right: 8px;
  z-index: 1000;
  display: flex;
  gap: 6px;
  align-items: center;
}
#topbar-actions button {
  height: 36px;
  border-radius: 8px;
  background: rgba(30, 30, 30, 0.85);
  border: 1px solid #333;
  color: #aaa;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 100ms ease, color 100ms ease;
}
#topbar-actions button:hover { background: #2A2A2A; color: #fff; }

#install-btn {
  padding: 0 12px;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
#install-btn:hover { background: var(--accent-dark); color: #fff; }
#install-btn.hidden { display: none; }

/* ---------- iOS install instruction sheet ---------- */
.ios-sheet {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: var(--modal-overlay);
  z-index: 1100;
  padding: 0;
}
.ios-sheet.hidden { display: none; }
.ios-sheet-card {
  position: relative;
  background: #1A1A1A;
  border-top: 1px solid #2A2A2A;
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 480px;
  padding: 22px 22px calc(22px + var(--safe-bottom, 0px));
}
.ios-sheet-card h2 { margin: 0 0 12px; font-size: 18px; }
.ios-sheet-card p { font-size: 14.5px; line-height: 1.5; }
.ios-steps {
  margin: 12px 0;
  padding-left: 22px;
  font-size: 14.5px;
  line-height: 1.65;
}
.ios-steps li { margin-bottom: 8px; }
.ios-steps .inline-icon {
  vertical-align: middle;
  margin: 0 2px;
  color: var(--accent-2);
}
.ios-sheet-note { font-size: 13px; color: #aaa; margin: 6px 0 0; }

/* ---------- Bottom tab buttons ---------- */
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: #aaa;
  padding: 6px 2px;
  font-size: 11px;
  transition: color 120ms ease, background 120ms ease;
}
.tab.active { color: var(--accent-2); background: rgba(98, 0, 238, 0.18); }
.tab-icon { width: 22px; height: 22px; }
.tab-label { font-weight: 500; letter-spacing: 0.2px; }

/* ---------- Modal ---------- */
.modal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--modal-overlay);
  z-index: 100;
  padding: 16px;
}
.modal.hidden { display: none; }
.modal-card {
  position: relative;
  background: #1A1A1A;
  border: 1px solid #2A2A2A;
  border-radius: 12px;
  max-width: 480px;
  width: 100%;
  max-height: 90%;
  overflow-y: auto;
  padding: 20px;
}
.modal-close {
  position: absolute;
  top: 6px;
  right: 10px;
  font-size: 26px;
  line-height: 1;
  color: #ccc;
  padding: 6px 10px;
  border-radius: 6px;
}
.modal-close:hover { background: #2A2A2A; color: #fff; }
.welcome-card h2 { margin-top: 0; font-size: 20px; }
.welcome-card p { line-height: 1.45; font-size: 14.5px; }
.welcome-dont-show {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: 14px;
  cursor: pointer;
}

/* ---------- Easy Pitch view ---------- */
.easy-pitch {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 12px;
  width: 100%;
  height: 100%;
  padding: 12px;
}
.solfege-strip {
  display: grid;
  grid-template-rows: 44px repeat(8, 1fr);
  gap: 6px;
}
.solfege-strip .octave-toggle {
  background: var(--button-bg);
  border: 1px solid #333;
  border-radius: 8px;
  font-size: 22px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
}
.solfege-btn {
  background: var(--button-bg);
  border: 1px solid #333;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 100ms ease, border-color 100ms ease;
}
.solfege-btn.activated {
  background: var(--button-bg-active);
  border-color: var(--accent);
  color: #fff;
}

.note-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 8px;
  height: 100%;
}
.note-btn {
  background: var(--button-bg);
  border: 1px solid #333;
  border-radius: 10px;
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: background 80ms ease, transform 80ms ease;
  touch-action: none;
}
.note-btn:active { transform: scale(0.97); }
.note-btn.pressed { background: var(--accent-dark); border-color: var(--accent); }
.note-btn.highlighted { background: var(--highlight-key); color: #000; border-color: #6FCB55; }
.note-btn.highlighted.pressed { background: #7FC065; }
.note-btn .accidental {
  font-size: 0.7em;
  vertical-align: super;
  line-height: 1;
}
.note-btn .alt {
  font-size: 0.6em;
  opacity: 0.6;
  margin-left: 2px;
}
.note-btn.help-btn {
  grid-column: span 2;
  background: var(--accent-dark);
  border-color: var(--accent);
  font-size: 18px;
  font-weight: 600;
}

/* Landscape: collapse to 4x4 with horizontal solfège strip */
@media (orientation: landscape) and (max-height: 560px) {
  .easy-pitch {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 70px;
  }
  .solfege-strip {
    grid-template-rows: 1fr;
    grid-template-columns: 60px repeat(8, 1fr);
    grid-row: 2;
    height: 100%;
  }
  .note-grid {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
  }
}

/* ---------- Wizard dialog ---------- */
.wizard-card { padding: 24px 20px 20px; min-height: 280px; }
.wizard-card h3 { margin: 4px 0 12px; font-size: 18px; }
.wizard-card p { font-size: 14.5px; line-height: 1.45; }
.wizard-card img { display: block; max-width: 100%; max-height: 50vh; margin: 12px auto; }
.wizard-card .reference-img { filter: brightness(0) invert(1); max-height: 80px; }
.wizard-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.wizard-buttons.split { justify-content: space-between; }
.wizard-btn {
  padding: 10px 20px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  border: none;
  min-width: 80px;
}
.wizard-btn.secondary { background: #333; }
.wizard-btn:disabled { opacity: 0.4; cursor: default; }

.wizard-heading {
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 12px;
}
.wizard-body {
  text-align: center;
  font-size: 14.5px;
  margin: 0 0 16px;
}
.wizard-subtle {
  text-align: center;
  font-size: 13px;
  color: #aaa;
  margin: 0 0 16px;
}

.sharps-flats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 16px 0 24px;
}
.sf-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.sf-label {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}
.sf-col .reference-img {
  width: 56px;
  height: 56px;
  object-fit: contain;
}
.sf-select {
  background: #2A2A2A;
  color: #fff;
  border: 1px solid #444;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 18px;
  width: 100%;
  text-align: center;
}

.detected-key {
  font-size: 48px;
  text-align: center;
  font-weight: 700;
  margin: 18px 0;
  color: var(--accent-2);
}

.shape-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 8px;
}
.shape-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 4px;
  background: var(--button-bg);
  border: 1px solid #333;
  border-radius: 8px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  transition: background 80ms ease, border-color 80ms ease;
}
.shape-btn:hover { background: #2A2A2A; border-color: #555; }
.shape-btn:active { background: var(--accent-dark); }
.shape-btn svg { display: block; }

.result-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  margin: 10px 0;
  justify-content: center;
}
.result-row .result-label { color: #aaa; }
.result-row .result-shape { display: inline-flex; color: #fff; }

.solfege-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.solfege-picker .solfege-btn {
  padding: 14px 0;
  background: var(--button-bg);
  border-radius: 6px;
  border: 1px solid #333;
}

/* ---------- Advanced Pitch view ---------- */
.advanced-pitch {
  display: grid;
  grid-template-columns: 110px 1fr;
  grid-template-rows: minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  height: 100%;
  padding: 12px;
}
.advanced-right {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) 80px;
  gap: 12px;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}
.adv-carousel-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border: 1px solid #222;
  border-radius: 10px;
  background: #0A0A0A;
  overflow: hidden;
}
.adv-carousel {
  height: 100%;
  width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.adv-carousel::-webkit-scrollbar { display: none; }
.adv-spacer {
  height: 0;
  width: 100%;
  flex-shrink: 0;
  pointer-events: none;
}
.adv-item {
  scroll-snap-align: center;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--fg);
  transition: opacity 100ms linear;
}
/* DEBUG readout — leave in place but hidden; flip to block to re-enable if needed.
.adv-debug {
  position: absolute;
  left: 4px;
  bottom: 4px;
  right: 4px;
  z-index: 5;
  font-size: 10px;
  font-family: monospace;
  color: #03DAC5;
  background: rgba(0,0,0,0.7);
  padding: 2px 4px;
  border-radius: 4px;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
}
*/
.adv-debug { display: none; }
.adv-overlay {
  position: absolute;
  left: 0; right: 0;
  height: 80px;
  pointer-events: none;
  z-index: 2;
}
.adv-overlay.top {
  top: 0;
  background: linear-gradient(to bottom, rgba(10,10,10,0.95), rgba(10,10,10,0));
}
.adv-overlay.bot {
  bottom: 0;
  background: linear-gradient(to top, rgba(10,10,10,0.95), rgba(10,10,10,0));
}
.adv-center-line {
  position: absolute;
  left: 12px; right: 12px;
  top: 50%;
  border-top: 1px dashed var(--tick-line);
  pointer-events: none;
  z-index: 1;
}
.adv-play-btn {
  background: var(--accent);
  color: #fff;
  border-radius: 50px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  border: none;
  touch-action: none;
}
.adv-play-btn.pressed { background: var(--accent-dark); }

/* ---------- Conducting view ---------- */
.conductor {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding: 12px;
  gap: 10px;
}
.conductor h1 { margin: 0; font-size: 22px; text-align: center; }
.conductor-canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.conductor-canvas-wrap canvas {
  display: block;
  background: #050505;
  border-radius: 12px;
  border: 1px solid #1F1F1F;
  width: 100%;
  height: 100%;
  max-width: 600px;
  max-height: 600px;
  aspect-ratio: 1 / 1;
}
.conductor-controls {
  background: #111;
  border: 1px solid #222;
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}
.conductor-controls .bpm-row { flex: 1 1 180px; min-width: 0; }
.bpm-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.bpm-row .bpm-display {
  font-size: 16px;
  font-weight: 700;
}
.bpm-row input[type=range] { width: 100%; }
.time-sig {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 18px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 8px;
  background: #1E1E1E;
  border: 1px solid #333;
}
.time-sig .num, .time-sig .den { line-height: 1; }
.time-sig .bar {
  width: 22px;
  border-top: 2px solid #fff;
  margin: 2px 0;
}
.conduct-in {
  padding: 8px 14px;
  background: #1E1E1E;
  border: 1px solid #333;
  border-radius: 8px;
  font-size: 14px;
}
.play-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}
.play-btn.playing { background: #B00020; }
.popup-menu {
  position: fixed;
  background: #1E1E1E;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 6px;
  z-index: 200;
  min-width: 90px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
}
.popup-menu button {
  display: block;
  width: 100%;
  padding: 8px 10px;
  text-align: left;
  border-radius: 4px;
  font-size: 14px;
}
.popup-menu button:hover { background: #2A2A2A; }

/* ---------- Guide view ---------- */
.guide {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000;
}
.guide-img-wrap {
  position: absolute;
  inset: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.guide-img-wrap img {
  width: 100%;
  height: 100%;
  max-width: 800px;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}
.guide-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 56px;
  height: 56px;
  background: rgba(0, 0, 0, 0.27);
  color: #fff;
  font-size: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 500ms ease;
  pointer-events: none;
  z-index: 10;
}
.guide-arrow.visible {
  opacity: 1;
  pointer-events: auto;
  transition-duration: 300ms;
}
.guide-arrow.left { left: 12px; }
.guide-arrow.right { right: 12px; }

/* ---------- Simple Pitch Pipe ---------- */
.simple-view {
  flex: 1;
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 12px;
  padding: 12px;
  width: 100%;
  height: 100%;
  min-height: 0;
}
.simple-solfege-strip {
  display: grid;
  grid-template-rows: 44px repeat(8, 1fr);
  gap: 6px;
  min-height: 0;
}
.simple-solfege-strip .octave-toggle {
  background: var(--button-bg);
  border: 1px solid #333;
  border-radius: 8px;
  font-size: 22px;
  font-weight: bold;
  color: var(--fg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.simple-solfege-strip .solfege-btn {
  color: var(--fg);
  cursor: pointer;
}
.simple-circle-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-height: 0;
}
.simple-circle {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.simple-wedge {
  fill: var(--button-bg);
  stroke: #000;
  stroke-width: 2;
  cursor: pointer;
  transition: fill 80ms ease;
}
.simple-wedge:hover { fill: #2A2A2A; }
.simple-wedge.pressed {
  fill: var(--accent-dark);
  stroke: var(--accent);
}
.simple-help { cursor: pointer; }
.simple-help-bg {
  fill: var(--accent-dark);
  stroke: var(--accent);
  stroke-width: 3;
  transition: fill 100ms ease;
}
.simple-help:hover .simple-help-bg,
.simple-help:focus .simple-help-bg { fill: var(--accent); }
.simple-help:focus { outline: none; }
.simple-help:focus .simple-help-bg { stroke: var(--accent-2); }
.simple-help-label {
  fill: #fff;
  font-size: 28px;
  font-weight: 700;
  pointer-events: none;
  font-family: inherit;
}
.simple-label {
  fill: var(--fg);
  font-size: 30px;
  font-weight: 600;
  font-family: inherit;
  dominant-baseline: central;
}
.simple-label-acc {
  font-size: 18px;
  font-weight: 500;
}
.simple-oct { font-size: 0.55em; fill: var(--accent-2); }
.simple-hint {
  font-size: 13px;
  color: #888;
}

/* Landscape: strip becomes a horizontal bar under the circle */
@media (orientation: landscape) and (max-height: 560px) {
  .simple-view {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 70px;
    gap: 8px;
    padding: 8px;
  }
  .simple-circle-wrap { grid-row: 1; }
  .simple-solfege-strip {
    grid-row: 2;
    grid-template-rows: 1fr;
    grid-template-columns: 60px repeat(8, 1fr);
    height: 100%;
  }
}

/* ---------- Misc ---------- */
.help-example-img { max-width: 100%; max-height: 60vh; }
.what-note-img { max-width: 100%; max-height: 50vh; }

/* ---------- Container queries: narrow layouts ---------- */
@container app (max-width: 480px) {
  .easy-pitch, .advanced-pitch {
    grid-template-columns: 76px 1fr;
    gap: 8px;
    padding: 8px;
  }
  .simple-view {
    grid-template-columns: 44px 1fr;
    gap: 6px;
    padding: 8px;
  }
  .simple-solfege-strip .octave-toggle { font-size: 18px; }
  .solfege-strip .octave-toggle { font-size: 18px; }
  .solfege-btn { font-size: 13px; }
  .note-btn { font-size: 18px; border-radius: 8px; }
  .note-btn.help-btn { font-size: 14px; }
  .adv-item { font-size: 19px; height: 56px; }
  .conductor { padding: 8px; gap: 8px; }
  .conductor h1 { font-size: 18px; }
  .conductor-controls { padding: 8px; gap: 10px; }
  .play-btn { width: 48px; height: 48px; font-size: 18px; }
  .tab-label { font-size: 10px; }
  .tab-icon { width: 20px; height: 20px; }
}

@container app (max-width: 360px) {
  .easy-pitch, .advanced-pitch {
    grid-template-columns: 64px 1fr;
  }
  .simple-view {
    grid-template-columns: 40px 1fr;
  }
  .solfege-btn { font-size: 12px; }
  .note-btn { font-size: 16px; }
}
