@import url("https://cdn-font.hyperos.mi.com/font/css?family=MiSans_Latin_VF:VF:Latin&display=swap");

:root {
  color-scheme: light;
  --ink: #17211f;
  --muted: #64706c;
  --line: #dfe7e2;
  --soft-line: #ecf1ee;
  --paper: #fbfcfa;
  --surface: #ffffff;
  --mist: #f4f8f6;
  --sage: #667b5f;
  --sage-dark: #344c3d;
  --ochre: #b2823a;
  --rose: #b65050;
  --blue: #466c95;
  --violet: #66578a;
  --shadow: 0 18px 50px rgba(35, 55, 49, 0.11);
  --radius: 8px;
  font-family:
    "MiSans Latin VF", MiSans, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

.app-shell > *,
.brand > *,
.search-box > *,
.workspace-header > *,
.study-layout > *,
.meaning-flow > *,
.snapshot-grid > *,
.section-title > *,
.context-grid > *,
.interpretation-grid > *,
.graph-layout > *,
.language-grid > *,
.advanced-grid > *,
.timeline-panel > *,
.character-panel > *,
.character-row > * {
  min-width: 0;
}

h1,
h2,
h3,
p,
li,
label,
strong,
span,
a,
button,
textarea,
input {
  overflow-wrap: anywhere;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(102, 123, 95, 0.08) 1px, transparent 1px),
    linear-gradient(180deg, rgba(102, 123, 95, 0.06) 1px, transparent 1px), var(--paper);
  background-size: 36px 36px;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
  line-height: 1.2;
  white-space: normal;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(260px, 310px) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 22px;
  background: rgba(255, 255, 255, 0.92);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  margin-bottom: 28px;
}

.brand {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 12px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  height: 46px;
  border-radius: 8px;
  color: white;
  background: linear-gradient(135deg, var(--sage-dark), var(--ochre));
  font-weight: 800;
  font-size: 0.84rem;
}

.brand strong,
.brand small {
  display: block;
  max-width: 100%;
}

.brand small {
  color: var(--muted);
  margin-top: 2px;
}

.search-panel,
.mode-panel {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 16px;
}

.search-panel label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
  margin-bottom: 10px;
}

.search-box {
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 8px;
}

.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--paper);
  outline: none;
}

.search-box input {
  min-width: 0;
  height: 42px;
  padding: 0 12px;
}

.search-box input:focus {
  border-color: var(--sage);
  box-shadow: 0 0 0 3px rgba(102, 123, 95, 0.16);
}

.database-notice {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.database-notice.error {
  border-color: rgba(182, 80, 80, 0.38);
  background: #fff1ef;
  color: #71413c;
}

.database-notice.success {
  border-color: rgba(52, 108, 76, 0.36);
  background: #eef8f2;
  color: #2f5a42;
}

.database-notice strong {
  color: var(--rose);
}

.database-notice.success strong {
  color: #2f6d48;
}

.database-notice p {
  margin: 0;
  line-height: 1.45;
}

.database-notice-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 2px;
}

.database-request-button {
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius);
  color: white;
  background: var(--rose);
  font-weight: 800;
}

.database-request-button:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.database-request-button.sent {
  background: #8b9490;
  box-shadow: none;
  opacity: 1;
}

.icon-button,
.primary-button,
.secondary-button,
.text-button,
.mode-button {
  border: 0;
  border-radius: var(--radius);
}

.icon-button {
  color: white;
  background: var(--sage-dark);
  font-weight: 800;
}

.mode-panel p,
.panel-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 0.79rem;
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 750;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  margin-top: 10px;
  background: var(--mist);
  border-radius: var(--radius);
}

.language-toggle {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  padding: 4px;
  margin-top: 10px;
  background: var(--mist);
  border-radius: var(--radius);
}

.language-toggle.compact {
  width: 82px;
  margin-top: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(35, 55, 49, 0.08);
}

.mode-button,
.language-button {
  min-height: 36px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: var(--radius);
}

.language-toggle.compact .language-button {
  min-height: 30px;
  padding: 0;
  font-size: 0.76rem;
  font-weight: 800;
}

.mode-button.active,
.language-button.active {
  color: white;
  background: var(--sage-dark);
  box-shadow: 0 8px 18px rgba(52, 76, 61, 0.22);
}

.side-nav {
  display: grid;
  gap: 4px;
  margin: 22px 0;
}

.side-nav a {
  padding: 10px 12px;
  color: var(--muted);
  text-decoration: none;
  border-radius: var(--radius);
}

.side-nav a:hover {
  color: var(--ink);
  background: var(--mist);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.text-button {
  color: var(--sage-dark);
  background: transparent;
  padding: 4px 6px;
  font-size: 0.82rem;
}

.main {
  min-width: 0;
  padding: 28px;
}

.workspace-header {
  min-height: 290px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 28px;
  align-items: end;
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.96), rgba(244, 248, 246, 0.9)),
    radial-gradient(circle at 92% 10%, rgba(178, 130, 58, 0.18), transparent 32%),
    linear-gradient(135deg, rgba(52, 76, 61, 0.08), rgba(70, 108, 149, 0.08));
  box-shadow: var(--shadow);
}

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

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

h1 {
  margin-bottom: 12px;
  font-size: clamp(2rem, 5vw, 4.8rem);
  line-height: 0.95;
  max-width: 760px;
}

.workspace-header p:not(.eyebrow) {
  max-width: 660px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.65;
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-button,
.secondary-button {
  max-width: 100%;
  min-height: 42px;
  padding: 0 16px;
  font-weight: 760;
}

.primary-button {
  color: white;
  background: var(--sage-dark);
}

.secondary-button {
  color: var(--sage-dark);
  background: white;
  border: 1px solid var(--line);
}

.study-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(290px, 0.7fr);
  gap: 18px;
}

.passage-panel,
.insight-panel,
.context-grid article,
.interpretation-card,
.language-card,
.timeline-panel,
.character-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
}

.passage-panel,
.insight-panel {
  padding: 24px;
}

.passage-panel h2 {
  margin: 20px 0 10px;
  font-size: clamp(1.8rem, 4vw, 3.2rem);
}

.verse-text {
  color: #24302d;
  font-size: clamp(1.25rem, 2.5vw, 1.8rem);
  line-height: 1.55;
  border-left: 4px solid var(--ochre);
  padding-left: 18px;
}

.confidence-badge,
.warning-pill,
.connection-type,
.language-meta {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 760;
}

.confidence-badge {
  color: var(--sage-dark);
  background: #e8f1e9;
}

.warning-card {
  display: grid;
  gap: 6px;
  margin: 20px 0;
  padding: 14px;
  border: 1px solid rgba(182, 80, 80, 0.28);
  border-radius: var(--radius);
  background: #fff7f5;
}

.warning-card strong {
  color: var(--rose);
}

.warning-card p {
  margin: 0;
  color: #714b46;
  line-height: 1.5;
}

.meaning-flow {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 20px;
}

.meaning-flow div,
.snapshot-grid div {
  padding: 14px;
  border: 1px solid var(--soft-line);
  border-radius: var(--radius);
  background: var(--mist);
}

.meaning-flow span,
.snapshot-grid span,
.context-grid span,
.interpretation-card span,
.language-card span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 800;
  margin-bottom: 6px;
}

.meaning-flow strong,
.snapshot-grid strong {
  display: block;
  line-height: 1.45;
}

.snapshot-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.section-grid {
  margin-top: 42px;
}

.section-title {
  display: grid;
  grid-template-columns: minmax(0, 420px) minmax(0, 1fr);
  gap: 24px;
  align-items: end;
  margin-bottom: 16px;
}

.section-title h2 {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 2.2rem);
}

.context-grid,
.interpretation-grid,
.language-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.context-grid article,
.interpretation-card,
.language-card {
  padding: 18px;
}

.context-grid p,
.interpretation-card p,
.language-card p,
.connection-card p {
  color: var(--muted);
  line-height: 1.58;
}

.interpretation-card {
  display: grid;
  gap: 12px;
}

.interpretation-card h3,
.language-card h3 {
  margin: 0;
}

.interpretation-card ul,
.language-card ul {
  padding-left: 18px;
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.graph-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.graph-wrap {
  height: clamp(300px, 42vw, 390px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(102, 123, 95, 0.08) 1px, transparent 1px),
    linear-gradient(180deg, rgba(102, 123, 95, 0.08) 1px, transparent 1px), #ffffff;
  background-size: 30px 30px;
  overflow: hidden;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.connection-list {
  display: grid;
  gap: 10px;
}

.connection-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.connection-card strong {
  display: block;
  margin-bottom: 8px;
}

.connection-type {
  color: var(--blue);
  background: #edf4fb;
  margin-bottom: 8px;
}

.language-card {
  min-height: 235px;
}

.language-original {
  font-size: 2rem;
  margin-bottom: 8px;
}

.language-meta {
  color: var(--violet);
  background: #f0eef8;
  margin-bottom: 12px;
}

.advanced-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 42px;
}

.timeline-panel,
.character-panel {
  padding: 20px;
}

.timeline-track {
  position: relative;
  display: grid;
  gap: 0;
  margin-top: 12px;
  padding: 0;
}

.timeline-track::before {
  content: "";
  position: absolute;
  top: 12px;
  bottom: 12px;
  left: 13px;
  width: 2px;
  border-radius: 999px;
  background: #1b6684;
}

.era:first-child::before,
.era:last-child::after {
  content: "";
  position: absolute;
  z-index: 1;
  left: 8px;
  width: 12px;
  height: calc(50% - 11px);
  background: rgba(255, 255, 255, 0.96);
}

.era:first-child::before {
  top: 0;
}

.era:last-child::after {
  bottom: 0;
}

.era {
  position: relative;
  min-height: 52px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  color: var(--ink);
}

.era-marker {
  z-index: 1;
  width: 22px;
  height: 22px;
  justify-self: center;
  border: 2px solid #123042;
  border-radius: 999px;
  background: #1f6f8d;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.96);
}

.era strong {
  color: inherit;
  font-size: 1rem;
  font-weight: 650;
  line-height: 1.08;
}

.era.active .era-marker {
  background: var(--ochre);
  border-color: var(--sage-dark);
}

.era.active strong {
  color: var(--sage-dark);
  font-weight: 800;
}

#characterExplorer {
  margin-top: 16px;
  display: grid;
  gap: 10px;
}

.character-row {
  display: grid;
  grid-template-columns: minmax(80px, 110px) minmax(0, 1fr);
  gap: 10px;
  border-bottom: 1px solid var(--soft-line);
  padding-bottom: 10px;
}

.character-row span {
  color: var(--muted);
  font-size: 0.82rem;
}

.empty-state {
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: white;
}

.hidden {
  display: none !important;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand-row {
    align-items: center;
  }

  .side-nav {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .workspace-header,
  .study-layout,
  .graph-layout,
  .advanced-grid {
    grid-template-columns: 1fr;
  }

  .context-grid,
  .interpretation-grid,
  .language-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .main,
  .sidebar {
    padding: 16px;
  }

  .brand-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
  }

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

  .brand-mark {
    height: 42px;
  }

  .workspace-header,
  .passage-panel,
  .insight-panel {
    padding: 18px;
  }

  .header-actions,
  .meaning-flow,
  .section-title,
  .context-grid,
  .interpretation-grid,
  .language-grid {
    grid-template-columns: 1fr;
  }

  .header-actions {
    justify-content: stretch;
  }

  .header-actions button {
    width: 100%;
  }

  .verse-text {
    padding-left: 12px;
  }

  .character-row {
    grid-template-columns: 1fr;
  }
}
