:root {
  --bg: #11110f;
  --panel: #1b1b18;
  --panel-2: #22221e;
  --line: #37372f;
  --text: #eeeeea;
  --muted: #a5a59a;
  --accent: #f2b84b;
  --accent-2: #66d1a6;
  --danger: #ff6a5f;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

.topbar {
  height: 58px;
  display: grid;
  grid-template-columns: auto minmax(260px, 1fr) auto minmax(160px, 260px);
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #171714;
}

.brand {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
}

.search {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto auto;
  gap: 8px;
  min-width: 0;
}

input[type="search"] {
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #10100e;
  color: var(--text);
  font: inherit;
  outline: none;
}

input[type="search"]:focus {
  border-color: var(--accent);
}

textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #10100e;
  color: var(--text);
  font: inherit;
  outline: none;
  resize: vertical;
}

textarea:focus {
  border-color: var(--accent);
}

button {
  height: 36px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

button:disabled:hover {
  border-color: var(--line);
}

.downloadButton {
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.downloadButton:not(.disabled):hover {
  border-color: var(--accent);
}

.downloadButton.disabled {
  cursor: not-allowed;
  opacity: 0.52;
  pointer-events: none;
}

.slider {
  display: grid;
  grid-template-columns: auto 140px 78px;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

input[type="range"] {
  width: 140px;
  accent-color: var(--accent);
}

output {
  text-align: right;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.status {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layout {
  height: calc(100vh - 58px);
  display: grid;
  grid-template-rows: minmax(260px, 1fr) clamp(380px, 42vh, 460px);
}

.mapPanel {
  position: relative;
  min-height: 0;
  border-bottom: 1px solid var(--line);
}

#mapCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}

#mapCanvas.dragging {
  cursor: grabbing;
}

.mapControls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 3;
  display: grid;
  grid-template-columns: auto 36px 36px;
  gap: 6px;
}

.mapControls button {
  height: 34px;
  min-width: 36px;
  padding: 0 10px;
  background: rgba(34, 34, 30, 0.92);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

.tooltip {
  position: absolute;
  z-index: 2;
  max-width: min(520px, calc(100vw - 40px));
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(20, 20, 18, 0.94);
  color: var(--text);
  pointer-events: none;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-size: 13px;
}

.tooltip .name {
  font-weight: 700;
  margin-bottom: 3px;
  overflow-wrap: anywhere;
}

.tooltip .sub {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.detailPanel {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(240px, 360px) minmax(300px, 1fr) minmax(280px, 480px);
  gap: 14px;
  padding: 12px 14px;
  background: var(--panel);
}

.metaBlock,
.playerBlock,
.transcriptBlock,
.transcript {
  min-width: 0;
  min-height: 0;
}

.selectionName {
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 8px;
  overflow-wrap: anywhere;
}

.selectionMeta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.playerBlock {
  display: grid;
  grid-template-rows: 42px minmax(0, 1fr);
  gap: 9px;
}

audio {
  width: 100%;
  height: 38px;
}

.spectrogramStack {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 36px;
  gap: 6px;
}

.referenceRange {
  --range-left: 0%;
  --range-right: 100%;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: visible;
  touch-action: none;
}

.referenceRange.disabled .referenceShade,
.referenceRange.disabled .referenceWindow,
.referenceRange.disabled .referenceHandle,
.referenceRange.ttsDisabled .referenceShade,
.referenceRange.ttsDisabled .referenceWindow,
.referenceRange.ttsDisabled .referenceHandle {
  display: none;
}

#spectrogram {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  object-fit: fill;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0c0c0b;
}

.referenceShade,
.referenceWindow {
  position: absolute;
  top: 1px;
  bottom: 1px;
  pointer-events: none;
  z-index: 2;
}

#referenceShadeLeft {
  left: 1px;
  width: var(--range-left);
  border-radius: 6px 0 0 6px;
  background: rgba(0, 0, 0, 0.48);
}

#referenceShadeRight {
  left: var(--range-right);
  right: 1px;
  border-radius: 0 6px 6px 0;
  background: rgba(0, 0, 0, 0.48);
}

.referenceWindow {
  left: var(--range-left);
  right: calc(100% - var(--range-right));
  border-top: 2px solid rgba(242, 184, 75, 0.9);
  border-bottom: 2px solid rgba(242, 184, 75, 0.9);
}

.referenceHandle {
  position: absolute;
  top: 1px;
  bottom: 1px;
  z-index: 3;
  width: 16px;
  min-width: 16px;
  height: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: ew-resize;
  touch-action: none;
}

.referenceHandle::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 6px;
  width: 4px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow:
    0 0 0 1px rgba(17, 17, 15, 0.85),
    0 0 12px rgba(0, 0, 0, 0.45);
}

.referenceHandle:hover::before,
.referenceHandle:focus-visible::before {
  background: #ffd783;
}

.referenceHandle.left {
  left: var(--range-left);
  transform: translateX(-8px);
}

.referenceHandle.right {
  left: var(--range-right);
  transform: translateX(-8px);
}

.transcript {
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #141412;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.transcriptBlock {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto 164px;
  gap: 9px;
}

.ttsTextBlock {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.ttsTextControls {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.ttsTextControls button {
  min-width: 0;
  padding: 0 10px;
  font-size: 13px;
  line-height: 1.12;
  white-space: normal;
}

.checkControl {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.checkControl input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.ttsTextInput {
  height: 72px;
  min-height: 56px;
  max-height: 142px;
  padding: 8px 9px;
  line-height: 1.35;
}

.ttsPanel {
  min-height: 0;
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 9px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #141412;
}

.ttsSelector {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 36px minmax(0, 1fr);
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.ttsSelector select {
  width: 100%;
  min-width: 0;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #10100e;
  color: var(--text);
  font: inherit;
  outline: none;
}

.ttsStatus {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.ttsPreview {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 32px minmax(0, 1fr);
  gap: 6px;
}

.ttsPreview .downloadButton {
  height: 32px;
}

.ttsPreview .spectrogramStack {
  grid-template-rows: minmax(0, 1fr) 32px;
}

#ttsAudio {
  height: 32px;
}

#ttsSpectrogram {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  object-fit: fill;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0c0c0b;
}

#ttsGenerate {
  align-self: start;
}

.word {
  display: inline-block;
  padding: 0 2px;
  border-radius: 4px;
  color: var(--text);
}

.word.active {
  background: var(--accent);
  color: #11110f;
}

.badge {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12px;
}

.badge.cleaned {
  border-color: rgba(242, 184, 75, 0.55);
  color: var(--accent);
}

.badge.original {
  border-color: rgba(102, 209, 166, 0.55);
  color: var(--accent-2);
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .topbar {
    height: auto;
    grid-template-columns: 1fr;
  }

  .layout {
    height: auto;
    min-height: calc(100vh - 58px);
    grid-template-rows: 58vh auto;
  }

  .detailPanel {
    grid-template-columns: 1fr;
    grid-auto-rows: auto;
  }

  .playerBlock {
    min-height: 220px;
  }

  .transcriptBlock {
    min-height: 300px;
  }

  .ttsPanel {
    grid-template-columns: 1fr;
    grid-template-rows: auto 120px auto;
  }
}
