/* ── MOCHA-TIMIT Explorer — Style ── */

:root {
  /* Dark canvas theme inspired by Praat/ESPS */
  --bg:          #0e1117;
  --bg-card:     #161b22;
  --bg-raised:   #1c2128;
  --border:      #30363d;
  --text:        #e6edf3;
  --text-dim:    #8b949e;
  --text-muted:  #484f58;
  --accent:      #58a6ff;    /* cyan blue, like a Praat cursor */
  --accent-glow: #58a6ff44;
  --green:       #3fb950;
  --gold:        #d29922;
  --red:         #f85149;
  --orange:      #db6d28;
  --pink:        #f778ba;

  --font-body:   'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono:   'DM Mono', 'SF Mono', 'Fira Code', monospace;
  --font-display:'Playfair Display', Georgia, serif;

  --tab-h:       56px;
  --header-h:    64px;
  --radius:      8px;
}

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

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ── Header ── */

#header {
  /* height removed — now auto-sized by content */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 6px 16px 8px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg) 100%);
  flex-shrink: 0;
  gap: 4px;
}

.header-top-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  justify-content: center;
}

.header-title {
  font-family: var(--font-display);
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
}

/* Sentence picker (speaker + utt dropdowns) */
.sentence-picker {
  display: flex;
  gap: 6px;
  align-items: center;
}

.picker-select {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 2px 8px 3px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  cursor: pointer;
  max-width: 180px;
  outline: none;
  transition: border-color 0.15s;
}

.picker-select:hover {
  border-color: var(--text-muted);
}

.picker-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.picker-select:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.picker-utt {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.74rem;
  color: var(--text-dim);
  line-height: 1.3;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge-speaker {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--accent);
  color: var(--bg);
  font-weight: 500;
  flex-shrink: 0;
}

.quote {
  font-family: var(--font-display);
  font-style: italic;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Loading overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(14, 17, 23, 0.85);
  backdrop-filter: blur(4px);
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* ── Main Content ── */

#content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px calc(var(--tab-h) + 16px);
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

/* ── Tab Panels ── */

.tab-panel {
  display: none;
}

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

/* ── Shared audio mini-components (hidden in original DOM, cloned into slots) ── */

.audio-comp {
  display: none !important;  /* hide the source containers in the hidden archive */
}

/* But once moved into a visible tab slot, show them */
.tab-audio-body .audio-comp {
  display: block !important;
}

/* ── Tab audio body: slot container that draws components at bottom of each tab ── */

.tab-audio-body {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 14px 20px;
  align-items: flex-start;
}

/* Audio tab: waveform on top (full-width), controls+transcript side-by-side below */
#tab-audio .tab-audio-body {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

/* Compact mode inside the tab audio body */
.tab-audio-body .btn-play {
  width: 36px;
  height: 36px;
}

.tab-audio-body .btn-play svg {
  width: 22px;
  height: 22px;
}

.tab-audio-body #audio-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.tab-audio-body #time-display {
  font-size: 0.82rem;
}

/* Transcript inside tab audio body */
.tab-audio-body #transcript-container {
  flex: 1;
  min-width: 0;
  margin-top: 0;
  padding: 10px 12px;
  background: rgba(22, 27, 34, 0.5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.tab-audio-body .transcript-word {
  font-size: 0.95rem;
  padding: 3px 6px;
}

.tab-audio-body .phoneme-seg {
  font-size: 0.72rem;
  padding: 1px 4px;
}

/* Waveform inside tab audio body (Audio tab only) */
.tab-audio-body #waveform-container {
  width: 100%;
  height: 120px;
  min-height: 80px;
}

/* ── Audio tab layout overrides ── */

/* Waveform takes full width on row 1 */
#tab-audio .tab-audio-body #waveform-container {
  flex-basis: 100%;
}

/* Controls and Transcript share row 2 */
#tab-audio .tab-audio-body #audio-controls {
  flex-shrink: 0;
  gap: 14px;
}

#tab-audio .tab-audio-body .btn-play {
  width: 44px;
  height: 44px;
}

#tab-audio .tab-audio-body .btn-play svg {
  width: 28px;
  height: 28px;
}

#tab-audio .tab-audio-body #transcript-container {
  flex: 1;
  min-width: 0;
}

#tab-audio .tab-audio-body .transcript-word {
  font-size: 1.1rem;
  padding: 4px 8px;
}

#tab-audio .tab-audio-body .phoneme-seg {
  font-size: 0.78rem;
  padding: 2px 5px;
}

/* ── Waveform ── */

#waveform-container {
  position: relative;
  width: 100%;
  height: 140px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
}

#waveform-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#playback-cursor {
  position: absolute;
  top: 0;
  left: 0;
  width: 2px;
  height: 100%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
  pointer-events: none;
  transform: translateX(0);
  transition: none;
}

/* ── Audio Controls ── */

#audio-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 12px;
}

.btn-play {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: transparent;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}

.btn-play:hover {
  background: var(--accent-glow);
}

.btn-play:active {
  transform: scale(0.93);
}

#time-display {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-dim);
  display: flex;
  align-items: baseline;
  gap: 3px;
}

#time-current {
  color: var(--text);
  font-weight: 500;
  min-width: 3.5ch;
  text-align: right;
}

.time-sep { color: var(--text-muted); }

.time-unit { font-size: 0.72rem; color: var(--text-muted); margin-left: 1px; }

/* ── Transcript ── */

#transcript-container {
  margin-top: 20px;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.transcript-line {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 2px;
}

.transcript-word {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 1.15rem;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
  color: var(--text-dim);
  position: relative;
}

.transcript-word.active {
  background: var(--accent);
  color: var(--bg);
}

.transcript-word.past {
  color: var(--text);
}

.phoneme-line {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  gap: 2px 1px;
}

.phoneme-seg {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 2px 5px;
  border-radius: 3px;
  color: var(--text-muted);
  transition: background 0.12s, color 0.12s;
}

.phoneme-seg.active {
  background: var(--green);
  color: var(--bg);
  font-weight: 500;
}

.phoneme-seg.past {
  color: var(--text-dim);
}

/* ── Tab Bar ── */

#tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--tab-h);
  display: flex;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  z-index: 100;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.tab-btn:hover {
  color: var(--text-dim);
}

.tab-btn.active {
  color: var(--accent);
}

.tab-btn.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 20%;
  right: 20%;
  height: 2px;
  background: var(--accent);
  border-radius: 0 0 2px 2px;
}

.tab-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.tab-label {
  font-size: 0.62rem;
  font-family: var(--font-mono);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── Responsive ── */

@media (min-width: 600px) {
  #content {
    max-width: 580px;
    padding: 20px 24px calc(var(--tab-h) + 24px);
  }

  #tab-audio .tab-audio-body #waveform-container {
    height: 160px;
  }
}

/* ── TextGrid Viewer ── */

#textgrid-container {
  position: relative;
  width: 100%;
  height: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;            /* scroll when canvas is wider than container (zoomed) */
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;   /* momentum scrolling on iOS */
  cursor: pointer;
}

#textgrid-canvas {
  /* width/height set by JS based on zoom; container scrolls overflow */
  display: block;
}

/* TextGrid zoom controls — floating bottom-right of container */
.tg-zoom-controls {
  position: absolute;
  bottom: 8px;
  right: 12px;
  display: flex;
  gap: 6px;
  z-index: 5;
}

.tg-zoom-btn {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(22, 27, 34, 0.88);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background 0.12s;
}

.tg-zoom-btn:hover {
  background: rgba(56, 64, 80, 0.9);
}

.tg-zoom-level {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-dim);
  width: 34px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(22, 27, 34, 0.88);
  border: 1px solid var(--border);
  border-radius: 6px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

/* Swipe hint for mobile — only shown when scrollable */
.tg-swipe-hint {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 0.58rem;
  color: var(--text-muted);
  background: rgba(22, 27, 34, 0.8);
  padding: 3px 10px;
  border-radius: 10px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 5;
}

.tg-swipe-hint.visible {
  opacity: 1;
}

@media (max-width: 480px) {
  #textgrid-container {
    height: 320px;
  }

  .tg-zoom-btn {
    width: 34px;
    height: 34px;
    font-size: 1.2rem;
  }
}

#interval-detail {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  display: none;
}

#interval-detail.visible {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
}

.detail-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.detail-label {
  font-size: 0.62rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.detail-value {
  color: var(--text);
  font-weight: 500;
}

.detail-value.tier-name {
  color: var(--accent);
}

.detail-value.range {
  color: var(--green);
}

.tab-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.tab-panel-title {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── EMA Explorer ── */

#ema-sagittal-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

#ema-sagittal-wrapper {
  width: 100%;
  aspect-ratio: 500 / 350;
  max-height: 280px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ema-svg {
  width: 100%;
  height: 100%;
  display: block;
}

#ema-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.ema-legend-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(22, 27, 34, 0.7);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.ema-legend-btn:hover {
  background: rgba(56, 64, 80, 0.7);
}

.ema-legend-btn.active {
  color: var(--text);
  border-color: currentColor;
}

.ema-legend-btn.active .ema-legend-dot {
  transform: scale(1.3);
  box-shadow: 0 0 6px currentColor;
}

.ema-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: transform 0.15s;
}

.ema-legend-name {
  white-space: nowrap;
}

.ema-legend-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  align-self: center;
  margin: 0 4px;
}

/* EMA trajectory canvas */

#ema-trajectory-container {
  width: 100%;
  height: 180px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

#ema-trajectory-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* EMA info note */

.ema-info-note {
  margin-top: 10px;
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.ema-info-icon {
  color: var(--accent);
  font-size: 0.82rem;
  flex-shrink: 0;
}

/* ── EPG Viewer ── */

#tab-epg {
  padding: 16px;
  flex-direction: column;
  gap: 12px;
  height: 100%;
}

#tab-epg.active {
  display: flex;
}

#epg-grid-container {
  flex: 1;
  min-height: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

#epg-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.epg-info-note {
  margin-top: 10px;
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.epg-info-icon {
  color: var(--accent);
  font-size: 0.82rem;
  flex-shrink: 0;
}

/* ── LAR Viewer ── */

#tab-lar {
  padding: 16px;
  flex-direction: column;
  gap: 12px;
  height: 100%;
}

#tab-lar.active {
  display: flex;
}

#lar-container {
  flex: 1;
  min-height: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

#lar-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.lar-info-note {
  margin-top: 10px;
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.lar-info-icon {
  color: #58a6ff;
  font-size: 0.82rem;
  flex-shrink: 0;
}

@media (min-width: 600px) {
  #ema-sagittal-container {
    flex-direction: row;
    align-items: flex-start;
  }

  #ema-sagittal-wrapper {
    flex: 1;
    max-height: 260px;
  }

  #ema-legend {
    flex-direction: column;
    width: 160px;
    align-items: stretch;
    justify-content: flex-start;
    padding-top: 20px;
  }

  #ema-trajectory-container {
    height: 200px;
  }
}

@media (max-width: 480px) {
  #ema-sagittal-wrapper {
    max-height: 200px;
  }

  #ema-trajectory-container {
    height: 160px;
  }
}

/* ── Dataset Intro (Audio tab only) ── */

.dataset-intro {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(88,166,255,0.04) 0%, transparent 100%);
}

.intro-title {
  font-family: var(--font-display);
  font-size: 0.90rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 5px;
}

.intro-body {
  font-size: 0.76rem;
  line-height: 1.48;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.intro-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  align-items: center;
}

.link-placeholder {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  cursor: default;
  padding: 1px 0;
}

.link-sep {
  font-size: 0.60rem;
  color: var(--text-muted);
  margin: 0 7px;
}

/* ── Site Footer (copyright, document-flow bottom) ── */

#site-footer {
  text-align: center;
  padding: 40px 16px 24px;
  font-size: 0.68rem;
  color: var(--text-muted);
  line-height: 1.5;
  flex-shrink: 0;
}
