:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #243033;
  --muted: #667174;
  --line: #d8e0df;
  --teal: #0f766e;
  --teal-soft: #d9f0ec;
  --wine: #7f1d1d;
  --amber: #a16207;
  --shadow: 0 12px 36px rgba(30, 41, 43, 0.10);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.08), transparent 280px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: var(--teal);
  color: #ffffff;
  padding: 0 14px;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: #0b5f59;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 0 12px;
}

input:focus {
  border-color: var(--teal);
  outline: 3px solid rgba(15, 118, 110, 0.15);
}

.player-shell {
  width: min(1760px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.player-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.portrait-frame {
  width: 68px;
  aspect-ratio: 1;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid rgba(36, 48, 51, 0.18);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.portrait-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.55rem, 2.2vw, 2.35rem);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 10px;
  font-size: 1.04rem;
  letter-spacing: 0;
}

.muted {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.status-strip {
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.stat,
.mode-badge {
  min-width: 112px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  padding: 9px 12px;
  box-shadow: 0 8px 24px rgba(30, 41, 43, 0.06);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  margin-top: 2px;
  font-size: 1.28rem;
}

.mode-badge {
  display: grid;
  place-items: center;
  min-width: 120px;
  color: var(--wine);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.player-workspace {
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(460px, 1fr) minmax(280px, 380px);
  gap: 14px;
  align-items: start;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.panel-head,
.reader-head {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.reader-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 300px);
  gap: 12px;
  align-items: end;
}

.sessions-list,
.search-results {
  max-height: calc(100vh - 184px);
  overflow: auto;
  padding: 8px;
}

.session-button,
.search-result {
  display: block;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  padding: 10px;
  text-align: left;
  cursor: pointer;
}

.session-button:hover,
.search-result:hover {
  border-color: var(--line);
  background: #f8fbfb;
}

.session-button.is-active {
  border-color: rgba(15, 118, 110, 0.35);
  background: var(--teal-soft);
}

.session-title,
.result-title {
  display: block;
  margin-bottom: 5px;
  font-weight: 800;
  line-height: 1.25;
}

.session-meta,
.result-meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.reader-panel {
  min-height: calc(100vh - 124px);
}

.document-viewer {
  height: calc(100vh - 246px);
  min-height: 520px;
  overflow: auto;
  padding: 24px;
}

.document-text {
  max-width: 900px;
  margin: 0 auto;
  line-height: 1.68;
  font-size: 1rem;
}

.document-text h1,
.document-text h2,
.document-text h3 {
  margin: 1.5em 0 0.45em;
  line-height: 1.2;
}

.document-text h1:first-child,
.document-text h2:first-child,
.document-text h3:first-child {
  margin-top: 0;
}

.document-text p {
  margin-bottom: 1em;
}

.document-text ul,
.document-text ol {
  padding-left: 1.35rem;
}

.document-text blockquote {
  margin: 1rem 0;
  border-left: 4px solid var(--amber);
  padding: 0.3rem 0 0.3rem 1rem;
  color: #414a4d;
  background: #fff8e8;
}

mark {
  border-radius: 3px;
  background: #fde68a;
  color: #2d2413;
  padding: 0 2px;
}

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

.search-controls {
  display: grid;
  grid-template-columns: minmax(120px, 1.2fr) repeat(2, minmax(108px, 1fr)) minmax(110px, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.search-controls label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.search-controls select,
.search-controls input {
  min-height: 38px;
  padding: 0 9px;
  font-size: 0.9rem;
  font-weight: 500;
}

.search-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.search-title-row h2 {
  margin-bottom: 0;
}

.quiet-button {
  min-height: 34px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--teal);
  padding: 0 10px;
  font-size: 0.9rem;
}

.quiet-button:hover {
  background: var(--teal-soft);
}

.search-result {
  border-color: var(--line);
  margin-bottom: 8px;
  background: #ffffff;
  color: var(--ink);
}

.result-snippet {
  margin: 8px 0 0;
  color: #3d494c;
  font-size: 0.92rem;
  line-height: 1.45;
}

.empty-state {
  color: var(--muted);
}

.load-error {
  color: var(--wine);
  font-weight: 700;
}

@media (max-width: 1180px) {
  .player-workspace {
    grid-template-columns: minmax(230px, 300px) minmax(0, 1fr);
  }

  .search-panel {
    grid-column: 1 / -1;
  }

  .search-results {
    max-height: none;
  }
}

@media (max-width: 760px) {
  .player-shell {
    padding: 10px;
  }

  .player-topbar,
  .brand,
  .reader-head {
    align-items: stretch;
    display: grid;
    grid-template-columns: 1fr;
  }

  .brand {
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .portrait-frame {
    width: 58px;
  }

  .status-strip {
    justify-content: stretch;
  }

  .stat,
  .mode-badge {
    flex: 1 1 0;
    min-width: 0;
  }

  .player-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .search-panel {
    order: 1;
    position: sticky;
    top: 0;
    z-index: 20;
    max-height: calc(100dvh - 12px);
    overflow: hidden;
  }

  .sessions-panel {
    order: 2;
  }

  .reader-panel {
    order: 3;
  }

  .search-form {
    grid-template-columns: 1fr;
  }

  .search-controls {
    grid-template-columns: 1fr 1fr;
  }

  .search-panel.is-expanded {
    display: flex;
    flex-direction: column;
  }

  .search-panel.is-expanded .panel-head {
    flex: 0 0 auto;
  }

  .search-panel.is-expanded .search-results {
    flex: 1 1 auto;
    max-height: none;
    min-height: 180px;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .search-panel:not(.is-expanded) .search-results {
    display: none;
  }

  .search-form input,
  .search-controls input,
  .search-controls select,
  #session-filter,
  #document-search {
    min-height: 48px;
    font-size: 1rem;
  }

  .sessions-list,
  .document-viewer {
    max-height: none;
    height: auto;
    min-height: 320px;
  }

  .document-viewer {
    padding: 16px;
  }
}
