* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

.info-banner {
  background: #1a2a3e;
  border: 1px solid #2a4a6e;
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 0.85rem;
  color: #a0c0e0;
  line-height: 1.5;
}

.info-banner strong {
  color: #e0e0e0;
}

h2 {
  font-size: 1.1rem;
  font-weight: 500;
  margin-bottom: 12px;
  color: #a0a0c0;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.status-dot.connected { background: #4caf50; }
.status-dot.disconnected { background: #f44336; }

/* Controls */
section {
  margin-bottom: 24px;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

label {
  font-size: 0.9rem;
  color: #a0a0c0;
}

select {
  background: #2a2a3e;
  color: #e0e0e0;
  border: 1px solid #3a3a5e;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 0.9rem;
}

.btn {
  padding: 6px 16px;
  border: 1px solid #3a3a5e;
  border-radius: 4px;
  background: #2a2a3e;
  color: #e0e0e0;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s;
}

.btn:hover { background: #3a3a5e; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary { background: #1565c0; border-color: #1976d2; }
.btn.primary:hover { background: #1976d2; }
.btn.danger { background: #c62828; border-color: #d32f2f; }
.btn.danger:hover { background: #d32f2f; }

details {
  margin-top: 12px;
}

summary {
  cursor: pointer;
  color: #a0a0c0;
  font-size: 0.85rem;
}

#device-list {
  margin-top: 8px;
  font-size: 0.85rem;
  color: #808090;
}

/* Current Turn Display */
#current-turn {
  background: #2a2a3e;
  padding: 16px;
  border-radius: 8px;
}

.turn-text {
  font-size: 1.05rem;
  line-height: 1.5;
  min-height: 2em;
}

.turn-meta {
  font-size: 0.8rem;
  color: #808090;
  margin-top: 6px;
}

#progress-bar-container {
  position: relative;
  height: 8px;
  background: #1a1a2e;
  border-radius: 4px;
  margin-top: 10px;
  overflow: visible;
}

#progress-bar {
  height: 100%;
  background: #1976d2;
  border-radius: 4px;
  width: 0%;
  transition: width 0.1s linear;
}

#hesitation-markers {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.hesitation-marker {
  position: absolute;
  top: -2px;
  height: 12px;
  background: rgba(255, 193, 7, 0.5);
  border-radius: 2px;
}

.hidden { display: none; }

/* Summary Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}

.stat {
  background: #2a2a3e;
  padding: 12px;
  border-radius: 6px;
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.75rem;
  color: #808090;
  margin-bottom: 4px;
}

.stat-value {
  display: block;
  font-size: 1.2rem;
  font-weight: 600;
}

/* Turn Table */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  table-layout: fixed;
}

thead th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid #3a3a5e;
  color: #a0a0c0;
  font-weight: 500;
  white-space: nowrap;
}

tbody td {
  padding: 6px 10px;
  border-bottom: 1px solid #2a2a3e;
  vertical-align: top;
}

tbody tr:hover {
  background: #2a2a3e;
}

tbody tr.active {
  background: #1a3a5e;
}

tbody tr.barge-in {
  background: rgba(255, 152, 0, 0.15);
}

.summary-row {
  border-top: 2px solid #3a3a5e;
  background: #1a1a2e;
}

.summary-row:hover {
  background: #1a1a2e;
}

.text-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ttfa-cell { font-weight: 600; }
.ttfa-green { color: #4caf50; }
.ttfa-yellow { color: #ffc107; }
.ttfa-red { color: #f44336; }
.ttfa-negative { color: #e040fb; }

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 500;
}

.status-pending { background: #3a3a5e; color: #808090; }
.status-playing { background: #1565c0; color: #fff; }
.status-listening { background: #6a1b9a; color: #fff; }
.status-done { background: #2e7d32; color: #fff; }
.status-barge_in { background: #e65100; color: #fff; }
.status-no_response { background: #616161; color: #fff; }
.status-skipped { background: #3a3a5e; color: #606060; }

.btn-play-single {
  background: none;
  border: 1px solid #3a3a5e;
  color: #a0a0c0;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
}

.turn-num {
  color: #8aa0ff;
  text-decoration: none;
  cursor: pointer;
}
.turn-num:hover {
  text-decoration: underline;
  color: #c5d1ff;
}

/* Audio Devices + Turn-types key side-by-side under #controls. */
.config-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  margin-top: 8px;
}
.config-grid > details {
  min-width: 0;
}
@media (max-width: 900px) {
  .config-grid {
    grid-template-columns: 1fr;
  }
}

dl.cat-key {
  margin: 6px 0 0 0;
  font-size: 0.85rem;
  color: #c0c0d8;
}
dl.cat-key dt {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-weight: 600;
}
dl.cat-key dt:first-child {
  margin-top: 0;
}
dl.cat-key dd {
  margin: 2px 0 0 0;
  color: #9090b0;
  line-height: 1.35;
}
dl.cat-key em {
  color: #8a8aa8;
  font-style: italic;
  font-size: 0.9em;
}
dl.cat-key code {
  background: #1a1a2e;
  border: 1px solid #2a2a4a;
  border-radius: 3px;
  padding: 1px 4px;
  font-size: 0.8em;
  color: #c5d1ff;
  font-weight: 400;
}

/* Inline summary strip in the turn table's footer row. Same muted
 * weight/colour the old "Average" label used; one row so screen
 * recordings end on the headline numbers. */
td.summary-strip {
  text-align: right;
  font-weight: 600;
  color: #a0a0c0;
  padding: 8px 12px;
}
td.summary-strip span {
  margin-left: 18px;
}
td.summary-strip span:first-child {
  margin-left: 0;
}
td.summary-strip b {
  color: #e0e0e8;
  font-weight: 700;
  margin-left: 4px;
}

.btn-play-single:hover {
  background: #3a3a5e;
  color: #e0e0e0;
}

/* Category badges */
.type-cell {
  white-space: nowrap;
}

.category-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 500;
}

.cat-normal { background: #2e7d32; color: #fff; }
.cat-hesitation { background: #e65100; color: #fff; }
.cat-hesitation2 { background: #bf360c; color: #fff; }
.cat-pause { background: #6a1b9a; color: #fff; }
.cat-ambiguous { background: #0277bd; color: #fff; }

.gap-label {
  display: inline-block;
  margin-left: 4px;
  font-size: 0.7rem;
  color: #a0a0c0;
  font-weight: 600;
}

/* Header Setup button */
header { gap: 12px; }
header #btn-setup { margin-left: auto; }

/* Audition button (in-browser preview) */
.btn-audition {
  background: transparent;
  border: 1px solid #3a3a5a;
  color: #e0e0e0;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 0.9rem;
  cursor: pointer;
  margin-right: 4px;
}
.btn-audition:hover { background: #2a2a4a; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}
.modal-panel {
  position: relative;
  background: #1a1a2e;
  border: 1px solid #2a2a4a;
  border-radius: 8px;
  width: min(720px, 92vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid #2a2a4a;
}
.modal-head h2 { margin: 0; color: #e0e0e0; }
.modal-close {
  background: transparent;
  border: 0;
  color: #a0a0c0;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  font-size: 0.9rem;
  line-height: 1.55;
}
.modal-body h3 {
  font-size: 1rem;
  color: #e0e0e0;
  margin: 14px 0 6px;
}
.modal-body h3:first-child { margin-top: 0; }
.modal-body h4 {
  font-size: 0.92rem;
  color: #c0c0e0;
  margin: 10px 0 4px;
}
.modal-body p { margin: 6px 0; }
.modal-body ul,
.modal-body ol {
  margin: 6px 0 8px 22px;
}
.modal-body li { margin: 3px 0; }
.modal-body code {
  background: #2a2a4a;
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 0.85rem;
}
.modal-body pre {
  background: #11111e;
  border: 1px solid #2a2a4a;
  border-radius: 4px;
  padding: 8px 10px;
  overflow-x: auto;
  margin: 4px 0 8px;
}
.modal-body pre code { background: transparent; padding: 0; }

/* Audio device picker — one row per slot */
.device-grid {
  display: grid;
  gap: 14px;
  padding: 8px 0 4px;
}
.device-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
}
.device-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}
.device-dot {
  font-size: 0.8rem;
  line-height: 1;
}
.device-select {
  background: #11111e;
  color: #e0e0e0;
  border: 1px solid #2a2a4a;
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 0.85rem;
  width: 100%;
}
.device-select:focus { outline: 1px solid #4a6ee0; border-color: #4a6ee0; }
.device-hint {
  font-size: 0.78rem;
  color: #8888a0;
  line-height: 1.4;
}

/* Browser-mode toggle */
.mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 16px;
  font-size: 0.85rem;
  color: #c0c0e0;
  cursor: pointer;
}
.mode-toggle input { cursor: pointer; }

/* Device-picker notes / warning */
.device-note {
  font-size: 0.85rem;
  color: #a0a0c0;
  padding: 8px 10px;
  background: #11111e;
  border: 1px solid #2a2a4a;
  border-radius: 4px;
  margin-bottom: 10px;
}
.device-note .btn {
  margin-left: 8px;
  font-size: 0.85rem;
}
.device-warn {
  border-color: #6a4a1c;
  background: #2a1a08;
  color: #f0c060;
}

/* Auto-picked tag on a device slot */
.device-auto-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 8px;
  background: #2a2a4a;
  color: #a0c0e0;
  font-size: 0.7rem;
  font-weight: 600;
  margin-left: 8px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Live input amplitude meter */
.meter-wrap {
  margin-top: 6px;
  font-size: 0.8rem;
  color: #a0a0c0;
}
.meter-bar {
  position: relative;
  height: 10px;
  background: #11111e;
  border: 1px solid #2a2a4a;
  border-radius: 3px;
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2d6cdf, #4a90ff);
  transition: width 60ms linear;
}
.meter-fill.over-threshold {
  background: linear-gradient(90deg, #2e7d32, #5cc26b);
}
.meter-threshold {
  /* Browser VAD threshold at RMS 0.003, scaled against METER_MAX_RMS=0.2 -> 1.5% */
  position: absolute;
  top: -1px;
  bottom: -1px;
  left: 1.5%;
  width: 1px;
  background: #f0c060;
}
.meter-readout {
  margin-top: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
}
.meter-label { color: #8888a0; }

/* Copy button on modal code blocks */
.modal-body pre { position: relative; }
.copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: #2a2a4a;
  color: #e0e0e0;
  border: 1px solid #3a3a5a;
  border-radius: 3px;
  padding: 2px 8px;
  font-size: 0.75rem;
  cursor: pointer;
  opacity: 0.75;
}
.copy-btn:hover { opacity: 1; }
.copy-btn.copied { background: #2e7d32; border-color: #4caf50; opacity: 1; }

/* Streamlined setup steps */
.modal-body ol.setup-steps {
  margin: 12px 0 10px 22px;
  display: grid;
  gap: 12px;
}
.modal-body ol.setup-steps > li {
  padding-left: 4px;
}
.modal-body ol.setup-steps > li > strong:first-child {
  display: inline-block;
  margin-right: 4px;
}
.modal-body p.setup-note {
  background: #11111e;
  border-left: 3px solid #4a6ee0;
  padding: 8px 12px;
  margin: 10px 0 4px;
  font-size: 0.85rem;
  color: #c0c0e0;
}

/* Why / how subnotes inside each setup step */
.modal-body ol.setup-steps p.step-why,
.modal-body ol.setup-steps p.step-how {
  margin: 4px 0 0;
  font-size: 0.82rem;
  color: #a8a8c0;
  line-height: 1.5;
}
.modal-body ol.setup-steps p.step-how em:first-child,
.modal-body ol.setup-steps p.step-why em:first-child {
  color: #c0c0e0;
  font-style: normal;
  font-weight: 600;
}
