:root {
  color-scheme: dark;
  --bg: #0e1116;
  --panel: #151a22;
  --panel-alt: #19202a;
  --input: #202936;
  --grid: #2b3543;
  --chart-border: #3a4a59;
  --table-heading: #1b222c;
  --selected-row: #243c3a;
  --current-row: #493a25;
  --text: #f3f6f8;
  --muted: #929eae;
  --accent: #69d4b4;
  --accent-hover: #7de2c3;
  --playhead: #f2b95f;
  --playhead-halo: rgba(242, 185, 95, 0.22);
  --button-on-accent: #0c1514;
  --danger: #f07979;
  --border: rgba(255, 255, 255, 0.025);
  --row-border: rgba(255, 255, 255, 0.035);
  --toast: #26303d;
  --transport-shadow: 0 20px 70px rgba(0, 0, 0, 0.45);
  --modal-shadow: 0 30px 100px rgba(0, 0, 0, 0.65);
  --modal-backdrop: rgba(4, 7, 10, 0.72);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="ocean"] {
  --accent: #63b3ff;
  --accent-hover: #80c1ff;
  --playhead: #ffbe63;
  --playhead-halo: rgba(255, 190, 99, 0.22);
  --selected-row: #21394e;
}

:root[data-theme="violet"] {
  --accent: #b49cff;
  --accent-hover: #c4b2ff;
  --playhead: #70dbc2;
  --playhead-halo: rgba(112, 219, 194, 0.22);
  --selected-row: #362f4d;
}

:root[data-theme="ember"] {
  --accent: #f2a65f;
  --accent-hover: #f6b978;
  --playhead: #72c7ff;
  --playhead-halo: rgba(114, 199, 255, 0.22);
  --selected-row: #493525;
}

:root[data-mode="light"] {
  color-scheme: light;
  --bg: #f2f5f7;
  --panel: #ffffff;
  --panel-alt: #f7f9fa;
  --input: #e8edf1;
  --grid: #d4dde4;
  --chart-border: #b8c5cf;
  --table-heading: #edf1f4;
  --current-row: #fff1d6;
  --text: #17212b;
  --muted: #667482;
  --button-on-accent: #ffffff;
  --danger: #bf4050;
  --border: rgba(24, 42, 57, 0.08);
  --row-border: rgba(24, 42, 57, 0.08);
  --toast: #263541;
  --transport-shadow: 0 20px 60px rgba(37, 58, 74, 0.16);
  --modal-shadow: 0 30px 90px rgba(37, 58, 74, 0.25);
  --modal-backdrop: rgba(29, 43, 54, 0.35);
}

:root[data-mode="light"][data-theme="mint"] {
  --accent: #177e68;
  --accent-hover: #116c59;
  --playhead: #a66016;
  --playhead-halo: rgba(166, 96, 22, 0.18);
  --selected-row: #dcefe9;
}

:root[data-mode="light"][data-theme="ocean"] {
  --accent: #2377b8;
  --accent-hover: #1d659c;
  --playhead: #a45e12;
  --playhead-halo: rgba(164, 94, 18, 0.18);
  --selected-row: #dceaf5;
}

:root[data-mode="light"][data-theme="violet"] {
  --accent: #7253bd;
  --accent-hover: #6043a7;
  --playhead: #147b66;
  --playhead-halo: rgba(20, 123, 102, 0.18);
  --selected-row: #e9e2f7;
}

:root[data-mode="light"][data-theme="ember"] {
  --accent: #b85f16;
  --accent-hover: #9e4f11;
  --playhead: #176fa8;
  --playhead-halo: rgba(23, 111, 168, 0.18);
  --selected-row: #f5e4d6;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: none;
}

button,
input,
select {
  font: inherit;
}

button,
select,
.numeric-input {
  min-height: 44px;
}

button {
  touch-action: manipulation;
}

.app-shell {
  width: min(1500px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 24px calc(138px + var(--safe-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 0 16px;
}

.brand h1,
.card h2 {
  margin: 0;
}

.brand h1 {
  font-size: clamp(1.4rem, 2.2vw, 1.8rem);
  letter-spacing: -0.03em;
}

.brand p,
.card-heading p,
.progress {
  margin: 3px 0 0;
  color: var(--muted);
}

.brand p,
.eyebrow,
.status,
.timer span,
.data-table th {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.preset-bar,
.playlist-add-row,
.actions,
.transport,
.timer-group,
.setting-line,
.signature-control {
  display: flex;
  align-items: center;
}

.preset-bar,
.playlist-add-row,
.actions {
  gap: 8px;
}

.preset-bar select {
  width: min(260px, 28vw);
}

select,
.numeric-input {
  border: 1px solid transparent;
  border-radius: 9px;
  outline: none;
  background: var(--input);
  color: var(--text);
  padding: 9px 12px;
}

select:focus-visible,
input:focus-visible,
button:focus-visible {
  border-color: var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 2px;
}

.button {
  min-height: 44px;
  border: 0;
  border-radius: 9px;
  background: var(--input);
  color: var(--text);
  padding: 10px 15px;
  font-weight: 700;
  cursor: pointer;
}

.button:active:not(:disabled) {
  transform: translateY(1px);
}

.button.accent {
  background: var(--accent);
  color: var(--button-on-accent);
  padding-inline: 22px;
}

.button.danger {
  background: transparent;
  color: var(--danger);
}

.button.ghost {
  background: transparent;
  color: var(--muted);
}

.button:disabled,
select:disabled,
input:disabled {
  opacity: 0.38;
  cursor: default;
}

.settings-card,
.card,
.transport {
  background: var(--panel);
  border: 1px solid var(--border);
}

.settings-card {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto auto minmax(180px, 1fr);
  gap: 18px 26px;
  align-items: end;
  padding: 15px 18px;
  border-radius: 12px;
}

.setting {
  min-width: 0;
}

.setting > .eyebrow,
.setting-line .eyebrow {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
}

.signature-control {
  gap: 7px;
}

.signature-control input {
  width: 62px;
  text-align: center;
}

.signature-control select {
  width: 66px;
}

.setting-line {
  justify-content: space-between;
}

.setting-line output {
  color: var(--text);
  font-size: 0.86rem;
}

.appearance-setting {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 14px;
  border-top: 1px solid var(--row-border);
  padding-top: 12px;
}

.appearance-setting > .eyebrow {
  margin: 0;
}

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

.appearance-controls select {
  min-width: 120px;
}

input[type="range"] {
  width: 100%;
  height: 28px;
  margin: 0;
  accent-color: var(--accent);
}

.tabs {
  display: flex;
  gap: 3px;
  margin-top: 14px;
}

.tab {
  min-width: 120px;
  border: 0;
  border-radius: 9px 9px 0 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 18px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.tab.is-active {
  background: var(--panel);
  color: var(--text);
}

.pane {
  display: none;
}

.pane.is-active {
  display: block;
}

.program-grid {
  display: grid;
  grid-template-columns: minmax(470px, 0.93fr) minmax(480px, 1.07fr);
  gap: 12px;
  min-height: 485px;
}

.card {
  min-width: 0;
  border-radius: 12px;
  padding: 18px;
}

.card-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 14px;
}

.card h2 {
  font-size: 1rem;
}

.card-heading p {
  font-size: 0.82rem;
}

.table-wrap {
  overflow: auto;
  border-radius: 8px;
  -webkit-overflow-scrolling: touch;
}

.schedule-card,
.chart-card,
.playlist-card {
  display: flex;
  flex-direction: column;
}

.schedule-card .table-wrap,
.playlist-table-wrap {
  flex: 1;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  height: 42px;
  background: var(--table-heading);
  color: var(--muted);
  text-align: center;
}

.data-table td {
  height: 52px;
  border-bottom: 1px solid var(--row-border);
  text-align: center;
}

.data-table tr.is-selected td {
  background: var(--selected-row);
}

.data-table tr.is-current td {
  background: var(--current-row);
  color: var(--playhead);
}

.stage-table th:nth-child(1),
.stage-table td:nth-child(1) {
  width: 60px;
}

.stage-table th:nth-child(2),
.stage-table td:nth-child(2),
.stage-table th:nth-child(3),
.stage-table td:nth-child(3),
.stage-table th:nth-child(4),
.stage-table td:nth-child(4) {
  width: 92px;
}

.cell-input,
.cell-select {
  width: calc(100% - 10px);
  min-height: 44px;
  border: 1px solid transparent;
  background: transparent;
  text-align: center;
  color: inherit;
}

.numeric-input {
  font-size: 16px;
  -webkit-user-select: text;
  user-select: text;
}

.cell-input:focus,
.cell-select:focus {
  background: var(--input);
}

.actions {
  margin-top: 12px;
}

.action-spacer {
  flex: 1;
}

.icon-button {
  width: 44px;
  padding: 0;
  font-size: 1.1rem;
}

.chart-wrap {
  position: relative;
  flex: 1;
  min-height: 360px;
}

#tempoChart {
  display: block;
  width: 100%;
  height: 100%;
}

.playlist-card {
  min-height: 485px;
}

.playlist-heading strong {
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.playlist-add-row {
  margin-bottom: 14px;
}

.playlist-add-row select {
  min-width: 260px;
}

.playlist-table th:nth-child(1),
.playlist-table td:nth-child(1) {
  width: 72px;
}

.playlist-table th:nth-child(3),
.playlist-table td:nth-child(3) {
  width: 140px;
}

.transport {
  position: fixed;
  z-index: 10;
  right: 24px;
  bottom: calc(14px + var(--safe-bottom));
  left: 24px;
  width: min(calc(100% - 48px), 1452px);
  min-height: 102px;
  margin: 0 auto;
  gap: 24px;
  border-radius: 14px;
  padding: 14px 18px;
  box-shadow: var(--transport-shadow);
}

.tempo-status {
  flex: 0 0 105px;
}

.status {
  display: block;
  color: var(--accent);
}

.tempo-status strong {
  font-size: 2rem;
}

.tempo-status div span {
  color: var(--muted);
  font-size: 0.72rem;
}

.beat-dots {
  display: flex;
  flex: 0 1 180px;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-width: 100px;
}

.beat-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--grid);
}

.beat-dot.is-active {
  width: 12px;
  height: 12px;
  background: var(--playhead);
  box-shadow: 0 0 0 5px var(--playhead-halo);
}

.progress {
  flex: 1 1 250px;
  text-align: center;
  font-size: 0.78rem;
  line-height: 1.35;
}

.timer-group {
  flex: 0 0 auto;
  gap: 20px;
}

.timer {
  min-width: 72px;
  text-align: right;
}

.timer span {
  display: block;
  color: var(--muted);
  white-space: nowrap;
}

.timer strong {
  font-size: 1.08rem;
}

.transport-buttons {
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.toast {
  position: fixed;
  z-index: 20;
  right: 50%;
  bottom: calc(132px + var(--safe-bottom));
  max-width: calc(100vw - 40px);
  border-radius: 9px;
  background: var(--toast);
  color: var(--text);
  padding: 10px 15px;
  opacity: 0;
  pointer-events: none;
  transform: translate(50%, 8px);
  transition: 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(50%, 0);
}

.modal {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--grid);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  padding: 22px;
  box-shadow: var(--modal-shadow);
}

.modal::backdrop {
  background: var(--modal-backdrop);
  backdrop-filter: blur(5px);
}

.modal h2 {
  margin: 0 0 18px;
  font-size: 1.05rem;
}

.modal label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.modal input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--grid);
  border-radius: 9px;
  outline: none;
  background: var(--input);
  color: var(--text);
  padding: 10px 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

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

@media (max-width: 1100px) {
  .app-shell {
    padding-inline: 16px;
  }

  .settings-card {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .subdivision-volume-setting {
    grid-column: span 1;
  }

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

  .chart-wrap {
    min-height: 390px;
  }

  .transport {
    right: 12px;
    left: 12px;
    width: calc(100% - 24px);
    gap: 14px;
  }

  .beat-dots {
    display: none;
  }

  .timer-group {
    gap: 12px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: max(14px, env(safe-area-inset-top)) 10px calc(190px + var(--safe-bottom));
  }

  .app-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .preset-bar {
    width: 100%;
    overflow-x: auto;
  }

  .preset-bar select {
    min-width: 190px;
    width: auto;
  }

  .settings-card {
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }

  .subdivision-volume-setting {
    grid-column: 1 / -1;
  }

  .program-grid {
    min-height: 0;
  }

  .card {
    padding: 13px;
  }

  .schedule-card .table-wrap {
    min-height: 310px;
  }

  .stage-table {
    min-width: 570px;
  }

  .playlist-add-row {
    flex-wrap: wrap;
  }

  .playlist-add-row select {
    min-width: 0;
    flex: 1 1 180px;
  }

  .playlist-add-row .action-spacer {
    display: none;
  }

  .transport {
    bottom: calc(6px + var(--safe-bottom));
    display: grid;
    grid-template-columns: auto 1fr auto;
    min-height: 170px;
    padding: 12px;
  }

  .tempo-status {
    grid-column: 1;
    grid-row: 1;
  }

  .progress {
    grid-column: 2 / 4;
    grid-row: 1;
    text-align: right;
  }

  .timer-group {
    grid-column: 1 / 3;
    grid-row: 2;
    justify-content: flex-start;
  }

  .transport-buttons {
    grid-column: 3;
    grid-row: 2;
    justify-content: flex-end;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
