:root {
  color-scheme: dark;
  --bg: #070a08;
  --header: #0b100c;
  --panel: #0f1511;
  --panel-raised: #151d17;
  --panel-hover: #19231c;
  --border: #2d3e32;
  --border-soft: #202d25;
  --text: #e7eee9;
  --muted: #91a097;
  --accent: #72ee88;
  --accent-bright: #9bffaa;
  --accent-dark: #14371d;
  --accent-ink: #061208;
  --focus-glow: rgb(114 238 136 / 30%);
  --warn: #efbd66;
  --shadow: #0009;
  --radius: 7px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { background: var(--bg); }

body {
  margin: 0;
  padding-bottom: 94px;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% -260px, rgb(114 238 136 / 7%), transparent 640px),
    var(--bg);
  color: var(--text);
  font: 14px/1.42 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body[data-mode="hosted"] .desktop-only { display: none !important; }

button,
input,
select {
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--panel-raised);
  color: var(--text);
  font: inherit;
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

input::placeholder { color: #748179; }

button {
  cursor: pointer;
  font-weight: 680;
}

button:hover,
input:hover,
select:hover { border-color: #4f6f59; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--focus-glow);
}

button:disabled { cursor: wait; opacity: .52; }

button.primary,
.primary-action {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

button.primary:hover,
.primary-action:hover {
  border-color: var(--accent-bright);
  background: var(--accent-bright);
}

.secondary-action,
.secondary-button { background: transparent; }

h1,
h2,
p { margin: 0; }

h1 {
  color: var(--accent-bright);
  font-size: 23px;
  letter-spacing: .02em;
}

h2 { font-size: 15px; letter-spacing: .01em; }

header {
  position: sticky;
  z-index: 8;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 17px 28px;
  border-bottom: 1px solid var(--border);
  background: rgb(11 16 12 / 96%);
  box-shadow: 0 8px 28px #0005;
  backdrop-filter: blur(12px);
}

header p,
.panel p { color: var(--muted); }

header > div,
.semantic-heading > div,
.browser-title { min-width: 0; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.session-identity {
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: min(100%, 2200px);
  margin: 0 auto;
  padding: 18px 28px;
  gap: 14px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(6, minmax(110px, 1fr));
  gap: 9px;
}

.summary article,
.panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 8px 24px #0003;
}

.summary article {
  display: grid;
  padding: 12px 14px;
  gap: 2px;
}

.summary strong {
  color: var(--accent);
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.summary span {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .045em;
  text-transform: uppercase;
}

.compact-summary {
  display: none;
  min-width: 0;
  padding: 8px 11px;
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

body[data-mode="hosted"][data-role="user"] .summary { display: none; }
body[data-mode="hosted"][data-role="user"] .compact-summary { display: block; }

.panel { padding: 14px; }
.muted { color: var(--muted); }

.setup-panel {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  align-items: center;
  gap: 12px 24px;
}

.setup-controls { display: flex; gap: 8px; }
.setup-controls input { flex: 1; min-width: 260px; }
.manual-label { display: grid; gap: 2px; }
.manual-controls input { min-width: 120px; }
.manual-controls #manual-path { min-width: 250px; }
.setup-panel #root-status { grid-column: 1 / -1; }

.scan-heading,
.browser-heading,
.admin-heading,
.publication-row,
.semantic-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

#scan-state { color: var(--accent); text-transform: capitalize; }

progress {
  width: 100%;
  height: 9px;
  margin: 12px 0 8px;
  accent-color: var(--accent);
}

.scan-stats { color: var(--muted); font-variant-numeric: tabular-nums; }
#scan-errors-panel { margin-top: 10px; color: var(--warn); }
#scan-error-list { max-height: 150px; margin: 8px 0 0; overflow: auto; }

.admin-panel { display: grid; gap: 10px; }
.admin-heading > div:first-child { display: grid; gap: 3px; }
.publication-list { display: grid; gap: 6px; }
.publication-row { padding: 8px; border: 1px solid var(--border-soft); background: var(--panel-raised); }
.publication-row > div { display: flex; gap: 6px; }
.publication-row button { min-height: 30px; padding: 4px 8px; }
#publication-history { max-height: 150px; overflow: auto; }

.semantic-panel { display: grid; gap: 10px; }
.semantic-heading > div:first-child { display: grid; gap: 3px; }

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

#semantic-query {
  min-height: 48px;
  padding: 10px 14px;
  border-color: #42604a;
  background: #111b14;
  box-shadow: inset 0 0 24px rgb(114 238 136 / 3%);
  font-size: 15px;
}

#semantic-query:focus { border-color: var(--accent); }
#semantic-search-button { min-width: 104px; font-size: 14px; }

.semantic-options {
  display: flex;
  align-items: center;
  gap: 10px 18px;
  padding: 8px 10px;
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  background: #0b110d;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.control-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.segmented-control {
  display: flex;
  margin: 0;
  padding: 0;
  border: 0;
}

.segmented-control label { cursor: pointer; }
.segmented-control input { position: absolute; opacity: 0; pointer-events: none; }

.segmented-control span {
  display: block;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  background: var(--panel-raised);
  font-size: 12px;
  font-weight: 700;
}

.segmented-control label:first-child span { border-radius: 4px 0 0 4px; }
.segmented-control label:last-child span { margin-left: -1px; border-radius: 0 4px 4px 0; }
.segmented-control input:checked + span { border-color: var(--accent); background: var(--accent-dark); color: var(--accent); }
.segmented-control input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.duration-presets { display: flex; gap: 4px; }
.duration-preset { min-height: 32px; padding: 5px 8px; font-size: 12px; }
.duration-preset.active { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }

.custom-duration-group label {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.custom-duration-group input { width: 68px; min-height: 32px; padding: 5px 7px; }
.preset-state { color: var(--muted); font-size: 11px; white-space: nowrap; }
.preset-state strong { color: var(--text); }
.duration-note { margin-top: -5px; font-size: 11px; }
#semantic-result-count { min-height: 20px; font-size: 12px; }

.semantic-results-wrap {
  max-height: 390px;
  overflow: auto;
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  scrollbar-color: #42604a var(--panel);
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

tr { border-bottom: 1px solid var(--border-soft); }
tbody tr:last-child { border-bottom: 0; }

th {
  position: sticky;
  z-index: 2;
  top: 0;
  background: var(--panel-raised);
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .055em;
  text-align: left;
  text-transform: uppercase;
}

th,
td {
  padding: 9px 10px;
  border: 0;
  vertical-align: top;
}

tbody tr:hover { background: var(--panel-hover); }

td {
  min-width: 0;
  overflow-wrap: anywhere;
}

td.description {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.semantic-table th:nth-child(1) { width: 168px; }
.semantic-table th:nth-child(2) { width: 136px; }
.semantic-table th:nth-child(3) { width: 235px; }
.semantic-table th:nth-child(5) { width: 88px; }
.semantic-table th:nth-child(6) { width: 235px; }

.asset-table th:nth-child(1) { width: 158px; }
.asset-table th:nth-child(2) { width: 250px; }
.asset-table th:nth-child(4) { width: 86px; }
.asset-table th:nth-child(5) { width: 235px; }
.asset-table th:nth-child(6) { width: 180px; }

.actions-cell { white-space: nowrap; }
.actions-cell button { min-height: 30px; padding: 4px 9px; font-size: 11px; }
.actions-cell .similar-button { margin-left: 5px; }

.title-stack { display: grid; gap: 3px; }
.title-stack strong { line-height: 1.3; }
.title-stack span { color: var(--accent); font-size: 12px; }

.score-stack {
  display: grid;
  gap: 1px;
  font-variant-numeric: tabular-nums;
}

.score-stack strong { color: var(--accent); font-size: 12px; }
.score-stack small { color: var(--muted); font-size: 10px; }
.match-cell,
.duration-cell { color: var(--muted); font-variant-numeric: tabular-nums; }

.library-links {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
}

.library-link {
  min-width: 0;
  min-height: 27px;
  padding: 3px 7px;
  overflow: hidden;
  border-color: #35503d;
  background: var(--accent-dark);
  color: var(--accent);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-link:hover { border-color: var(--accent); }

.browser-panel { padding: 0; overflow: hidden; }
.browser-heading { padding: 13px 14px; border-bottom: 1px solid var(--border); }
.browser-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.browser-breadcrumb { color: var(--muted); }
.breadcrumb-link { min-height: 25px; padding: 2px 6px; border: 0; background: transparent; color: var(--accent); font-size: 12px; }

.browser-filters {
  display: grid;
  grid-template-columns: minmax(140px, .7fr) minmax(210px, 1fr) minmax(280px, 2fr) minmax(110px, .6fr);
  gap: 8px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-soft);
  background: #0b110d;
}

.browser-filters label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.browser-filters input,
.browser-filters select { min-width: 0; width: 100%; }

.browser-empty {
  display: grid;
  min-height: 190px;
  place-content: center;
  gap: 5px;
  padding: 26px;
  color: var(--muted);
  text-align: center;
}

.browser-empty strong { color: var(--text); font-size: 15px; }
.asset-scroll { min-height: 300px; max-height: 62vh; overflow: auto; scrollbar-color: #42604a var(--panel); }

.details-cell details { color: var(--muted); font-size: 11px; }
.details-cell summary { cursor: pointer; color: var(--text); }
.details-cell details div { margin-top: 5px; overflow-wrap: anywhere; }

.browser-sentinel {
  min-height: 46px;
  padding: 14px;
  border-top: 1px solid var(--border-soft);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.player-bar {
  position: fixed;
  z-index: 10;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(420px, 2fr);
  align-items: center;
  min-height: 76px;
  padding: 10px 28px;
  gap: 22px;
  border-top: 1px solid #3d5744;
  background: rgb(10 16 12 / 97%);
  box-shadow: 0 -10px 32px var(--shadow);
  backdrop-filter: blur(14px);
}

.player-bar > div { display: grid; min-width: 0; gap: 1px; }
.player-bar strong,
.player-context { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-bar strong { color: var(--accent-bright); }
.player-context { color: var(--muted); font-size: 11px; }
audio { width: 100%; height: 42px; accent-color: var(--accent); }

code { color: var(--accent-bright); }

.login-page { padding: 0; }
.login-shell { display: grid; min-height: 100vh; padding: 24px; place-items: center; }

.login-card {
  display: grid;
  width: min(390px, 100%);
  padding: 24px;
  gap: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 18px 60px #000b;
}

.login-card > div:first-child { display: grid; gap: 4px; }
.login-card p { color: var(--muted); }
.login-card label { display: grid; gap: 6px; color: var(--muted); font-weight: 650; }
.login-error { min-height: 20px; color: var(--warn); }

@media (max-width: 1180px) {
  .semantic-options { flex-wrap: wrap; }
  .custom-duration-group { flex: 1 1 370px; }
  .semantic-table th:nth-child(3) { width: 205px; }
  .semantic-table th:nth-child(6) { width: 195px; }
  .asset-table th:nth-child(2) { width: 220px; }
  .asset-table th:nth-child(5) { width: 195px; }
}

@media (max-width: 980px) {
  .summary { grid-template-columns: repeat(3, 1fr); }
  .setup-panel { grid-template-columns: 1fr; }
  .setup-panel #root-status { grid-column: auto; }
  .browser-heading { align-items: flex-start; flex-direction: column; }
  .browser-title { width: 100%; flex-wrap: wrap; }
  .browser-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .browser-search-label { grid-column: 1 / -1; grid-row: 2; }
  .semantic-heading { align-items: flex-start; }
  header,
  .admin-heading,
  .publication-row { align-items: flex-start; }
  .header-actions { flex-wrap: wrap; justify-content: flex-end; }
}

@media (max-width: 820px) {
  body { padding-bottom: 116px; font-size: 13px; }

  button,
  input,
  select { min-height: 42px; }

  header {
    position: static;
    align-items: flex-start;
    padding: 13px 12px;
    gap: 10px;
  }

  h1 { font-size: 20px; }
  header p { font-size: 11px; }
  .header-actions { flex-direction: column; align-items: flex-end; gap: 5px; }
  .session-identity { max-width: 145px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  main { padding: 10px; gap: 10px; }
  .summary { display: none; }
  .compact-summary { display: block; }
  .panel { padding: 11px; border-radius: 6px; }

  .setup-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  .setup-controls input,
  .manual-controls input,
  .manual-controls #manual-path { width: 100%; min-width: 0; }

  .scan-stats,
  #semantic-status { overflow-wrap: anywhere; }
  .semantic-heading { flex-wrap: wrap; }

  .semantic-search-controls { grid-template-columns: minmax(0, 1fr) 82px; }
  #semantic-query { min-height: 48px; padding: 8px 10px; font-size: 16px; }
  #semantic-search-button { min-width: 0; }

  .semantic-options { display: grid; padding: 8px; gap: 8px; }
  .control-group { flex-wrap: wrap; }
  .control-label { width: 58px; }
  .mode-group,
  .duration-group { flex-wrap: nowrap; }
  .custom-duration-group { display: grid; grid-template-columns: 58px 1fr 1fr; }
  .custom-duration-group .preset-state { grid-column: 2 / -1; }
  .custom-duration-group input { width: min(72px, 15vw); min-height: 38px; }
  .duration-presets { min-width: 0; }
  .duration-preset { min-height: 38px; padding: 5px 7px; }
  .semantic-results-wrap { max-height: none; overflow-x: hidden; border: 0; }

  table,
  tbody { display: block; width: 100%; }
  thead { display: none; }

  .semantic-table tr,
  .asset-table tr {
    display: grid;
    width: 100%;
    margin-bottom: 8px;
    padding: 11px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--panel-raised);
    gap: 7px 10px;
  }

  .semantic-table tr {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "sound sound"
      "library library"
      "score match"
      "description description"
      "actions actions";
  }

  .asset-table tr {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "sound sound"
      "library duration"
      "description description"
      "details details"
      "actions actions";
  }

  td {
    display: block;
    width: auto;
    max-width: none;
    padding: 0;
    overflow: visible;
  }

  .sound-cell { grid-area: sound; }
  .actions-cell { grid-area: actions; display: flex; gap: 7px; }
  .score-cell { grid-area: score; }
  .description { grid-area: description; }
  .match-cell { grid-area: match; text-align: right; }
  .duration-cell { grid-area: duration; text-align: right; }
  .library-cell { grid-area: library; }
  .details-cell { grid-area: details; }

  .actions-cell button { flex: 1; min-height: 42px; margin: 0 !important; font-size: 12px; }
  .match-cell::before { content: "Match "; color: var(--muted); }
  .duration-cell::before { content: "Duration "; color: var(--muted); }
  .score-stack { display: flex; align-items: baseline; flex-wrap: wrap; gap: 3px 8px; }
  .score-stack small { font-size: 9px; }
  .library-links { flex-wrap: wrap; }
  .library-link { min-height: 34px; max-width: calc(100vw - 70px); }
  td.description { font-size: 11px; }

  .browser-panel { padding: 0; }
  .browser-heading { padding: 11px; }
  .browser-title { display: grid; gap: 3px; }
  .browser-filters { grid-template-columns: 1fr; padding: 10px; }
  .browser-search-label { grid-column: auto; grid-row: auto; }
  .browser-empty { min-height: 145px; padding: 20px; }
  .asset-scroll { min-height: 240px; max-height: none; overflow-x: hidden; padding: 8px; }
  .browser-sentinel { margin: 0 -8px -8px; }

  .player-bar {
    grid-template-columns: 1fr;
    min-height: 106px;
    padding: 8px 11px;
    gap: 5px;
  }

  .player-bar .muted { display: none; }
  .player-context { font-size: 10px; }
  audio { height: 38px; }
}

@media (max-width: 390px) {
  .semantic-search-controls { grid-template-columns: 1fr; }
  #semantic-search-button { width: 100%; }
  .mode-group,
  .duration-group { align-items: flex-start; flex-direction: column; }
  .control-label { width: auto; }
  .duration-presets { width: 100%; }
  .duration-preset { flex: 1; padding-inline: 4px; }
  .custom-duration-group { grid-template-columns: 1fr 1fr; }
  .custom-duration-group > .control-label { grid-column: 1 / -1; }
  .custom-duration-group .preset-state { grid-column: 1 / -1; }
}
