:root {
  color-scheme: dark;
  --bg: #101418;
  --panel: #182026;
  --panel-2: #202a2f;
  --line: #33414a;
  --text: #f4f7f5;
  --muted: #aab5b5;
  --mint: #70d6b8;
  --amber: #f2bd5a;
  --coral: #f06458;
  --sky: #80b7ff;
  --ui-scale: 1;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: calc(14px * var(--ui-scale));
}

button,
textarea,
input {
  font: inherit;
}

button,
.import-button,
.file-card {
  min-height: calc(34px * var(--ui-scale));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

button:active,
.import-button:active,
.file-card:active {
  transform: translateY(1px);
}

.app-shell {
  width: min(820px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(calc(12px * var(--ui-scale)), env(safe-area-inset-top)) calc(12px * var(--ui-scale)) max(calc(24px * var(--ui-scale)), env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--mint);
  font-size: 0.76rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 1.55rem;
  line-height: 1.1;
}

.top-actions {
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: 6px;
  justify-content: end;
  min-width: 210px;
}

.status-pill {
  grid-column: 1 / -1;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

.mini-button {
  min-height: 32px;
  padding: 0 6px;
  font-size: 0.74rem;
}

.audio-panel,
.tab-panel,
.timeline-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: calc(10px * var(--ui-scale));
}

.file-card {
  display: grid;
  gap: 4px;
  padding: 10px;
}

.file-card input,
.import-button input {
  display: none;
}

.file-label,
.text-field span,
.hint,
.counter,
.queue-header,
.timeline-toolbar {
  color: var(--muted);
  font-size: 0.82rem;
}

canvas,
.wave-wrap,
.wave-marker-layer,
.wave-marker,
.transport,
.history-actions,
.timeline-track,
.timeline-block,
.timeline-handle {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.wave-wrap {
  position: relative;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#waveform,
#timelineWaveform {
  display: block;
  width: 100%;
  height: calc(74px * var(--ui-scale));
  margin: 10px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b0e10;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.wave-marker-layer {
  position: absolute;
  inset: 10px 0;
  pointer-events: none;
}

.wave-marker-layer.editable {
  pointer-events: auto;
}

.wave-marker {
  position: absolute;
  width: 18px;
  height: 18px;
  margin-left: -9px;
  border: 2px solid #101418;
  border-radius: 50%;
  padding: 0;
  min-height: 18px;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.wave-marker[disabled] {
  pointer-events: none;
}

.wave-marker.start {
  top: 2px;
  background: var(--mint);
}

.wave-marker.end {
  bottom: 2px;
  background: var(--coral);
}

.wave-tip {
  position: absolute;
  top: 8px;
  left: 8px;
  display: none;
  padding: 6px 8px;
  border: 1px solid rgba(242, 189, 90, 0.8);
  border-radius: 8px;
  background: rgba(11, 14, 16, 0.94);
  color: var(--amber);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.wave-tip.show {
  display: block;
}

.playhead-time {
  position: absolute;
  top: 2px;
  left: calc(50% + 9px);
  z-index: 36;
  min-width: 78px;
  padding: 3px 7px;
  transform: none;
  border: 1px solid rgba(242, 189, 90, 0.68);
  border-radius: 6px;
  background: rgba(11, 14, 16, 0.92);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  color: var(--amber);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  pointer-events: none;
}

.time-row {
  display: grid;
  grid-template-columns: 78px 1fr 78px;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
}

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

.transport,
.quick-grid,
.export-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  align-items: center;
}

.history-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 8px 0 0;
}

.history-actions button {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 12px;
  font-weight: 700;
}

.undo-strong {
  border-color: rgba(112, 214, 184, 0.86);
  background: #173f34;
}

.redo-strong {
  border-color: rgba(128, 183, 255, 0.9);
  background: #183652;
}

.transport button,
.quick-grid button,
.export-grid button,
.import-button {
  flex: 0 0 auto;
  width: auto;
  padding: 0 12px;
}

.primary {
  border-color: rgba(112, 214, 184, 0.7);
  background: #214138;
}

button.active {
  border-color: var(--amber);
  background: #4c3517;
}

.danger,
.stamp-button {
  border-color: rgba(240, 100, 88, 0.82);
  background: #5a211f;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: 0.9fr 0.9fr 1.45fr;
  gap: 8px;
  margin: 12px 0;
  padding: 8px 0;
  background: var(--bg);
}

.tab {
  background: transparent;
}

.tab.active {
  border-color: var(--sky);
  background: #1c3147;
  box-shadow: 0 0 0 2px rgba(128, 183, 255, 0.28);
}

.timeline-tab {
  min-height: calc(50px * var(--ui-scale));
  padding-inline: 16px;
  border-width: 2px;
  border-color: rgba(112, 214, 184, 0.72);
  background: rgba(23, 63, 52, 0.72);
  color: #e9fff7;
  font-size: 1.04rem;
  font-weight: 800;
  box-shadow: 0 0 0 1px rgba(112, 214, 184, 0.18), inset 0 0 0 1px rgba(112, 214, 184, 0.08);
}

.timeline-tab.active {
  border-color: rgba(112, 214, 184, 0.95);
  background: #174f40;
  box-shadow: 0 0 0 3px rgba(112, 214, 184, 0.28);
}

.tab-panel,
.timeline-panel {
  display: none;
}

.tab-panel.active,
.timeline-panel.active {
  display: block;
}

.export-modal {
  position: fixed;
  left: 12px;
  right: 12px;
  top: max(72px, env(safe-area-inset-top));
  z-index: 40;
  max-height: calc(100vh - 96px);
  overflow: auto;
  border: 2px solid rgba(242, 189, 90, 0.92);
  background: linear-gradient(180deg, #2a2114 0%, #151d22 42%, #101418 100%);
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.48), 0 20px 70px rgba(0, 0, 0, 0.68), 0 0 0 4px rgba(242, 189, 90, 0.18);
}

.export-modal.open {
  display: block;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  color: #fff3d0;
}

.modal-head button {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 14px;
  border-color: rgba(240, 100, 88, 0.95);
  background: #6a2420;
  color: #fff8f0;
  font-weight: 800;
}

.bottom-play-row {
  display: flex;
  justify-content: center;
  margin: 12px 0 8px;
}

.play-large {
  min-height: calc(54px * var(--ui-scale));
  min-width: min(360px, 88%);
  padding: 0 24px;
  font-size: 1.08rem;
  font-weight: 800;
}

.stamp-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
}

.stamp-actions {
  display: grid;
  gap: 6px;
  align-self: start;
}

.subtabs {
  display: flex;
  gap: 8px;
  margin: 12px 0 8px;
}

.subtab {
  padding: 0 12px;
}

.subtab.active {
  border-color: var(--sky);
  background: #1c3147;
}

#queueTab.active {
  border-color: rgba(128, 183, 255, 0.96);
  background: #173452;
  color: #eaf4ff;
}

#doneTab.active {
  border-color: rgba(242, 189, 90, 0.96);
  background: #4b3517;
  color: #fff3d0;
}

.subpane {
  display: none;
}

.subpane.active {
  display: block;
  border: 1px solid rgba(128, 183, 255, 0.7);
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 0 0 2px rgba(128, 183, 255, 0.13);
}

#donePane.active {
  border-color: rgba(242, 189, 90, 0.78);
  box-shadow: 0 0 0 2px rgba(242, 189, 90, 0.14);
}

.now-card {
  min-height: calc(76px * var(--ui-scale));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #11181d;
}

.now-card p {
  margin: 6px 0 0;
  font-size: 1.2rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.stamp-button {
  align-self: start;
  min-height: calc(38px * var(--ui-scale));
  width: auto;
  padding: 0 12px;
  color: #fff7f4;
  font-size: 0.9rem;
  font-weight: 800;
}

#stamp {
  min-height: calc(76px * var(--ui-scale));
  padding: 0 18px;
  font-size: 1.06rem;
}

.secondary-end {
  border-color: rgba(242, 189, 90, 0.82);
  background: #4c3517;
}

.queue-header {
  display: flex;
  justify-content: space-between;
  margin: 12px 2px 6px;
}

.queue-list,
.block-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: visible;
  overscroll-behavior: contain;
}

.queue-list {
  max-height: none;
  padding-right: 2px;
}

.block-list {
  max-height: calc(230px * var(--ui-scale));
}

.queue-list li,
.block-list li {
  display: grid;
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11181d;
}

.queue-list li {
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  min-height: calc(58px * var(--ui-scale));
}

.queue-list li.insert-row {
  display: flex;
  justify-content: center;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.insert-line-button {
  min-height: 24px;
  padding: 0 10px;
  border-style: dashed;
  color: var(--muted);
  font-size: 0.72rem;
}

.insert-line-button:focus,
.insert-line-button:active {
  color: var(--text);
  border-color: var(--mint);
}

.queue-list li.active {
  border-color: var(--amber);
}

.block-list li {
  grid-template-columns: 68px 1fr 42px;
}

.time,
.queue-index {
  color: var(--amber);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.queue-text,
.block-text {
  min-height: 36px;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  overflow-wrap: anywhere;
  resize: none;
  text-align: left;
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
  cursor: text;
}

.queue-text:focus,
.block-text:focus {
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px var(--mint);
  background: rgba(112, 214, 184, 0.08);
  padding: 6px;
}

.text-field {
  display: grid;
  gap: 6px;
}

textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #0b0e10;
  color: var(--text);
  line-height: 1.45;
}

.import-button {
  display: grid;
  place-items: center;
  padding: 0 10px;
  text-align: center;
}

.hint {
  margin: 10px 0 0;
}

body.timeline-mode .audio-panel,
body.timeline-mode .tabs,
body.timeline-mode .tab-panel {
  display: none;
}

body.timeline-mode .timeline-panel {
  display: block;
}

.timeline-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.timeline-toolbar button {
  flex: 0 0 auto;
  min-height: 30px;
  padding: 0 8px;
  font-size: 0.78rem;
}

#timelineTime {
  margin-left: auto;
  color: var(--amber);
  font-variant-numeric: tabular-nums;
}

.desktop-wave {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b0e10;
  padding: 8px;
  touch-action: none;
}

.desktop-wave::after {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 50%;
  z-index: 4;
  width: 3px;
  transform: translateX(-1px);
  background: var(--amber);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.desktop-wave #timelineWaveform {
  margin: 0;
  border: 0;
}

.timeline-track-wrap {
  position: relative;
  margin-top: 10px;
}

.timeline-track {
  position: relative;
  min-height: calc(420px * var(--ui-scale));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  background:
    repeating-linear-gradient(to right, rgba(128, 183, 255, 0.16) 0 1px, transparent 1px 80px),
    #11181d;
  touch-action: none;
}

.timeline-track::after {
  display: none;
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  z-index: 8;
  width: 3px;
  transform: translateX(-1px);
  background: var(--amber);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.timeline-center-line {
  position: absolute;
  top: 1px;
  bottom: 1px;
  left: 50%;
  z-index: 30;
  width: 3px;
  transform: translateX(-1px);
  background: var(--amber);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.timeline-time-float {
  top: 4px;
}

.timeline-track.grabbing {
  cursor: grabbing;
}

.timeline-canvas {
  position: relative;
  min-width: 900px;
  min-height: calc(420px * var(--ui-scale));
}

.timeline-playhead {
  display: none;
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--amber);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.timeline-block {
  position: absolute;
  height: 50px;
  min-width: 0;
  padding: 5px 18px;
  border: 1px solid rgba(112, 214, 184, 0.72);
  border-radius: 8px;
  background: rgba(33, 65, 56, 0.95);
  color: var(--text);
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.timeline-block.compact {
  padding: 3px 4px;
}

.timeline-block.tiny {
  padding: 0;
  border-radius: 3px;
}

.timeline-block.selected {
  border-color: var(--amber);
  box-shadow: 0 0 0 2px rgba(242, 189, 90, 0.24);
}

.timeline-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 18px;
  background: rgba(244, 247, 245, 0.18);
}

.timeline-block.compact .timeline-handle,
.timeline-block.tiny .timeline-handle {
  display: none;
}

.timeline-handle.left {
  left: 0;
}

.timeline-handle.right {
  right: 0;
}

.delete-small {
  min-height: 34px;
  padding: 0 6px;
  font-size: 0.76rem;
}

.scale-popover {
  position: fixed;
  top: max(64px, env(safe-area-inset-top));
  right: 10px;
  z-index: 20;
  display: none;
  grid-template-columns: repeat(3, 58px);
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 20, 24, 0.98);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
}

.scale-popover.open {
  display: grid;
}

.scale-popover button {
  min-height: 34px;
  font-size: 0.78rem;
}

.timeline-block small {
  display: block;
  color: var(--amber);
  font-size: 0.7rem;
}

.timeline-block span {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-block.compact small,
.timeline-block.compact span,
.timeline-block.tiny small,
.timeline-block.tiny span {
  display: none;
}

.timeline-ruler-label {
  position: absolute;
  top: 4px;
  transform: translateX(-50%);
  color: rgba(244, 247, 245, 0.82);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.timeline-ruler-tick {
  position: absolute;
  top: 22px;
  width: 1px;
  height: 100%;
  background: rgba(128, 183, 255, 0.18);
  pointer-events: none;
}

@media (max-width: 420px) {
  .top-actions {
    min-width: 190px;
  }
}

@media (min-width: 760px) {
  .app-shell {
    padding-top: 22px;
  }
}

.site-footer {
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 18px 0 28px;
  color: var(--muted);
  font-size: 0.84rem;
}

.site-footer a,
.legal-page a {
  color: var(--accent);
  text-decoration: none;
}

.legal-page {
  min-height: 100vh;
  padding-top: 48px;
  line-height: 1.65;
}

.legal-page h1 {
  margin: 0 0 18px;
  font-size: 2rem;
}

.legal-page p {
  color: var(--text);
  margin: 0 0 14px;
}
