/* Circle of Fifths — mobile app shell (Fibidrop-adjacent palette). */

:root {
  --bg: #0c0e1a;
  --bg2: #171334;
  --gold: #e8c46b;
  --gold-dim: #b8954a;
  --cream: #f5e9c8;
  --muted: #b9bdd6;
  --panel: #12152a;
  --border: rgba(245, 233, 200, 0.18);
  --chord: #f0a0a0;
  --mode: #c8d4f0;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body.app {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(180deg, var(--bg), var(--bg2));
  color: var(--cream);
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body.home {
  overflow: hidden;
}

body.home .app-shell {
  overflow: visible;
  max-width: none; /* use full phone width in portrait */
}

a {
  color: var(--gold);
  text-decoration: none;
}

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  height: 100dvh;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 0.25rem 0.35rem 0.4rem;
}

.app-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.2rem 0.1rem 0.35rem;
}

.app-brand {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 0.02em;
}

.app-bar-btn,
.menu-close {
  min-height: 40px;
  padding: 0.4rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(232, 196, 107, 0.08);
  color: var(--cream);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.app-bar-btn:active,
.menu-close:active {
  background: rgba(232, 196, 107, 0.18);
}

.stage-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.25rem;
  padding: 0.1rem 0.2rem 0.15rem;
  overflow: visible;
}

/* Strip under the header for A aeolian = C ionian etc. */
.play-caption-band {
  flex: 0 0 2.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 2.35rem;
}

.stage-cluster {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 0.3rem;
  /* Room above the panel so the Ionian halo isn’t clipped */
  padding-top: 0.85rem;
  overflow: visible;
}

.stage {
  position: relative;
  width: min(100%, calc(100dvh - 17.35rem));
  max-height: min(100%, calc(100dvh - 17.35rem));
  aspect-ratio: 1;
  flex: 0 1 auto;
  border-radius: 16px;
  border: 1px solid var(--border);
  background:
    radial-gradient(circle at 50% 42%, rgba(232, 196, 107, 0.07), transparent 55%),
    var(--panel);
  overflow: visible;
  touch-action: none;
  user-select: none;
}

.stage-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.guide-ring {
  fill: none;
  stroke: rgba(245, 233, 200, 0.07);
  stroke-width: 0.35;
}

.divider {
  stroke: rgba(245, 233, 200, 0.92);
  stroke-width: 1.1;
  stroke-linecap: round;
}

.ring {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ring-notes {
  transition: transform 320ms cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}

/* —— Note seeds (Fibidrop-like orbs) —— */

.note-seed {
  position: absolute;
  width: 10.5%;
  height: 10.5%;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  pointer-events: auto;
  cursor: pointer;
  color: var(--bg);
  font-weight: 700;
  font-size: clamp(0.65rem, 3.3vw, 0.95rem);
  font-family: inherit;
  line-height: 1;
  background:
    radial-gradient(circle at 32% 28%, #fff8e8 0%, var(--gold) 38%, var(--gold-dim) 78%, #6a4e22 100%);
  box-shadow:
    0 0 0 1px rgba(255, 240, 200, 0.25),
    0 4px 14px rgba(0, 0, 0, 0.45),
    inset 0 -3px 6px rgba(0, 0, 0, 0.25);
  transform: translate(-50%, -50%);
  transition: filter 120ms ease, box-shadow 120ms ease;
  z-index: 3;
}

.note-seed:active {
  filter: brightness(1.08);
}

.note-seed.is-top {
  box-shadow:
    0 0 0 2px rgba(255, 240, 200, 0.55),
    0 0 18px rgba(232, 196, 107, 0.45),
    0 4px 14px rgba(0, 0, 0, 0.45),
    inset 0 -3px 6px rgba(0, 0, 0, 0.25);
}

.note-seed.is-flash {
  z-index: 4;
  animation: note-flash 0.42s ease-out;
}

@keyframes note-flash {
  0% {
    filter: brightness(1.55);
    box-shadow:
      0 0 0 3px rgba(255, 248, 220, 0.85),
      0 0 22px rgba(232, 196, 107, 0.75),
      0 4px 14px rgba(0, 0, 0, 0.45),
      inset 0 -3px 6px rgba(0, 0, 0, 0.25);
    transform: translate(-50%, -50%) scale(1.28);
  }
  100% {
    filter: brightness(1);
    transform: translate(-50%, -50%) scale(1);
  }
}

/* Counter-rotate label so letters stay upright while the ring spins */
.note-seed > span {
  display: block;
  transform: rotate(calc(-1 * var(--ring-rot, 0deg)));
}

/* —— Chord / mode labels —— */

.chord-label,
.mode-label {
  position: absolute;
  pointer-events: auto;
  margin: 0;
  padding: 0.12rem 0.2rem;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.chord-label {
  transform: translate(-50%, -50%) rotate(var(--a, 0deg)) translateX(0.35em) rotate(calc(-1 * var(--a, 0deg)));
  color: var(--chord);
  font-size: clamp(0.52rem, 2.3vw, 0.7rem);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.95;
  z-index: 2;
}

.mode-label {
  transform: translate(-50%, -50%);
  color: var(--mode);
  font-size: clamp(0.48rem, 1.9vw, 0.65rem);
  font-weight: 500;
  letter-spacing: 0;
  /* Below note seeds so overlapping taps hit notes, not mode links */
  z-index: 2;
  text-shadow: 0 0 8px rgba(12, 14, 26, 0.95), 0 1px 2px rgba(12, 14, 26, 0.9);
}

.chord-label:active,
.mode-label:active {
  color: var(--gold);
}

.hint {
  flex: 0 0 auto;
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
  opacity: 0.85;
}

.circle-toggles {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
  width: min(100%, 26rem);
}

.circle-toggles .menu-segment {
  flex: 1 1 7.5rem;
  min-width: 7rem;
}

.circle-toggles .menu-segment-btn {
  min-height: 36px;
  font-size: 0.82rem;
  padding: 0.3rem 0.45rem;
}

.play-focus-btn {
  flex: 0 0 auto;
  min-width: 4.6rem;
}

.play-focus-btn.is-active {
  border-color: rgba(232, 196, 107, 0.55);
  background: rgba(232, 196, 107, 0.18);
  color: var(--gold);
}

/* Play mode: notes surge forward over modes/chords */
.stage.play-focus .ring-notes {
  z-index: 8;
}

.stage.play-focus .note-seed,
body.play-focus .stage .note-seed {
  width: 20% !important;
  height: 20% !important;
  font-size: clamp(0.9rem, 4.5vw, 1.25rem) !important;
  z-index: 9;
  box-shadow:
    0 0 0 2px rgba(255, 240, 200, 0.4),
    0 12px 32px rgba(0, 0, 0, 0.6),
    inset 0 -3px 6px rgba(0, 0, 0, 0.25);
  transition:
    width 420ms cubic-bezier(0.22, 1, 0.36, 1),
    height 420ms cubic-bezier(0.22, 1, 0.36, 1),
    font-size 420ms ease,
    left 420ms cubic-bezier(0.22, 1, 0.36, 1),
    top 420ms cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 420ms ease,
    filter 120ms ease;
}

.stage.play-focus .mode-label,
.stage.play-focus .chord-label,
.stage.play-focus .home-mode-mark,
body.play-focus .stage .mode-label,
body.play-focus .stage .chord-label,
body.play-focus .stage .home-mode-mark {
  opacity: 0.18;
  pointer-events: none;
  transition: opacity 320ms ease;
}

.stage:not(.play-focus) .mode-label,
.stage:not(.play-focus) .chord-label,
.stage:not(.play-focus) .home-mode-mark {
  transition: opacity 320ms ease;
}

.stage:not(.play-focus) .note-seed {
  transition:
    width 420ms cubic-bezier(0.22, 1, 0.36, 1),
    height 420ms cubic-bezier(0.22, 1, 0.36, 1),
    font-size 420ms ease,
    left 420ms cubic-bezier(0.22, 1, 0.36, 1),
    top 420ms cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 420ms ease,
    filter 120ms ease;
}

.play-caption {
  width: min(100%, 22rem);
  text-align: center;
  pointer-events: none;
}

.play-caption[hidden] {
  display: none !important;
}

.play-caption-line {
  margin: 0;
  font-size: clamp(0.78rem, 3.4vw, 1rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--gold);
  text-shadow: 0 1px 8px rgba(8, 10, 20, 0.85);
  line-height: 1.25;
}

.play-caption-secondary {
  margin-top: 0.15rem;
  font-weight: 600;
  color: rgba(245, 233, 200, 0.92);
}

.player-bar {
  flex: 0 0 auto;
  width: min(100%, 26rem);
  margin-top: 0.15rem;
  padding: 0.55rem 0.65rem 0.45rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(232, 196, 107, 0.06);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.player-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.65rem;
}

.player-field {
  flex: 1 1 6.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.player-field select {
  min-height: 40px;
  padding: 0.35rem 0.5rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(12, 14, 26, 0.85);
  color: var(--cream);
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
}

.player-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.player-btn {
  flex: 1 1 auto;
  min-height: 40px;
  padding: 0.4rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(232, 196, 107, 0.14);
  color: var(--cream);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.player-btn:active {
  background: rgba(232, 196, 107, 0.26);
}

.player-btn-quiet {
  flex: 0 0 auto;
  background: transparent;
  color: var(--muted);
}

.player-status {
  margin: 0;
  min-height: 1.1em;
  font-size: 0.75rem;
  line-height: 1.35;
  color: rgba(245, 233, 200, 0.72);
}

/* —— App menu —— */

.app-menu {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: max(12px, var(--safe-bottom)) 12px 12px;
  background: rgba(8, 10, 20, 0.72);
}

.app-menu[hidden] {
  display: none !important;
}

.app-menu-panel {
  width: min(400px, 100%);
  border-radius: 16px 16px 14px 14px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #1a1e35, var(--panel));
  padding: 1.1rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.app-menu-brand {
  margin: 0;
  color: var(--gold);
  font-weight: 600;
  font-size: 1.15rem;
}

.app-menu-tag {
  margin: 0 0 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.menu-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.menu-link {
  display: block;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  border: 1px solid transparent;
  background: rgba(245, 233, 200, 0.04);
  color: var(--cream);
  font-weight: 600;
  font-size: 0.95rem;
}

.menu-link.current,
.menu-link:active {
  border-color: rgba(232, 196, 107, 0.35);
  background: rgba(232, 196, 107, 0.12);
  color: var(--gold);
}

.menu-close {
  margin-top: 0.35rem;
  width: 100%;
}

.menu-settings {
  margin-top: 0.25rem;
  padding: 0.7rem 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(232, 196, 107, 0.06);
}

.menu-settings-title {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--gold);
}

.menu-settings-hint {
  margin: 0.25rem 0 0.55rem;
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--muted);
}

.menu-segment {
  display: flex;
  gap: 0.35rem;
}

.menu-segment-btn {
  flex: 1 1 0;
  min-height: 40px;
  padding: 0.4rem 0.5rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(12, 14, 26, 0.55);
  color: var(--cream);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.menu-segment-btn.is-active {
  border-color: rgba(232, 196, 107, 0.55);
  background: rgba(232, 196, 107, 0.18);
  color: var(--gold);
}

.home-mode-mark {
  position: absolute;
  width: 14%;
  height: 14%;
  margin: 0;
  border-radius: 50%;
  border: 2px solid rgba(232, 196, 107, 0.85);
  box-shadow:
    0 0 0 1px rgba(255, 248, 220, 0.2),
    0 0 14px rgba(232, 196, 107, 0.35);
  background: radial-gradient(
    circle at 50% 50%,
    rgba(232, 196, 107, 0.16),
    transparent 68%
  );
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 3;
}

/* —— Content pages (same app chrome) —— */

body.app:not(.home) {
  overflow: auto;
}

body.app:not(.home) .app-shell {
  height: auto;
  min-height: 100dvh;
  max-width: 40rem;
}

.content-page {
  padding: 0.25rem 0.15rem 2rem;
}

.content-page h1 {
  margin: 0 0 0.85rem;
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--gold);
}

.content-page h2 {
  margin: 1.4rem 0 0.5rem;
  font-size: 1.05rem;
  color: var(--cream);
}

.content-page p,
.content-page li {
  color: rgba(245, 233, 200, 0.88);
  line-height: 1.5;
  font-size: 0.95rem;
}

.content-page a {
  color: var(--gold);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.content-page ul,
.content-page ol {
  padding-left: 1.25rem;
}

.tonic-picker {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin: 0.85rem 0 1rem;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(232, 196, 107, 0.06);
}

.tonic-picker label,
.tonic-picker-mode {
  margin: 0;
  color: rgba(245, 233, 200, 0.9);
  font-size: 0.9rem;
  font-weight: 600;
}

.tonic-picker-mode {
  color: var(--gold);
}

.tonic-picker select {
  min-height: 40px;
  min-width: 4.5rem;
  padding: 0.35rem 0.55rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(12, 14, 26, 0.85);
  color: var(--cream);
  font-size: 0.95rem;
  font-weight: 600;
}

.tonic-picker select:focus {
  outline: 2px solid rgba(232, 196, 107, 0.45);
  outline-offset: 2px;
}

.back-home {
  margin-top: 1.75rem;
}

.back-home a {
  display: inline-block;
  padding: 0.55rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(232, 196, 107, 0.08);
  color: var(--cream);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}
