:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 100%;
  line-height: 1.5;
  color: #17202a;
  background: #f4f1e8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

button,
select,
summary,
a {
  touch-action: manipulation;
}

main {
  width: min(100% - 1.5rem, 46rem);
  margin: 0 auto;
  padding: 1rem 0 3rem;
}

h1,
h2,
h3 {
  line-height: 1.2;
}

h1 {
  margin: 0 0 0.75rem;
  font-size: clamp(2rem, 7vw, 3rem);
}

h2 {
  margin-top: 0;
  font-size: 1.25rem;
}

h3 {
  margin: 0;
  font-size: 1rem;
}

.page-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.page-title-row h1 {
  min-width: 0;
  margin-bottom: 0;
}

.language-switcher {
  display: inline-flex;
  flex: 0 0 auto;
  padding: 2px;
  border: 1px solid #777263;
  border-radius: 0.4rem;
  background: #fff;
}

.language-switcher button {
  min-width: 0;
  min-height: 2rem;
  padding: 0.25rem 0.5rem;
  border: 0;
  color: #3e443d;
  background: transparent;
}

.language-switcher button[aria-pressed="false"]:hover {
  background: #e9e5da;
}

.language-switcher button[aria-pressed="true"] {
  color: #fff;
  background: #27644e;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

section,
details {
  border: 1px solid #a9a38f;
  border-radius: 0.65rem;
  background: #fffdf7;
}

.practice-workspace {
  padding: 1rem;
  box-shadow: 0 0.2rem 0.8rem rgb(63 53 30 / 10%);
}

details {
  margin-top: 0.75rem;
}

label,
summary {
  font-weight: 700;
}

summary {
  display: list-item;
  min-height: 2.75rem;
  padding: 0.7rem 1rem;
  cursor: pointer;
}

details[open] > summary {
  border-bottom: 1px solid #d2cdbd;
}

.details-content {
  padding: 1rem;
}

textarea {
  display: block;
  width: 100%;
  min-height: 20rem;
  margin-top: 0.35rem;
  resize: vertical;
  padding: 0.9rem;
  border: 2px solid #777263;
  border-radius: 0.4rem;
  font: 1rem/1.55 ui-monospace, SFMono-Regular, Consolas, monospace;
  color: #17202a;
  background: #fff;
}

input[type="number"],
select {
  min-height: 2.75rem;
  padding: 0.5rem;
  border: 2px solid #777263;
  border-radius: 0.4rem;
  font: inherit;
  color: #17202a;
  background: #fff;
}

input[type="text"] {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.5rem;
  border: 2px solid #777263;
  border-radius: 0.4rem;
  font: 1rem/1.4 ui-monospace, SFMono-Regular, Consolas, monospace;
}

input[type="range"] {
  width: 100%;
  min-height: 2.75rem;
  margin: 0;
}

textarea:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible,
button:focus-visible {
  outline: 3px solid #d78300;
  outline-offset: 3px;
}

.preset-control label,
.setting-field label,
.tempo-ramp-fields label {
  display: block;
  margin-bottom: 0.3rem;
}

.preset-control select {
  width: 100%;
}

.preset-goal {
  margin: 0.3rem 0 0;
  color: #5c594e;
  font-size: 0.85rem;
  line-height: 1.35;
}

.transport-row {
  display: flex;
  align-items: stretch;
  gap: 0.75rem;
  margin-top: 0.9rem;
}

.transport-controls {
  display: flex;
  gap: 0.5rem;
}

.playback-toast {
  position: fixed;
  z-index: 20;
  top: calc(0.75rem + env(safe-area-inset-top));
  right: auto;
  bottom: auto;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: min(calc(100% - 1rem), 32rem);
  margin: 0;
  padding: 0.65rem 0.7rem;
  transform: translateX(-50%);
  border: 2px solid #27644e;
  border-left-width: 0.4rem;
  border-radius: 0.45rem;
  background: #e5f2eb;
  box-shadow: 0 0.5rem 1.4rem rgb(31 42 36 / 32%);
}

.playback-toast[hidden] {
  display: none;
}

.playback-toast[data-tone="warning"] {
  border-color: #8b6508;
  background: #fff1c2;
}

.playback-toast[data-tone="error"] {
  border-color: #972e2e;
  background: #fde3e3;
}

#playback-status {
  flex: 1;
  margin: 0;
  line-height: 1.35;
}

.toast-dismiss {
  flex: 0 0 auto;
  min-width: 2.5rem;
  min-height: 2.5rem;
  padding: 0.25rem;
  border-color: currentcolor;
  color: #3e443d;
  background: transparent;
  font-size: 1.25rem;
  line-height: 1;
}

.practice-chord-guide {
  margin-top: 0.75rem;
}

.practice-chord-guide h2 {
  margin-bottom: 0.35rem;
  font-size: 1rem;
}

.key-summary {
  margin: 0 0 0.55rem;
  font-weight: 700;
}

.chord-view-switcher {
  display: inline-grid;
  grid-template-columns: repeat(3, auto);
  gap: 0.2rem;
  padding: 0.2rem;
  border: 1px solid #777263;
  border-radius: 0.45rem;
  background: #fff;
}

.chord-view-switcher button {
  min-width: 0;
  min-height: 2rem;
  padding: 0.25rem 0.55rem;
  border: 0;
  color: #3e443d;
  background: transparent;
}

.chord-view-switcher button[aria-pressed="true"] {
  color: #fff;
  background: #27644e;
}

.chord-view-switcher button[aria-pressed="false"]:hover {
  background: #e9e5da;
}

.chord-guide-scroll {
  margin-top: 0.5rem;
  overflow-x: auto;
  border: 1px solid #a9a38f;
  border-radius: 0.4rem;
  background: #fff;
  scroll-padding-left: 0.65rem;
  scroll-snap-type: x mandatory;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}

.chord-timeline {
  display: flex;
  gap: 0.65rem;
  width: max-content;
  min-width: 100%;
  margin: 0;
  padding: 0.65rem;
  list-style: none;
}

.chord-bar-card {
  position: relative;
  flex: 0 0 max(clamp(15rem, 78vw, 18rem), calc(var(--bar-min-width) + 1.1rem));
  width: max(clamp(15rem, 78vw, 18rem), calc(var(--bar-min-width) + 1.1rem));
  padding: 0.55rem;
  border: 1px solid #a9a38f;
  border-radius: 0.45rem;
  background: #fffdf7;
  scroll-snap-align: start;
}

.chord-bar-number {
  display: block;
  color: #4a4a43;
  font-size: 0.8rem;
  font-weight: 700;
}

.chord-label-lanes {
  position: relative;
  height: calc(var(--label-lane-count) * 2rem + 0.35rem);
  margin: 0.35rem 0 0;
}

.chord-change-label {
  position: absolute;
  top: calc(var(--label-lane) * 2rem);
  display: inline-flex;
  align-items: baseline;
  gap: 0.3rem;
  max-width: none;
  padding: 0.2rem 0.4rem;
  border-radius: 0.3rem;
  white-space: nowrap;
  background: #edf5f1;
}

.chord-change-label.is-current {
  color: #fff;
  background: #27644e;
  box-shadow: 0 0 0 2px #173e30;
}

.chord-change-label.is-current .chord-timing-cue {
  color: #fff;
}

.chord-change-label.align-center {
  transform: translateX(-50%);
}

.chord-change-label.align-end {
  transform: translateX(-100%);
}

.chord-name {
  font: 700 1rem/1.35 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.chord-timing-cue {
  color: #5c594e;
  font-size: 0.75rem;
  font-weight: 700;
}

.chord-duration-band {
  position: relative;
  height: 1rem;
  overflow: hidden;
  border: 1px solid #777263;
  border-radius: 0.25rem;
  background-image: repeating-linear-gradient(
    to right,
    transparent 0,
    transparent calc(25% - 1px),
    #777263 calc(25% - 1px),
    #777263 25%
  );
}

.chord-duration-region {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgb(58 134 102 / 35%);
}

.chord-duration-region.is-current {
  background: rgb(39 100 78 / 78%);
}

.chord-duration-region + .chord-duration-region {
  border-left: 2px solid #27644e;
}

.chord-duration-region.alternate {
  background: rgb(215 131 0 / 28%);
}

.number-chord-controls {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #d2cdbd;
}

.key-controls-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.key-controls-grid select {
  width: 100%;
}

.key-controls-grid .secondary-button {
  align-self: end;
}

.key-controls-grid .context-status {
  grid-column: 1 / -1;
  margin: 0;
}

.tempo-control {
  margin-top: 0.8rem;
  padding: 0.7rem 0.8rem 0.35rem;
  border-radius: 0.5rem;
  background: #f2f0e9;
}

.tempo-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.bpm-value {
  display: flex;
  align-items: center;
  border: 2px solid #777263;
  border-radius: 999px;
  background: #fff;
}

.bpm-value input[type="number"] {
  width: 4.2rem;
  min-height: 2.35rem;
  padding: 0.25rem 0.15rem 0.25rem 0.5rem;
  border: 0;
  border-radius: 999px 0 0 999px;
  font-weight: 700;
  text-align: end;
}

.bpm-value span {
  padding: 0 0.65rem 0 0.25rem;
  color: #4a4a43;
  font-size: 0.85rem;
  font-weight: 700;
}

.practice-options {
  background: #f8f6ef;
}

.practice-options-grid,
.arrangement-settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem 0.75rem;
}

.arrangement-settings-grid {
  margin-bottom: 1rem;
}

.setting-field {
  min-width: 0;
}

.setting-field select {
  width: 100%;
}

.tempo-ramp-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 0.8rem 0 0;
  padding: 0.75rem;
  border: 1px solid #a9a38f;
  border-radius: 0.5rem;
}

.tempo-ramp-fields[hidden] {
  display: none;
}

.tempo-ramp-fields legend {
  padding: 0 0.35rem;
  font-weight: 700;
}

.tempo-ramp-fields input {
  width: 100%;
}

.validation-panel {
  margin-top: 0.75rem;
}

.validation-summary {
  margin: 0;
  padding: 0.6rem 0.7rem;
  border-left: 0.3rem solid #777263;
  background: #f2f0e9;
}

.validation-summary.valid {
  border-color: #27644e;
  background: #edf5f1;
}

.validation-summary.invalid {
  border-color: #a32916;
  background: #fff0ed;
}

.validation-errors {
  margin: 0.75rem 0 0;
  padding-left: 1.5rem;
  color: #7b1d0f;
}

.validation-errors li + li {
  margin-top: 0.4rem;
}

.manual-copy {
  margin-top: 0.75rem;
  padding: 0.75rem;
  border-left: 0.3rem solid #8b6508;
  background: #fff7dc;
}

.manual-copy label {
  display: block;
  margin-bottom: 0.35rem;
}

.manual-copy p {
  margin-bottom: 0;
}

.context-status {
  margin: 0.65rem 0 0;
  color: #4a4a43;
}

.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.75rem;
}

button {
  min-width: 7rem;
  min-height: 2.75rem;
  padding: 0.6rem 0.9rem;
  border: 2px solid #244c3d;
  border-radius: 0.4rem;
  font: inherit;
  font-weight: 700;
  color: #fff;
  background: #27644e;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #194b38;
}

#play-pause[aria-pressed="true"] {
  border-color: #783600;
  background: #a94d00;
}

#play-pause[aria-pressed="true"]:hover {
  background: #843c00;
}

button.secondary-button {
  border-color: #565347;
  color: #252822;
  background: #fff;
}

button.secondary-button:hover:not(:disabled) {
  background: #e9e5da;
}

button:disabled,
button.secondary-button:disabled {
  border-color: #777;
  color: #eee;
  background: #777;
  cursor: not-allowed;
}

.help-content h2 {
  margin: 1.5rem 0 0.5rem;
  font-size: 1.1rem;
}

.help-content h2:first-child {
  margin-top: 0;
}

.help-content p {
  margin: 0.5rem 0;
}

.chord-list {
  overflow-wrap: anywhere;
}

.format-example {
  overflow-x: auto;
  padding: 0.75rem;
  border: 1px solid #d2cdbd;
  border-radius: 0.4rem;
  background: #f8f6ef;
}

.sound-test-group + .sound-test-group {
  margin-top: 1.25rem;
}

.sound-test-group h3 {
  margin-bottom: 0.5rem;
}

.sound-test-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(4.75rem, 1fr));
  gap: 0.5rem;
}

.sound-test-buttons button {
  min-width: 0;
}

.preset-notice {
  margin-top: 1.25rem;
  padding: 1rem;
  border-top: 1px solid #a9a38f;
  color: #4a4a43;
}

.preset-notice h2 {
  font-size: 1rem;
}

.preset-notice p {
  margin-bottom: 0;
}

code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

@media (max-width: 38rem) {
  .transport-row {
    display: grid;
  }

  .transport-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .transport-controls button {
    width: 100%;
    min-width: 0;
  }

  .tempo-ramp-fields {
    grid-template-columns: 1fr;
  }

  .key-controls-grid,
  .arrangement-settings-grid {
    grid-template-columns: 1fr;
  }

  .key-controls-grid .context-status {
    grid-column: auto;
  }
}

@media (max-width: 30rem) {
  .page-title-row h1 {
    font-size: clamp(1.25rem, 6vw, 1.75rem);
    white-space: nowrap;
  }
}

@media (max-width: 22rem) {
  main {
    width: min(100% - 1rem, 46rem);
  }

  .practice-options-grid {
    grid-template-columns: 1fr;
  }

  .button-group {
    display: grid;
  }

  .button-group button {
    width: 100%;
  }
}
