:root {
  --primary: #6707ed;
  --bg: #1e2530;
  --container-bg: #2b3240;
  --surface: #343d4e;
  --border: #4a5568;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #74c0fc;
  --accent-hover: #a5d8ff;
  --filled: #4a6fa5;
  --filled-text: #e2e8f0;
  --highlighted: #7bb661;
  --heard-green: #2ecc71;
}

* {
  box-sizing: border-box;
}

body {
  font-family:
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    sans-serif;
  background-color: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
}

a.icon-btn {
  text-decoration: none;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--surface);
  border-color: var(--accent);
  color: var(--accent);
}

.layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  max-width: 700px;
  margin: auto;
  padding: 1rem 1rem 3rem;
}

h1 {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 0;
  background: linear-gradient(135deg, var(--accent) 0%, var(--primary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  background: var(--container-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  max-width: 520px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.4rem 0.9rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.modal-close:hover {
  color: var(--text);
  background: var(--surface);
}

.modal-body {
  overflow-y: auto;
  padding: 1.2rem 1.4rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.modal-body section {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.modal-body h3 {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
}

.modal-body p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.55;
}

.modal-body strong {
  color: var(--text);
  font-weight: 600;
}

.help-table {
  border-collapse: collapse;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.help-table td {
  padding: 0.25rem 0.75rem 0.25rem 0;
  vertical-align: middle;
}

kbd {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.8rem;
  color: var(--text);
}

/* ── Controls Fieldset ── */
.controls-fieldset {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--container-bg);
  padding: 1rem 1.2rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.controls-fieldset legend {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 0 0.5rem;
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.25rem;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.control-group label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* File input — hidden, triggered by styled label */
input[type="file"] {
  display: none;
}

.file-btn {
  display: inline-block;
  padding: 0.4rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 7px;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.18s,
    color 0.18s;
}

.file-btn:hover {
  background: var(--accent);
  color: #111;
}

.file-name {
  font-size: 0.8rem;
  color: var(--text-muted);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Stop button */
.stop-btn {
  padding: 0.45rem 1.1rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.18s,
    border-color 0.18s,
    color 0.18s;
}

.stop-btn:hover:not(:disabled) {
  background: #4a1515;
  border-color: #e05555;
  color: #f99;
}

.stop-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Loop checkbox */
.loop-group label {
  cursor: pointer;
}

input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
  cursor: pointer;
  accent-color: var(--primary);
}

/* Loop length radio group */
.loop-length-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: 0.5rem;
  visibility: hidden;
}

.loop-length-group label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}

.loop-length-group input[type="radio"] {
  accent-color: var(--primary);
  cursor: pointer;
}

/* ── Two-column button grid ── */
.btn-column-wrapper {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2.5rem;
  width: 100%;
}

.btn-column {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
}

.btn-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.column-header {
  margin: 0 0 0.25rem;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 0.25rem 0.4rem;
  border-bottom: 1px solid var(--border);
  border-radius: 4px 4px 0 0;
  outline: none;
  white-space: nowrap;
  overflow: hidden;
  cursor: text;
}

.column-header:hover {
  background: var(--surface);
}

.column-header:focus {
  background: var(--surface);
  border-bottom-color: var(--accent);
  color: var(--text);
}

/* Volume buttons */
button[data-volume] {
  border: 1px solid var(--accent);
  border-radius: 6px;
  background-color: transparent;
  color: var(--accent-hover);
  cursor: pointer;
  font-weight: 700;
  font-size: max(0.9rem, min(3vw, 1.1rem));
  padding: 0.45rem 0;
  flex: 1;
  position: relative;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s,
    transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}

button[data-volume]::before {
  content: "▶";
  font-size: 0.6em;
  opacity: 0;
  position: absolute;
  left: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  transition: opacity 0.15s;
}

button[data-volume]:hover {
  background-color: var(--accent);
  color: #111;
}

button[data-volume]:hover::before {
  opacity: 1;
}

button[data-volume]:active {
  transform: scale(0.97);
  background-color: var(--accent-hover);
  color: #111;
}

button[data-volume].filled {
  background-color: var(--filled);
  border-color: var(--filled);
  color: var(--filled-text);
}

button[data-volume].highlighted {
  background-color: var(--highlighted);
  border-color: var(--highlighted);
  color: #111;
}

button[data-volume].active {
  border-width: 2px;
  border-color: #fff;
  box-shadow:
    0 0 0 3px rgba(116, 192, 252, 0.45),
    0 0 12px rgba(116, 192, 252, 0.25);
  color: #fff;
}

button[data-volume].active::before {
  opacity: 1;
}

/* Playing indicator — animated sound bars */
.playing-indicator {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  width: 100%;
  height: 14px;
  opacity: 0;
  transition: opacity 0.2s;
}

.btn-column.playing .playing-indicator {
  opacity: 1;
}

.playing-indicator span {
  display: block;
  flex: 1;
  background: var(--accent);
  border-radius: 1px 1px 0 0;
  height: 2px;
}

.btn-column.playing .playing-indicator span {
  animation: soundBar 0.7s ease-in-out infinite alternate;
}

.btn-column.playing .playing-indicator span:nth-child(1)  { animation-delay: 0.00s; animation-duration: 0.65s; }
.btn-column.playing .playing-indicator span:nth-child(2)  { animation-delay: 0.10s; animation-duration: 0.80s; }
.btn-column.playing .playing-indicator span:nth-child(3)  { animation-delay: 0.20s; animation-duration: 0.55s; }
.btn-column.playing .playing-indicator span:nth-child(4)  { animation-delay: 0.05s; animation-duration: 0.90s; }
.btn-column.playing .playing-indicator span:nth-child(5)  { animation-delay: 0.30s; animation-duration: 0.70s; }
.btn-column.playing .playing-indicator span:nth-child(6)  { animation-delay: 0.15s; animation-duration: 0.60s; }
.btn-column.playing .playing-indicator span:nth-child(7)  { animation-delay: 0.25s; animation-duration: 0.85s; }
.btn-column.playing .playing-indicator span:nth-child(8)  { animation-delay: 0.08s; animation-duration: 0.75s; }
.btn-column.playing .playing-indicator span:nth-child(9)  { animation-delay: 0.35s; animation-duration: 0.65s; }
.btn-column.playing .playing-indicator span:nth-child(10) { animation-delay: 0.18s; animation-duration: 0.50s; }
.btn-column.playing .playing-indicator span:nth-child(11) { animation-delay: 0.12s; animation-duration: 0.88s; }
.btn-column.playing .playing-indicator span:nth-child(12) { animation-delay: 0.28s; animation-duration: 0.72s; }
.btn-column.playing .playing-indicator span:nth-child(13) { animation-delay: 0.03s; animation-duration: 0.62s; }
.btn-column.playing .playing-indicator span:nth-child(14) { animation-delay: 0.22s; animation-duration: 0.82s; }
.btn-column.playing .playing-indicator span:nth-child(15) { animation-delay: 0.38s; animation-duration: 0.58s; }
.btn-column.playing .playing-indicator span:nth-child(16) { animation-delay: 0.14s; animation-duration: 0.76s; }
.btn-column.playing .playing-indicator span:nth-child(17) { animation-delay: 0.07s; animation-duration: 0.69s; }
.btn-column.playing .playing-indicator span:nth-child(18) { animation-delay: 0.23s; animation-duration: 0.83s; }
.btn-column.playing .playing-indicator span:nth-child(19) { animation-delay: 0.33s; animation-duration: 0.57s; }
.btn-column.playing .playing-indicator span:nth-child(20) { animation-delay: 0.11s; animation-duration: 0.91s; }
.btn-column.playing .playing-indicator span:nth-child(21) { animation-delay: 0.19s; animation-duration: 0.64s; }
.btn-column.playing .playing-indicator span:nth-child(22) { animation-delay: 0.29s; animation-duration: 0.78s; }
.btn-column.playing .playing-indicator span:nth-child(23) { animation-delay: 0.04s; animation-duration: 0.53s; }
.btn-column.playing .playing-indicator span:nth-child(24) { animation-delay: 0.36s; animation-duration: 0.87s; }
.btn-column.playing .playing-indicator span:nth-child(25) { animation-delay: 0.16s; animation-duration: 0.61s; }
.btn-column.playing .playing-indicator span:nth-child(26) { animation-delay: 0.26s; animation-duration: 0.74s; }
.btn-column.playing .playing-indicator span:nth-child(27) { animation-delay: 0.09s; animation-duration: 0.89s; }
.btn-column.playing .playing-indicator span:nth-child(28) { animation-delay: 0.31s; animation-duration: 0.67s; }
.btn-column.playing .playing-indicator span:nth-child(29) { animation-delay: 0.21s; animation-duration: 0.81s; }
.btn-column.playing .playing-indicator span:nth-child(30) { animation-delay: 0.13s; animation-duration: 0.56s; }
.btn-column.playing .playing-indicator span:nth-child(31) { animation-delay: 0.37s; animation-duration: 0.93s; }
.btn-column.playing .playing-indicator span:nth-child(32) { animation-delay: 0.02s; animation-duration: 0.71s; }

@keyframes soundBar {
  from { height: 2px; }
  to   { height: 14px; }
}

/* Audio players — hidden but functional */
.audio-player {
  display: none;
}

/* Heard indicator */
.heard-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid var(--border);
  border-radius: 4px;
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.4;
  cursor: pointer;
  transition:
    opacity 0.15s,
    background-color 0.15s,
    border-color 0.15s;
}

.heard-indicator:hover {
  opacity: 0.7;
  border-color: var(--heard-green);
}

.heard-indicator.heard {
  opacity: 1;
  background-color: var(--heard-green);
  border-color: #27ae60;
  color: #111;
}
