:root {
  --bg: #FAFAF7;
  --surface: #FFFFFF;
  --border: #E5E7EB;
  --border-strong: #D1D5DB;
  --text: #1F2937;
  --text-muted: #6B7280;
  --text-soft: #4B5563;
  --accent: #1E3A8A;
  --accent-hover: #1E40AF;
  --accent-soft: #E0E7FF;
  --accent-ring: rgba(30, 58, 138, 0.18);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --radius: 6px;
  --radius-sm: 4px;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-size: 15px;
  line-height: 1.55;
}

/* ---------- Typography ---------- */
h1, h2, h3, h4, h5, h6,
.titlePanel,
.shiny-text-output h1,
.shiny-text-output h2 {
  font-family: var(--font-sans);
  color: var(--text);
  letter-spacing: -0.01em;
  font-weight: 600;
}

h1, .titlePanel h2, .titlePanel h1 {
  font-size: 1.65rem;
  line-height: 1.2;
  margin: 0 0 0.4em;
}

.titlePanel {
  border-bottom: 1px solid var(--border);
  padding-top: 0.4rem;
  padding-bottom: 0.5rem;
  margin-bottom: 0.9rem;
}

h2 { font-size: 1.55rem; line-height: 1.25; margin: 1.4em 0 0.6em; }
h3 { font-size: 1.25rem; line-height: 1.3;  margin: 1.4em 0 0.4em; }
h4 { font-size: 1.05rem; line-height: 1.35; margin: 1.2em 0 0.35em; color: var(--text-soft); letter-spacing: 0; font-weight: 600; }

p { margin: 0 0 0.85em; }

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(30, 58, 138, 0.25);
  transition: border-color 120ms ease, color 120ms ease;
}
a:hover { color: var(--accent-hover); border-bottom-color: var(--accent); }

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2rem 0 1.2rem;
}

/* Home page lede */
.lede {
  font-size: 1.05rem;
  line-height: 1.6;
  color: var(--text-soft);
  margin: 0.4em 0 1.6em;
}
.lede p { margin: 0; }

/* Home page figure row */
.figure-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin: 1em 0 1.6em;
}
.figure-row img {
  max-height: 175px;
  width: auto;
  height: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 4px;
}

/* Footer */
.site-footer {
  margin-top: 2rem;
  padding: 1.2rem 0 2rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.875rem;
  line-height: 1.55;
  text-align: center;
}
.site-footer p { margin: 0 0 0.5em; }
.site-footer em { color: var(--text-soft); }

/* ---------- Page container ---------- */
.container-fluid {
  max-width: 1280px;
  margin-left: auto;
  margin-right: auto;
  padding-top: 0.25rem;
  padding-bottom: 2rem;
}

/* The navbar's own container shouldn't get the page padding */
.navbar .container-fluid { padding-top: 0; padding-bottom: 0; max-width: none; }

/* Tab content wrapper sits right under the navbar — keep it tight */
.tab-content { padding-top: 0; }

/* ---------- Navbar ---------- */
.navbar {
  background: var(--surface) !important;
  border: 0;
  border-bottom: 1px solid var(--border);
  box-shadow: none;
  margin-bottom: 0;
  min-height: 56px;
}
.navbar .container-fluid { padding-top: 0; padding-bottom: 0; }
.navbar-default { background: var(--surface); border-color: var(--border); }

.navbar-brand,
.navbar-default .navbar-brand {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text) !important;
  letter-spacing: -0.005em;
  padding: 18px 18px;
}

.navbar-nav > li > a,
.navbar-default .navbar-nav > li > a {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-soft) !important;
  padding: 18px 14px;
  border-bottom: 2px solid transparent;
  transition: color 120ms ease, border-color 120ms ease;
  background: transparent !important;
}
.navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:hover {
  color: var(--accent) !important;
  background: transparent !important;
}
.navbar-nav > li.active > a,
.navbar-default .navbar-nav > li.active > a,
.navbar-default .navbar-nav > .active > a:focus,
.navbar-default .navbar-nav > .active > a:hover {
  color: var(--accent) !important;
  background: transparent !important;
  border-bottom-color: var(--accent);
}

/* ---------- wellPanel (controls + audio-results) ---------- */
.well {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: none;
  padding: 16px 20px;
  margin-bottom: 1.4rem;
}

.controls { padding: 10px 16px; }
.controls .form-group { margin-bottom: 0.4rem; }
.controls .control-label,
.controls label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-soft);
  letter-spacing: 0.01em;
  margin-bottom: 0.2rem;
}

/* Audio page: extra-compact single-row control bar */
.audio-controls { padding: 8px 14px; margin-bottom: 0.6rem; }
.audio-controls .form-group { margin-bottom: 0; }
.audio-controls .radio-inline { margin-top: 4px; }
.audio-controls .checkbox { margin: 0; }

/* Vertically center the "Show neighbor" checkbox within its column so it
   sits at the visual midpoint of the control bar (not pinned to the top). */
.audio-controls .checkbox-center {
  display: flex;
  align-items: center;
  height: 100%;
  min-height: 60px;
}

/* ---------- Form controls ---------- */
.form-control,
.selectize-input,
.selectize-control.single .selectize-input,
.selectize-control.multi .selectize-input {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.92rem;
  min-height: 34px;
  box-shadow: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.form-control:focus,
.selectize-input.focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
  outline: none;
}

.selectize-dropdown {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
  font-size: 0.92rem;
}
.selectize-dropdown .active {
  background: var(--accent-soft);
  color: var(--text);
}

.selectize-control.multi .selectize-input > div {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(30, 58, 138, 0.18);
  border-radius: 3px;
  font-size: 0.85rem;
  padding: 1px 6px;
}

/* Radios / checkboxes */
.radio, .checkbox { margin-top: 0.3rem; margin-bottom: 0.3rem; }
.radio-inline, .checkbox-inline { padding-left: 0; margin-right: 1rem; }
.radio label, .checkbox label, .radio-inline, .checkbox-inline {
  font-size: 0.92rem;
  color: var(--text);
}
input[type="radio"], input[type="checkbox"] {
  accent-color: var(--accent);
}

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  box-shadow: none;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
.btn:hover, .btn:focus {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}
.btn:focus-visible { box-shadow: 0 0 0 3px var(--accent-ring); }

.btn-default { background: var(--surface); color: var(--text); }

.btn-primary,
.btn.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover, .btn-primary:focus {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

/* Button rows */
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-row .btn { min-width: 36px; }

/* ---------- Confusion matrix hover readout ---------- */
.hover-readout {
  margin-top: 0.6rem;
}
.hover-readout pre,
.hover-readout .shiny-text-output {
  background: #F5F5F2;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  padding: 6px 10px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Audio results ---------- */
.audio-results {
  height: 82vh;
  overflow-y: auto;
  padding: 16px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 0.6rem;
}
.audio-results h2 {
  font-size: 1.2rem;
  margin: 0 0 1rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}
.audio-results .row,
.audio-results > .shiny-html-output > .row {
  padding: 10px 0;
  border-bottom: 1px solid #F1F1EE;
}
.audio-results .row:last-child { border-bottom: 0; }
.audio-results p {
  margin: 0 0 0.4em;
  font-size: 1rem;
  color: var(--text);
}

/* Howler audio player tidy-up */
.audio-results .howler-module { margin: 4px 0; }

/* Hide volume controls in the howler basic module — not useful for short clips */
.howler-volumetoggle-button,
.howler-volumeup-button,
.howler-volumedown-button,
.howler-volume-slider {
  display: none !important;
}

/* Slim scrollbar on the results pane */
.audio-results::-webkit-scrollbar { width: 10px; }
.audio-results::-webkit-scrollbar-track { background: transparent; }
.audio-results::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 10px;
  border: 2px solid var(--surface);
}
.audio-results::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Pager row */
.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 1rem;
}
.pager .page-info {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-left: 0.4rem;
}

/* Download button row sitting above a plot */
.plot-download-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 6px;
}
.plot-download-row .btn { font-size: 0.82rem; padding: 4px 10px; }

/* Plot container — keep plots contained inside their bootstrap column */
.shiny-plot-output {
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 100%;
  overflow: hidden;
}
.shiny-plot-output img {
  max-width: 100% !important;
  height: auto;
  display: block;
}

/* Loading spinner. Shiny adds .recalculating to outputs while they're being
   recomputed (including first render). Override Shiny's default opacity:0.3
   fade — otherwise the spinner inherits that opacity and is barely visible.
   We replace the fade with a soft white overlay + a centered spinner. */
.shiny-plot-output.recalculating,
.shiny-html-output.recalculating {
  position: relative;
  min-height: 80px;
  opacity: 1 !important;
}
.shiny-plot-output.recalculating::before,
.shiny-html-output.recalculating::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(250, 250, 247, 0.75);
  z-index: 4;
  pointer-events: none;
}
.shiny-plot-output.recalculating::after,
.shiny-html-output.recalculating::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border: 4px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  pointer-events: none;
  z-index: 5;
  animation: idsviz-spin 0.75s linear infinite;
}
@keyframes idsviz-spin { to { transform: rotate(360deg); } }

/* Shiny's conditionalPanel wraps its children in a plain <div>; inside a
   Bootstrap 5 flex .row that wrapper would otherwise take auto width and
   push siblings to wrap. Treat it as a transparent passthrough so the
   col-sm-* inside picks up the row's column layout. */
.row > div:not([class*="col-"]) {
  display: contents;
}

/* validate() output (e.g., "Please Enter a Phoneme.") */
.shiny-output-error-validation {
  color: var(--text-muted);
  font-style: italic;
  padding: 1.2rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .controls .col-sm-2,
  .controls [class*="col-"] {
    margin-bottom: 0.8rem;
  }
  .figure-row { flex-direction: column; }
  .navbar-nav > li > a { padding: 12px 10px; }
}
