/* Apple-style system colours. The theme is set on <html data-theme> before
   the page draws (see index.html). */
:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --card: #ffffff;
  --label: #1d1d1f;
  --secondary: #6e6e73;
  --tertiary: #aeaeb2;
  --separator: rgba(60, 60, 67, 0.16);
  --fill: rgba(118, 118, 128, 0.12);
  --fill-strong: rgba(118, 118, 128, 0.2);
  --track: rgba(120, 120, 128, 0.2);
  --segment: #ffffff;
  --switch-off: #e9e9eb;
  --stage: #e8e8ed;
  --accent: #007aff;
  --green: #34c759;
  --red: #ff3b30;
  --left: #ff9500;
  --right: #5856d6;
  --manual: #34c759;
  --white-key: #ffffff;
  --black-key: #1d1d1f;
  --key-line: #d2d2d7;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 20px rgba(0, 0, 0, 0.05);
  --radius: 18px;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #000000;
  --card: #1c1c1e;
  --label: #f5f5f7;
  --secondary: #98989d;
  --tertiary: #636366;
  --separator: rgba(84, 84, 88, 0.6);
  --fill: rgba(118, 118, 128, 0.24);
  --fill-strong: rgba(118, 118, 128, 0.36);
  --track: rgba(120, 120, 128, 0.36);
  --segment: #636366;
  --switch-off: #39393d;
  --stage: #1c1c1e;
  --accent: #0a84ff;
  --green: #30d158;
  --red: #ff453a;
  --left: #ff9f0a;
  --right: #5e5ce6;
  --manual: #30d158;
  --white-key: #e5e5ea;
  --black-key: #000000;
  --key-line: #3a3a3c;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font: 15px/1.47 -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', 'Segoe UI', Roboto,
    sans-serif;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s;
}

h1,
h2,
.chord {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', 'Segoe UI', Roboto,
    sans-serif;
}

button,
select,
input {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

svg {
  display: block;
}

.footnote {
  margin: 8px 16px 0;
  color: var(--secondary);
  font-size: 13px;
}

.footnote:empty {
  display: none;
}

/* ---------- header ---------- */

.top {
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px 20px 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.top h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.025em;
}

.status {
  margin: 4px 0 0;
  color: var(--secondary);
  font-size: 15px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

.record-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 16px 0 14px;
  border: 0;
  border-radius: 18px;
  background: var(--fill);
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}

.record-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--red);
  transition: border-radius 0.2s, background-color 0.2s;
}

.record-button.recording {
  background: var(--red);
  color: #fff;
}

.record-button.recording .record-dot {
  border-radius: 2px;
  background: #fff;
}

.round-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--fill);
  cursor: pointer;
}

.round-button svg {
  width: 19px;
  height: 19px;
}

.record-button:disabled,
.round-button:disabled {
  opacity: 0.5;
  cursor: default;
}

.mic-button rect {
  fill: currentColor;
}

.mic-button .mic-stand,
.mic-button .mic-slash {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.mic-button[aria-pressed='true'] {
  background: var(--accent);
  color: #fff;
}

.mic-button[aria-pressed='true'] .mic-slash {
  display: none;
}

.mic-button[aria-pressed='false'] {
  color: var(--secondary);
}

.icon-sun {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.icon-moon {
  fill: currentColor;
}

:root[data-theme='dark'] .icon-moon,
:root:not([data-theme='dark']) .icon-sun {
  display: none;
}

/* ---------- layout ---------- */

.layout {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 20px 56px;
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1fr) 320px;
  grid-template-areas:
    'stage side'
    'keys keys'
    'patterns patterns'
    'recordings settings';
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-title {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
}

.section-title {
  margin: 0 0 10px 4px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* ---------- camera stage ---------- */

.stage {
  grid-area: stage;
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 22px;
  background: var(--stage);
}

.stage video,
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.stage video {
  object-fit: cover;
  transform: scaleX(-1); /* mirrored, like a mirror */
  opacity: 0;
  transition: opacity 0.4s;
}

.stage.live video {
  opacity: 1;
}

.intro {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
}

.intro[hidden] {
  display: none;
}

.intro h2 {
  margin: 0;
  font-size: clamp(22px, 2.6vw, 28px);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.intro p {
  margin: 0;
  max-width: 40ch;
  color: var(--secondary);
}

.intro .footnote {
  margin-top: 4px;
}

.intro-error {
  color: var(--red) !important;
}

.intro-error:empty {
  display: none;
}

.filled-button {
  margin-top: 10px;
  padding: 12px 26px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s;
}

.filled-button:active {
  transform: scale(0.97);
}

.filled-button:disabled {
  opacity: 0.5;
  cursor: progress;
}

/* ---------- now playing ---------- */

.side {
  grid-area: side;
  display: grid;
  gap: 16px;
  align-content: start;
}

.hands {
  display: grid;
  gap: 16px;
}

.hand-card {
  --c: var(--left);
  padding: 14px 18px 16px;
  transition: box-shadow 0.25s;
}

.hand-card[data-side='right'] {
  --c: var(--right);
}

.hand-card.playing {
  box-shadow: var(--shadow), inset 0 0 0 2px var(--c);
}

.hand-head {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--secondary);
  font-size: 13px;
  font-weight: 500;
}

.hand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c);
}

/* Octave stepper: − Oct 0 + */
.stepper {
  display: inline-flex;
  align-items: center;
  margin-left: auto;
  border-radius: 8px;
  background: var(--fill);
  overflow: hidden;
}

.stepper button {
  width: 28px;
  height: 26px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--label);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.stepper button:active:not(:disabled) {
  background: var(--fill-strong);
}

.stepper button:disabled {
  color: var(--tertiary);
  cursor: default;
}

.stepper output {
  min-width: 46px;
  color: var(--secondary);
  font-size: 12px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.hand-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 6px 0 4px;
}

.chord {
  font-size: 44px;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.03em;
  color: var(--tertiary);
  transform-origin: left center;
}

.playing .chord {
  color: var(--c);
}

.hand-roman {
  min-height: 20px;
  color: var(--secondary);
  font-size: 15px;
}

.hand-notes {
  margin: 0;
  min-height: 18px;
  color: var(--secondary);
  font-size: 13px;
}

/* ---------- finger glyph: five bars, thumb first ---------- */

.glyph {
  display: inline-flex;
  align-items: flex-end;
  gap: 3px;
  height: 28px;
  flex: none;
  color: var(--label);
}

.glyph i {
  --min: 26%;
  width: 6px;
  height: calc(var(--min) + (var(--max) - var(--min)) * var(--h, 0));
  border-radius: 3px;
  background: var(--fill-strong);
  transition: height 0.1s, background-color 0.15s;
}

.glyph i:nth-child(1) {
  --max: 58%;
  margin-right: 2px;
}
.glyph i:nth-child(2) {
  --max: 90%;
}
.glyph i:nth-child(3) {
  --max: 100%;
}
.glyph i:nth-child(4) {
  --max: 92%;
}
.glyph i:nth-child(5) {
  --max: 70%;
}

.glyph i.up {
  background: currentColor;
}

.glyph.big {
  height: 46px;
  gap: 4px;
  color: var(--c);
}

.glyph.big i {
  width: 8px;
  border-radius: 4px;
}

/* ---------- sound picker ---------- */

.sound {
  padding: 14px 16px 16px;
}

.sound-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.sound-grid button {
  padding: 8px 12px;
  border: 0;
  border-radius: 10px;
  background: var(--fill);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.sound-grid button[aria-pressed='true'] {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.sound-grid button.loading::after {
  content: '';
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-left: 6px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -1px;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- keyboard ---------- */

.keys {
  grid-area: keys;
  padding: 16px 16px 14px;
}

.keys .footnote {
  margin: 10px 0 0;
}

.keys-scroll {
  overflow-x: auto;
  scrollbar-width: none;
}

.keys-scroll::-webkit-scrollbar {
  display: none;
}

.keyboard {
  position: relative;
  min-width: 960px;
  height: 120px;
  touch-action: pan-x; /* taps play; a horizontal swipe scrolls on phones */
  user-select: none;
  -webkit-user-select: none;
}

.key {
  position: absolute;
  top: 0;
  cursor: pointer;
  transition: background-color 0.08s;
}

.key.white {
  height: 100%;
  background: var(--white-key);
  border: 1px solid var(--key-line);
  border-radius: 0 0 7px 7px;
}

.key.black {
  z-index: 1;
  height: 62%;
  background: var(--black-key);
  border: 1px solid var(--key-line);
  border-top: 0;
  border-radius: 0 0 5px 5px;
}

.key.left {
  background: var(--left);
}

.key.right {
  background: var(--right);
}

.key.left.right {
  background: linear-gradient(var(--left) 50%, var(--right) 50%);
}

.key.manual {
  background: var(--manual);
}

.key[data-label]::after,
.key[data-shortcut]::before {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 10px;
  color: #8e8e93;
}

.key[data-label]::after {
  content: attr(data-label);
  bottom: 5px;
}

.key[data-shortcut]::before {
  content: attr(data-shortcut);
  bottom: 21px;
  font-weight: 600;
}

.key.black[data-shortcut]::before {
  bottom: 7px;
  color: #8e8e93;
}

@media (hover: none) {
  .typing-hint,
  .key[data-shortcut]::before {
    display: none;
  }
}

/* ---------- finger patterns ---------- */

.patterns {
  grid-area: patterns;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 10px;
}

.section-head .section-title {
  margin-bottom: 0;
}

.section-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.gesture-list[hidden],
.segmented[hidden] {
  display: none;
}

.sign-result {
  font-size: 15px;
  font-weight: 600;
}

.gesture-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 12px;
}

.gesture {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas:
    'glyph name roman'
    'glyph chord chord';
  align-items: center;
  gap: 8px 14px;
  padding: 14px 16px;
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s;
}

.gesture .glyph {
  grid-area: glyph;
}

.gesture-name {
  grid-area: name;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.gesture-name strong {
  font-weight: 600;
}

.gesture-name small {
  color: var(--secondary);
  font-size: 13px;
}

.roman {
  grid-area: roman;
  color: var(--secondary);
  font-size: 13px;
}

.gesture-chord {
  grid-area: chord;
  display: flex;
  gap: 6px;
  margin: 0;
}

.gesture.fist .gesture-chord {
  color: var(--secondary);
  font-size: 13px;
}

.gesture .quality {
  flex: 1;
}

.gesture.on-left {
  box-shadow: var(--shadow), inset 0 0 0 2px var(--left);
}

.gesture.on-right {
  box-shadow: var(--shadow), inset 0 0 0 2px var(--right);
}

.gesture.on-left.on-right {
  box-shadow: var(--shadow), inset 0 0 0 2px var(--left), inset 0 0 0 4px var(--right);
}

/* ---------- pop-up buttons (selects) ---------- */

select {
  min-width: 0;
  padding: 6px 28px 6px 10px;
  border: 0;
  border-radius: 8px;
  background: var(--fill)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5 6 1.5l3 3M3 7.5l3 3 3-3' fill='none' stroke='%238e8e93' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
    no-repeat right 9px center / 11px;
  font-size: 14px;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

/* ---------- segmented control ---------- */

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 2px;
  border-radius: 9px;
  background: var(--fill);
}

.segmented label {
  position: relative;
}

.segmented input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented span {
  display: block;
  padding: 4px 14px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  transition: background-color 0.2s, box-shadow 0.2s;
}

.segmented input:checked + span {
  background: var(--segment);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 3px 1px rgba(0, 0, 0, 0.04);
  font-weight: 600;
}

.segmented input:focus-visible + span {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
}

/* ---------- grouped lists: recordings and settings ---------- */

.recordings {
  grid-area: recordings;
}

.settings {
  grid-area: settings;
}

.list {
  overflow: hidden;
}

.row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 6px 16px;
}

.row + .row::before,
.take + .take::before {
  content: '';
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  height: 1px;
  background: var(--separator);
  transform: scaleY(0.5);
}

.row-label {
  flex: 1;
}

.row input[type='range'] {
  flex: 1.4;
}

.row-value {
  min-width: 28px;
  color: var(--secondary);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.row.disabled {
  opacity: 0.4;
}

.row-button {
  width: 100%;
  border: 0;
  background: none;
  color: var(--accent);
  text-align: left;
  cursor: pointer;
}

.row-button:active {
  background: var(--fill);
}

.takes {
  margin: 0;
  padding: 0;
  list-style: none;
}

.take {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 16px;
}

.take + .take::before {
  left: 100px;
}

.take-thumb {
  position: relative;
  display: grid;
  place-items: center;
  width: 72px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--fill-strong);
  color: #fff;
  cursor: pointer;
  flex: none;
}

.take-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.take-play {
  position: relative;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.take-play svg {
  width: 12px;
  height: 12px;
  margin-left: 1px;
  fill: currentColor;
}

.take-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.take-name {
  font-weight: 500;
}

.take-time {
  color: var(--secondary);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.text-button {
  padding: 6px 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--accent);
  font-size: 15px;
  cursor: pointer;
}

.text-button:hover {
  background: var(--fill);
}

.text-button.strong {
  font-weight: 600;
}

/* ---------- take preview ---------- */

.preview {
  width: min(92vw, 880px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--card);
  color: var(--label);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.preview::backdrop {
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.preview video {
  display: block;
  width: 100%;
  max-height: 70vh;
  background: #000;
}

.preview-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 12px 10px 18px;
}

.preview-bar strong {
  flex: 1;
  font-weight: 600;
}

.delete-button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--secondary);
  cursor: pointer;
}

.delete-button:hover {
  color: var(--red);
  background: var(--fill);
}

.delete-button svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.empty {
  margin: 0;
  padding: 14px 16px;
  color: var(--secondary);
}

.empty[hidden] {
  display: none;
}

/* ---------- switch ---------- */

.switch {
  position: relative;
  flex: none;
  width: 51px;
  height: 31px;
  margin: 0;
  border-radius: 16px;
  background: var(--switch-off);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  transition: background-color 0.25s;
}

.switch::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 3px 1px rgba(0, 0, 0, 0.06);
  transition: transform 0.25s;
}

.switch:checked {
  background: var(--green);
}

.switch:checked::before {
  transform: translateX(20px);
}

/* ---------- slider ---------- */

input[type='range'] {
  --fill: 50%;
  height: 28px;
  margin: 0;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

input[type='range']::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--accent) var(--fill), var(--track) var(--fill));
}

input[type='range']::-webkit-slider-thumb {
  width: 26px;
  height: 26px;
  margin-top: -11px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0.5px 4px rgba(0, 0, 0, 0.12), 0 6px 13px rgba(0, 0, 0, 0.12);
  -webkit-appearance: none;
}

input[type='range']::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--track);
}

input[type='range']::-moz-range-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
}

input[type='range']::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0.5px 4px rgba(0, 0, 0, 0.12), 0 6px 13px rgba(0, 0, 0, 0.12);
}

input[type='range']:disabled {
  cursor: default;
}

/* ---------- small screens ---------- */

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: 'stage' 'side' 'keys' 'patterns' 'recordings' 'settings';
  }

  .hands {
    grid-template-columns: 1fr 1fr;
  }

  .sound-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .chord {
    font-size: 36px;
  }
}

@media (max-width: 520px) {
  .top {
    flex-wrap: wrap;
    padding: 20px 16px 16px;
  }

  .top h1 {
    font-size: 28px;
  }

  .layout {
    padding: 0 16px 40px;
    gap: 16px;
  }

  .record-button {
    padding: 0 12px;
  }

  .hand-card {
    padding: 12px 14px 14px;
  }

  .glyph.big {
    display: none;
  }

  .chord {
    font-size: 30px;
  }

  .section-head {
    flex-direction: column;
    align-items: stretch;
  }
}
