:root {
  --bg: #f5f1e8;
  --panel: #fffdf8;
  --ink: #20160f;
  --muted: #6e6257;
  --line: #d8ccbe;
  --accent: #5b4636;
  --accent-soft: #ede3d6;
  --shadow: 0 18px 48px rgba(48, 30, 12, 0.08);
  --radius: 22px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  background: linear-gradient(180deg, #fbf8f2 0%, var(--bg) 100%);
  color: var(--ink);
  line-height: 1.5;
}

.app-shell {
  max-width: 1300px;
  margin: 0 auto;
  padding: 28px 20px 40px;
}

.card {
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid rgba(216, 204, 190, 0.8);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero {
  padding: 28px 28px 24px;
  margin-bottom: 18px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 10px;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(2rem, 3vw, 3rem); }
.subtitle { color: var(--muted); margin-bottom: 18px; max-width: 70ch; }

.controls {
  display: grid;
  grid-template-columns: minmax(200px, 260px) 1fr;
  gap: 16px;
  align-items: end;
}

.control {
  display: grid;
  gap: 7px;
}

.control span {
  font-size: 0.9rem;
  color: var(--muted);
}

.control select,
.nav-group button {
  font: inherit;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 12px 14px;
}

.control select {
  min-height: 48px;
}

.nav-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.nav-group button {
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.nav-group button:hover:not(:disabled),
.control select:hover:not(:disabled) {
  border-color: #b39b85;
}

.nav-group button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled,
select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.status {
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.95rem;
}

.reader-card {
  padding: 24px 24px 28px;
}

.reader-head {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 18px;
}

.reader-kicker {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 8px;
}

#unit-title {
  font-size: clamp(1.4rem, 2.4vw, 2rem);
  margin-bottom: 0;
}

.counter {
  color: var(--muted);
  font-size: 0.95rem;
}

.reader-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.side-panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  padding: 18px 16px 16px;
  min-height: 420px;
}

.side-panel h3 {
  margin-bottom: 6px;
  font-size: 1.08rem;
}

.side-meta {
  color: var(--muted);
  font-size: 0.92rem;
  margin-bottom: 14px;
}

.text-column {
  display: grid;
  gap: 11px;
}

.line {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
}

.line-number {
  min-width: 58px;
  padding-top: 1px;
  color: var(--muted);
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.line-body {
  min-width: 0;
}

.word-wrap {
  display: inline;
}

.word {
  display: inline-block;
  margin-right: 0.22em;
  padding: 0.06em 0.08em;
  border-radius: 0.35em;
  transition: background 0.12s ease;
  white-space: nowrap;
}

.word:hover {
  background: var(--accent-soft);
}

.word[data-norm]:hover::after,
.word[data-pos]:hover::after,
.word[data-sem]:hover::after,
.word[data-orig]:hover::after {
  content: attr(data-display) " · " attr(data-orig) " · " attr(data-norm) " · " attr(data-pos) " · " attr(data-sem);
  position: absolute;
  z-index: 5;
  margin-top: 1.8em;
  margin-left: -0.5em;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(31, 21, 12, 0.96);
  color: #fff;
  font-size: 0.82rem;
  white-space: nowrap;
  pointer-events: none;
  max-width: 48ch;
  overflow: hidden;
  text-overflow: ellipsis;
}

.word[data-norm=""]:hover::after,
.word[data-pos=""]:hover::after,
.word[data-sem=""]:hover::after,
.word[data-orig=""]:hover::after {
  content: attr(data-display);
}

@media (max-width: 900px) {
  .controls,
  .reader-grid {
    grid-template-columns: 1fr;
  }

  .reader-head {
    flex-direction: column;
    align-items: flex-start;
  }
}
