:root {
  --color-bg: #f7f4ee;
  --color-surface: #ffffff;
  --color-border: #d8d0c0;
  --color-text: #2a2620;
  --color-text-muted: #6b6558;
  --color-accent: #7a5c2e;

  --color-achaean: #2b6cb0;
  --color-trojan: #c0392b;
  --color-ally: #d68910;
  --color-neutral: #7f8c8d;

  --font-serif: Georgia, "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-greek: "Gentium Plus", "Palatino Linotype", Palatino, "Times New Roman", serif;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 1rem;
  --space-4: 1.5rem;

  --radius: 6px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  flex: 0 0 auto;
}

.app-header h1 {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  margin: 0;
}

.header-controls {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.source-references {
  flex: 0 0 auto;
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 0.82rem;
}

.source-references summary {
  width: fit-content;
  color: var(--color-accent);
  font-weight: 600;
  cursor: pointer;
}

.source-reference-body {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  padding-top: var(--space-2);
}

.source-reference-body p { margin: 0; }
.source-reference-body a { color: var(--color-accent); }
.source-reference-body code { overflow-wrap: anywhere; }
.source-urn { margin-left: var(--space-1); }

.lang-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  cursor: pointer;
  padding: var(--space-1) 0;
}

.mobile-view-toggle {
  display: none;
}

.app-main {
  flex: 1 1 auto;
  display: grid;
  /* minmax(0, Nfr), not bare Nfr: a bare fr track still lets its item's
     content-based min-content width override the fr split, which is
     exactly what was happening here — a long unbroken description (or the
     detail panel's own content) in the side column would silently resize
     the whole grid instead of wrapping/truncating within its column. */
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: var(--space-3);
  padding: var(--space-3);
  min-height: 0;
}

.side-column {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 0;
}

.loading-message {
  color: var(--color-text-muted);
  font-style: italic;
  padding: var(--space-3);
}

button {
  font-family: inherit;
  cursor: pointer;
}

@media (max-width: 860px) {
  .app-header {
    flex-wrap: wrap;
    row-gap: var(--space-1);
  }

  .app-header h1 {
    flex: 1 1 100%;
    font-size: 1rem;
  }

  .source-references { padding: var(--space-2); }
  .source-reference-body { display: block; }
  .source-reference-body p + p { margin-top: var(--space-2); }

  .mobile-view-toggle {
    display: flex;
    flex: 0 0 auto;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
  }

  .mobile-view-button {
    flex: 1 1 50%;
    min-height: 44px;
    border: none;
    background: transparent;
    padding: var(--space-2) var(--space-2);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-text-muted);
    border-bottom: 3px solid transparent;
  }

  .mobile-view-button.active {
    color: var(--color-accent);
    border-bottom-color: var(--color-accent);
  }

  /* Below the breakpoint, the text panel and the map+tabs column each take
     the full app-main area, one at a time (toggled by data-mobile-view via
     js/app.js's initMobileNav) — the old approach let them stack vertically
     with app-main scrolling internally, which buried the map and side panel
     under a long scroll below the entire text. A plain 1fr grid track also
     doesn't clip a child's own min-content width (see the minmax(0, Nfr)
     comment above), so the text panel's max-width: 60em was silently
     overflowing the viewport and clipping every line on the right. */
  .app-main {
    display: flex;
    flex-direction: column;
    padding: var(--space-2);
    gap: var(--space-2);
    min-height: 0;
  }

  .app-main .text-panel,
  .app-main .side-column {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
  }

  .app-main[data-mobile-view="text"] .side-column { display: none; }
  .app-main[data-mobile-view="map"] .text-panel { display: none; }
}
