:root {
  --bg: #16130f;
  --bg-2: #1f1b16;
  --surface: #2a241c;
  --surface-2: #352e24;
  --line: #5a4f3f;
  --text: #f6f0e4;
  --text-strong: #fffaf0;
  --muted: #d9cdb8;
  --gold: #e4b34a;
  --gold-text: #1a150f;
  --cream: #f4ead6;
  --ink: #1a150f;
  --ink-soft: #3b3328;
  --key-white: #f4ead6;
  --key-white-text: #1a150f;
  --key-black: #2f2a24;
  --key-black-text: #f4ead6;
  --key-press: #e4b34a;
  --tonic: #c45c52;
  --tonic-fill: #f3d0c8;
  --tonic-text: #6b221c;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  --radius: 16px;
  --key-h: 118px;
}

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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(1200px 600px at 50% -10%, #3a3226 0%, var(--bg) 55%);
  color: var(--text);
  font-family: "DM Sans", system-ui, sans-serif;
}

body {
  line-height: 1.4;
}

button,
input {
  font: inherit;
}

h1,
h2 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 700;
  margin: 0;
  color: var(--text-strong);
}

.app {
  width: min(1180px, calc(100% - 20px));
  margin: 0 auto;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 10px 0 12px;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.brand h1 {
  font-size: 1.7rem;
  letter-spacing: -0.03em;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  background: var(--surface-2);
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.stage {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 10px 10px 6px;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.stage-main {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.mode-btn {
  flex: 0 0 36px;
  width: 36px;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-strong);
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  padding: 10px 0;
}

.mode-btn[aria-pressed="true"] {
  background: var(--gold);
  color: var(--gold-text);
  border-color: #b88922;
}

.mode-btn:hover,
.mode-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.board {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 4px;
}

.keyboard {
  user-select: none;
  touch-action: none;
  height: var(--key-h);
  min-width: 720px;
}

.keyboard.chromatic-layout {
  display: flex;
  gap: 3px;
}

.key {
  position: relative;
  border: 1px solid #6a5e4c;
  border-radius: 0 0 10px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 8px;
  cursor: pointer;
  color: var(--key-white-text);
  background: var(--key-white);
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.08);
}

.chromatic-layout .key {
  flex: 1 1 0;
  min-width: 26px;
}

.key.black {
  color: var(--key-black-text);
  background: repeating-linear-gradient(
    -45deg,
    #2a251f,
    #2a251f 5px,
    #3a342c 5px,
    #3a342c 10px
  );
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.28);
  border-color: #8a7b64;
}

.key-label {
  position: relative;
  z-index: 1;
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.01em;
}

.key.black .key-label {
  font-size: 0.68rem;
}

.key-oct {
  position: absolute;
  top: 6px;
  font-size: 0.62rem;
  font-weight: 700;
  opacity: 0.7;
}

.key.in-chord {
  box-shadow: inset 0 0 0 2px #2d6b5c, inset 0 -8px 0 rgba(0, 0, 0, 0.12);
}

.key.black.in-chord {
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.28);
  background: repeating-linear-gradient(
    -45deg,
    #3a3428,
    #3a3428 5px,
    #4a4336 5px,
    #4a4336 10px
  );
}

.key.tonic {
  background: var(--tonic-fill);
  color: var(--tonic-text);
  box-shadow: inset 0 0 0 2px var(--tonic), inset 0 -8px 0 rgba(90, 24, 20, 0.12);
}

.key.black.tonic {
  color: #f6e4dc;
  background: repeating-linear-gradient(
    -45deg,
    #4a2824,
    #4a2824 5px,
    #5c3530 5px,
    #5c3530 10px
  );
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.28);
}

.key.pressed,
.key:active {
  transform: translateY(2px);
  background: var(--key-press);
  color: var(--gold-text);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.18);
}

.key.black.pressed,
.key.black:active {
  background: var(--key-press);
  color: var(--gold-text);
}

.keyboard.piano-layout {
  position: relative;
  display: block;
}

.piano-layout .whites {
  display: flex;
  height: 100%;
  gap: 2px;
}

.piano-layout .key.white {
  flex: 1 1 0;
  height: 100%;
  min-width: 22px;
}

.piano-layout .key.black {
  position: absolute;
  top: 0;
  height: 58%;
  z-index: 2;
  padding-bottom: 6px;
  border-radius: 0 0 6px 6px;
}

.indicator-slot {
  position: relative;
  min-width: 720px;
  min-height: 104px;
  margin-top: 0;
}

.indicator-hint {
  margin: 18px 8px 0;
  color: var(--muted);
  text-align: center;
}

.indicator {
  position: absolute;
  top: 0;
  min-width: 160px;
  transition: left 0.16s ease, width 0.16s ease;
  z-index: 3;
}

.indicator.dragging {
  transition: none;
}

.indicator-arms {
  position: relative;
  height: 52px;
}

.indicator-arms::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 0;
  height: 3px;
  background: var(--ink);
}

.arm {
  position: absolute;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translateX(-50%);
}

.arm-head {
  position: relative;
  min-width: 36px;
  height: 34px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--cream);
  color: var(--ink);
  border: 2px solid var(--ink);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.68rem;
  letter-spacing: -0.02em;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
  z-index: 1;
}

.arm.black .arm-head {
  min-width: 44px;
  height: 40px;
  padding: 10px 4px 2px;
  border: 0;
  border-radius: 0;
  background: var(--ink);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.2);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.arm.black .arm-head::before {
  content: "";
  position: absolute;
  inset: 2px 3px 3px;
  background: var(--cream);
  clip-path: polygon(50% 8%, 92% 100%, 8% 100%);
  pointer-events: none;
}

.arm.black .arm-head span {
  position: relative;
  z-index: 1;
  color: var(--ink);
}

.arm.tonic .arm-head {
  background: var(--tonic-fill);
  border-color: var(--tonic);
  color: var(--tonic-text);
}

.arm.tonic .arm-stem {
  background: var(--tonic);
}

.arm.black.tonic .arm-head {
  background: var(--tonic);
}

.arm.black.tonic .arm-head::before {
  background: var(--tonic-fill);
}

.arm.black.tonic .arm-head span {
  color: var(--tonic-text);
}

.indicator.piano-mode .arm.black .arm-head {
  min-width: 46px;
  height: 44px;
  padding-top: 12px;
}

.arm-stem {
  width: 3px;
  flex: 1;
  background: var(--ink);
  min-height: 16px;
}

.indicator-body {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 50px;
  padding: 6px 10px;
  background: var(--cream);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-top-width: 3px;
  border-radius: 0 0 14px 14px;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.28);
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.indicator.dragging .indicator-body {
  cursor: grabbing;
}

.dots-btn {
  width: 28px;
  height: 36px;
  border: 0;
  background: transparent;
  display: grid;
  place-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 0;
}

.dots-btn span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink);
  display: block;
}

.chord-title {
  flex: 1;
  text-align: center;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
}

.nudge {
  display: flex;
  gap: 4px;
}

.nudge button {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 2px solid var(--ink);
  background: #efe4cc;
  color: var(--ink);
  font-size: 1.15rem;
  cursor: pointer;
  line-height: 1;
}

.nudge button:hover,
.nudge button:focus-visible,
.dots-btn:focus-visible {
  outline: 2px solid #0f6b56;
  outline-offset: 1px;
}

.nudge button:disabled {
  opacity: 0.35;
  cursor: default;
}

.indicator-menu {
  position: absolute;
  left: 8px;
  top: calc(100% + 6px);
  background: var(--cream);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 10px;
  min-width: 180px;
  z-index: 6;
  box-shadow: var(--shadow);
}

.menu-label {
  margin: 0 0 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.menu-inversions,
.inversion-row,
.inv-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.transport {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 6px 0 6px;
  flex-shrink: 0;
}

.play-btn,
.arp-btn {
  border: 0;
  border-radius: 999px;
  padding: 9px 18px;
  font-weight: 700;
  cursor: pointer;
}

.play-btn {
  background: var(--gold);
  color: var(--gold-text);
}

.arp-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}

.play-btn:hover,
.play-btn:focus-visible,
.arp-btn:hover,
.arp-btn:focus-visible {
  outline: 2px solid var(--cream);
  outline-offset: 2px;
}

.play-btn.held,
.arp-btn.held {
  transform: translateY(1px);
  filter: brightness(0.95);
}

.kbd-help {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

kbd {
  display: inline-block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 1px 6px;
  color: var(--text-strong);
  font-family: inherit;
  font-size: 0.85em;
}

.studio {
  display: grid;
  grid-template-columns: 196px minmax(0, 1fr);
  gap: 10px;
  flex: 1;
  min-height: 0;
}

.panel {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.panel h2 {
  font-size: 0.95rem;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.inv-heading {
  margin-top: 10px;
}

.notes-panel {
  overflow: auto;
}

.dict-panel {
  overflow: hidden;
}

.dict-panel .dict {
  flex: 1;
}

.note-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.note-btn,
.chord-btn,
.inv-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 4px;
  cursor: pointer;
  font-weight: 700;
}

.inv-btn {
  padding: 5px 8px;
  font-size: 0.75rem;
  font-weight: 600;
}

.note-btn.black {
  background: #231f1a;
  color: var(--cream);
}

.note-btn.selected,
.chord-btn.selected,
.inv-btn.selected {
  background: var(--gold);
  color: var(--gold-text);
  border-color: #b88922;
}

.note-btn:hover,
.chord-btn:hover,
.inv-btn:hover,
.note-btn:focus-visible,
.chord-btn:focus-visible,
.inv-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.dict {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 14px;
  overflow: auto;
  min-height: 0;
  padding-right: 4px;
  align-content: start;
  align-items: start;
}

.dict-group h3 {
  margin: 0 0 5px;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 700;
}

.dict-items {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.chord-btn {
  padding: 4px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.15;
  border-radius: 6px;
  flex: 0 0 auto;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 10, 8, 0.72);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 20;
}

.overlay[hidden],
.indicator[hidden],
.indicator-menu[hidden],
.indicator-hint[hidden] {
  display: none !important;
}

.sheet {
  width: min(480px, 100%);
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.close-btn {
  width: 40px;
  height: 40px;
  justify-content: center;
  padding: 0;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin: 0;
}

legend {
  padding: 0 6px;
  color: var(--muted);
  font-weight: 700;
}

.choice {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  color: var(--text);
  cursor: pointer;
}

.slider-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--gold);
}

@media (max-width: 900px) {
  .dict {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 800px) {
  .studio {
    grid-template-columns: 1fr;
  }

  .brand h1 {
    font-size: 1.45rem;
  }

  .kbd-help {
    width: 100%;
  }

  .mode-btn {
    flex-basis: 32px;
    width: 32px;
    font-size: 0.7rem;
  }
}
