:root {
  color-scheme: dark;
  --bg: #101114;
  --panel: #1a1d22;
  --panel-2: #242831;
  --text: #f7f1e7;
  --muted: #a8adb7;
  --line: rgba(255, 255, 255, 0.12);
  --accent: #14b8a6;
  --accent-2: #f59e0b;
  --danger: #fb7185;
  --key-white: #f2ece2;
  --key-black: #16181d;
  --key-text: #15171b;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(20, 184, 166, 0.18), transparent 32rem),
    linear-gradient(135deg, #101114, #151820 54%, #0e1116);
  color: var(--text);
}

body {
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

button {
  font: inherit;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.phone-shell {
  width: min(100vw, 460px);
  height: min(100vh, 920px);
  height: min(100svh, 920px);
  height: min(100dvh, 920px);
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  background: rgba(16, 17, 20, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.42);
  overflow: hidden;
}

.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(clamp(10px, 2dvh, 16px), env(safe-area-inset-top)) 18px clamp(6px, 1.2dvh, 10px);
}

.eyebrow,
.panel-label {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.2;
}

.screen-dots {
  display: flex;
  gap: 8px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
}

.dot.active {
  background: var(--accent);
}

.workspace {
  min-height: 0;
  overflow: hidden;
}

.screen-track {
  height: 100%;
  display: flex;
  transform: translateX(0);
  transition: transform 220ms ease;
}

.screen {
  width: 100%;
  flex: 0 0 100%;
  padding: clamp(4px, 1dvh, 8px) 16px clamp(8px, 1.6dvh, 14px);
  min-height: 0;
  overflow: auto;
}

.current-panel {
  min-height: 100%;
  display: grid;
  align-content: center;
  gap: 10px;
}

.current-code {
  font-size: clamp(3.4rem, 16vw, 5.4rem);
  font-weight: 900;
  line-height: 0.95;
  color: var(--text);
  overflow-wrap: anywhere;
}

.current-sub {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
}

.reason-panel {
  min-height: 70px;
  padding: 14px;
  display: flex;
  align-items: center;
  background: linear-gradient(135deg, rgba(20, 184, 166, 0.14), rgba(245, 158, 11, 0.09));
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #efe8dc;
  font-size: 0.94rem;
  line-height: 1.55;
}

.reason-panel.has-relations {
  max-height: 170px;
  display: block;
  overflow-y: auto;
}

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

.relation-item {
  display: grid;
  gap: 3px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.relation-item:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.relation-label {
  color: var(--accent-2);
  font-size: 0.78rem;
  font-weight: 850;
}

.relation-reason {
  color: #efe8dc;
  font-size: 0.86rem;
  line-height: 1.45;
}

.relation-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.stage-status-panel {
  min-height: 100%;
  display: grid;
  grid-template-rows: 1fr;
}

.nav-button,
.modifier-button,
.primary-button,
.quality-button,
.stage-chord-button {
  border-radius: 8px;
  min-height: 44px;
}

.stage-status-body {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 8px;
}

.stage-current-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stage-relations-toggle {
  flex: 0 0 auto;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 800;
}

.stage-relations-toggle-icon {
  width: 1em;
  color: var(--accent);
  text-align: center;
}

.stage-current-code {
  color: var(--text);
  font-size: clamp(3.2rem, 15vw, 5rem);
  font-weight: 900;
  line-height: 0.95;
  overflow-wrap: anywhere;
}

.stage-current-sub {
  min-width: 0;
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
}

.stage-relations {
  max-height: 150px;
  margin-top: 6px;
  padding: 10px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
}

.control-area {
  border-top: 1px solid var(--line);
  background: rgba(12, 13, 16, 0.9);
}

.control-panel {
  padding: clamp(8px, 1.2dvh, 10px) 10px;
}

[hidden] {
  display: none !important;
}

.root-roll,
.bass-roll,
.tension-roll {
  position: relative;
  height: clamp(76px, 12dvh, 92px);
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  margin-bottom: clamp(7px, 1.2dvh, 10px);
}

.key {
  position: relative;
  display: flex;
  align-items: end;
  justify-content: center;
  padding: 0 2px 9px;
  border: 1px solid rgba(0, 0, 0, 0.16);
  border-radius: 0 0 7px 7px;
  font-weight: 850;
}

.white-key {
  background: var(--key-white);
  color: var(--key-text);
}

.black-key {
  z-index: 2;
  position: absolute;
  top: 0;
  width: 9%;
  height: 58%;
  transform: translateX(-50%);
  background: var(--key-black);
  color: #f6f1e9;
  font-size: 0.72rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0 0 6px 6px;
  padding-bottom: 6px;
}

.key.selected,
.quality-button.selected {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.key.recommended,
.quality-button.recommended {
  box-shadow: inset 0 0 0 3px rgba(245, 158, 11, 0.72);
}

.key.recommended.selected,
.quality-button.recommended.selected {
  box-shadow: inset 0 0 0 3px rgba(245, 158, 11, 0.78), 0 0 0 3px rgba(20, 184, 166, 0.44);
}

.key:disabled {
  cursor: default;
}

.tension-key:disabled {
  opacity: 0.58;
}

.tension-key.root-marker {
  color: var(--accent);
}

.quality-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
}

.quality-button {
  min-width: 0;
  min-height: clamp(40px, 5.4dvh, 44px);
  padding: 0 6px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 0.94rem;
  font-weight: 820;
}

.modifier-row {
  display: grid;
  grid-template-columns: minmax(0, 0.7fr) minmax(0, 1.3fr);
  gap: 8px;
  margin-top: clamp(7px, 1.2dvh, 10px);
}

.modifier-button {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  padding: 0 8px;
  background: #303641;
  color: var(--text);
  font-weight: 850;
  min-height: clamp(40px, 5.4dvh, 44px);
}

.modifier-button.open {
  background: rgba(20, 184, 166, 0.2);
  outline: 2px solid rgba(20, 184, 166, 0.7);
}

.modifier-label {
  flex: 0 0 auto;
}

.modifier-bubbles {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
}

.modifier-bubble {
  flex: 0 0 auto;
  min-width: 24px;
  padding: 3px 6px;
  border-radius: 999px;
  background: rgba(20, 184, 166, 0.22);
  color: #99f6e4;
  font-size: 0.75rem;
  font-weight: 900;
  line-height: 1;
  text-align: center;
}

.modifier-chevron {
  flex: 0 0 auto;
  width: 1em;
  margin-left: auto;
  color: var(--accent);
  text-align: center;
}

.modifier-accordion {
  position: relative;
  max-height: 0;
  margin-top: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  visibility: hidden;
  transition:
    max-height 220ms ease,
    margin-top 220ms ease,
    opacity 160ms ease,
    visibility 0s linear 220ms;
}

.modifier-accordion.open {
  max-height: 100px;
  margin-top: clamp(7px, 1.2dvh, 10px);
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  transition-delay: 0s;
}

.modifier-panel-actions {
  position: absolute;
  z-index: 5;
  top: 4px;
  right: 4px;
}

.modifier-clear-button {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid #fb7185;
  border-radius: 50%;
  background: #fb7185;
  color: #2a0b13;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.34);
}

.modifier-clear-button:disabled {
  border-color: rgba(255, 255, 255, 0.14);
  background: #30343c;
  color: #777d88;
  cursor: default;
  opacity: 1;
  box-shadow: none;
}

.bass-roll {
  min-height: 0;
  margin-bottom: 0;
}

.tension-roll {
  min-height: 0;
  margin-bottom: 0;
}

.bass-roll::before {
  content: "on";
  position: absolute;
  z-index: 3;
  left: 8px;
  top: 8px;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(20, 184, 166, 0.9);
  color: #06201d;
  font-size: 0.72rem;
  font-weight: 900;
}

.tension-roll::before {
  content: "T";
  position: absolute;
  z-index: 3;
  left: 8px;
  top: 8px;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(245, 158, 11, 0.92);
  color: #241505;
  font-size: 0.72rem;
  font-weight: 900;
}

.stage-controls {
  height: clamp(240px, 48dvh, 410px);
  grid-template-rows: auto 1fr;
  gap: 10px;
  transition: height 220ms ease;
}

.stage-controls.relations-collapsed {
  height: clamp(300px, 62dvh, 550px);
}

.stage-controls:not([hidden]) {
  display: grid;
}

.stage-controls-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.stage-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stage-count {
  min-width: 28px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(20, 184, 166, 0.16);
  color: var(--accent);
  text-align: center;
}

.clear-stage-button {
  min-height: 32px;
  padding: 0 9px;
  border: 1px solid rgba(251, 113, 133, 0.38);
  border-radius: 6px;
  background: rgba(251, 113, 133, 0.1);
  color: #fecdd3;
  font-size: 0.875rem;
  font-weight: 800;
}

.clear-stage-button:disabled {
  border-color: var(--line);
  background: transparent;
  color: var(--muted);
  cursor: default;
  opacity: 0.5;
}

.stage-list {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-content: start;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.empty-state {
  grid-column: 1 / -1;
  margin: 22px 8px 0;
  color: var(--muted);
  line-height: 1.55;
}

.stage-tile {
  position: relative;
  min-width: 0;
  height: 82px;
}

.stage-chord-button {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 8px;
  align-content: center;
  padding: 10px 34px 10px 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  text-align: left;
}

.stage-tile.selected .stage-chord-button {
  border-color: rgba(20, 184, 166, 0.8);
  background: rgba(20, 184, 166, 0.14);
  box-shadow: inset 0 0 0 2px rgba(20, 184, 166, 0.26);
}

.stage-tile-index {
  grid-row: 1 / 3;
  align-self: center;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 850;
}

.stage-tile-code {
  min-width: 0;
  font-size: 1.05rem;
  font-weight: 850;
  overflow-wrap: anywhere;
}

.stage-tile-notes {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.delete-button {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: rgba(251, 113, 133, 0.12);
  color: #fecdd3;
  font-size: 1rem;
}

.actions {
  display: grid;
  grid-template-columns: 0.72fr 1.8fr;
  gap: 8px;
  margin-top: clamp(7px, 1.2dvh, 10px);
}

.primary-button {
  color: var(--text);
  font-weight: 850;
  min-height: clamp(40px, 5.4dvh, 44px);
}

.primary-button {
  background: #303641;
}

.play-button {
  background: var(--accent-2);
  color: #281700;
  font-size: 1.2rem;
  line-height: 1;
}

.primary-button.add {
  background: var(--accent);
  color: #06201d;
}

.primary-button.add:disabled {
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  cursor: default;
  opacity: 0.72;
}

.bottom-nav {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
  padding: 0 10px max(clamp(4px, 0.9dvh, 8px), env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: #0d0e11;
}

.nav-button {
  position: relative;
  min-height: clamp(46px, 6.2dvh, 52px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.nav-count {
  min-width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #06201d;
  font-size: 0.75rem;
  font-weight: 900;
  line-height: 1;
}

.nav-button::after {
  content: "";
  position: absolute;
  right: 18%;
  bottom: 0;
  left: 18%;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--accent);
  transform: scaleX(0);
  transition: transform 180ms ease;
}

.nav-button.active {
  color: var(--text);
}

.nav-button.active::after {
  transform: scaleX(1);
}

@media (min-width: 700px) {
  .phone-shell {
    border-radius: 24px;
    height: min(92vh, 880px);
  }
}

@media (max-height: 720px) {
  .app-bar {
    padding-right: 14px;
    padding-left: 14px;
  }

  .screen {
    padding-right: 14px;
    padding-left: 14px;
  }

  .root-roll,
  .bass-roll,
  .tension-roll {
    height: 76px;
  }

  .quality-grid {
    gap: 6px;
  }

  .quality-button,
  .primary-button,
  .modifier-button,
  .nav-button {
    min-height: 40px;
  }

  .current-code {
    font-size: clamp(2.8rem, 14vw, 4.8rem);
  }
}
