:root {
  --paper: #f5f1e8;
  --paper-light: #fbf9f4;
  --ink: #203338;
  --muted: #708083;
  --line: #d9dfda;
  --teal: #2c7c73;
  --teal-dark: #1e5d58;
  --coral: #e47f62;
  --coral-soft: #f3d3c7;
  --shadow: 0 18px 40px rgba(32, 51, 56, 0.08);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--paper); }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  background-image: radial-gradient(rgba(94, 75, 47, .08) .55px, transparent .7px), radial-gradient(rgba(255, 255, 255, .36) .65px, transparent .8px), repeating-linear-gradient(0deg, rgba(110, 87, 54, .018) 0, rgba(110, 87, 54, .018) 1px, transparent 1px, transparent 4px);
  background-size: 5px 5px, 7px 7px, auto;
  background-position: 0 0, 2px 3px, 0 0;
  font-family: "Segoe UI", Inter, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; max-width: 1500px; margin: 0 auto; padding: 0 34px 30px; }

.topbar {
  min-height: 86px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line); gap: 24px;
}

.brand-lockup { display: flex; align-items: center; gap: 12px; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--coral); color: #fffaf4; font: 700 18px Georgia, serif; }
.eyebrow, .section-kicker { margin: 0; color: var(--teal); font-size: 10px; font-weight: 800; letter-spacing: .18em; }
.brand-lockup h1 { margin: 2px 0 0; font: 700 18px Georgia, serif; letter-spacing: .01em; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.button { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 15px; border: 1px solid transparent; border-radius: 6px; font-size: 12px; font-weight: 700; letter-spacing: .01em; transition: .2s ease; }
.button span { font-size: 17px; line-height: 0; font-weight: 400; }
.button-primary { background: var(--teal); color: white; box-shadow: 0 4px 10px rgba(44, 124, 115, .15); }
.button-primary:hover { background: var(--teal-dark); transform: translateY(-1px); }
.button-ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.button-ghost:hover, .button-outline:hover { color: var(--teal-dark); border-color: var(--teal); background: rgba(44, 124, 115, .05); }
.button-outline { background: transparent; border-color: var(--line); color: var(--teal); }

.reading-toolbar { min-height: 68px; display: flex; align-items: center; gap: 18px; border-bottom: 1px solid var(--line); }
.toolbar-group { display: flex; gap: 4px; }
.toolbar-button { border: 0; background: transparent; color: var(--muted); padding: 8px 10px; border-radius: 5px; font-size: 12px; font-weight: 700; }
.toolbar-button span { margin-right: 5px; color: var(--coral); }
.toolbar-button.is-active { color: var(--ink); background: var(--paper-light); box-shadow: 0 1px 3px rgba(32,51,56,.06); }
.toolbar-divider { width: 1px; height: 26px; background: var(--line); }
.range-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; font-weight: 700; white-space: nowrap; }
input[type="range"] { width: 74px; accent-color: var(--coral); }
.range-control-line input { width: 80px; }
.toolbar-spacer { flex: 1; }
.selection-hint { color: var(--muted); font-size: 11px; }
.current-time { white-space: nowrap; font-variant-numeric: tabular-nums; }
.hint-dot { display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: var(--coral); vertical-align: 1px; }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 28px; padding-top: 29px; }
.reader-panel, .glossary-panel { min-width: 0; }
.article-header { display: flex; align-items: flex-start; justify-content: center; gap: 18px; }
.article-header > div:first-child { grid-column: 2; text-align: center; }
.glossary-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.article-header h2, .glossary-heading h2 { margin: 5px 0 0; color: var(--ink); font: 700 23px Georgia, serif; letter-spacing: -.01em; }
.article-meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; color: var(--muted); font-size: 11px; }
.reader-panel > .article-meta { justify-content: flex-end; margin: 8px 4px 0; }
.editor-view:not(.is-hidden) ~ .article-meta { display: none; }
.meta-dot { width: 3px; height: 3px; border-radius: 50%; background: var(--coral); }

.editor-view { margin-top: 26px; }
.editor-view textarea { display: block; width: 100%; min-height: 510px; padding: 28px; border: 1px solid var(--line); border-radius: 6px; resize: vertical; outline: none; color: var(--ink); background: var(--paper-light); font: 19px/1.72 Georgia, serif; box-shadow: var(--shadow); }
.editor-view textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(44,124,115,.1); }
.editor-footer { display: flex; align-items: center; justify-content: space-between; padding: 12px 2px 0; color: var(--muted); font-size: 11px; }

.article-body { padding: 6px 4px 20px; font-size: 19px; line-height: 1.72; font-family: Georgia, serif; color: #2f4143; }
.article-body[data-font="sans"] { font-family: Inter, "Segoe UI", sans-serif; }
.article-body[data-font="mono"] { font-family: "Courier New", monospace; font-size: 16px; }
.article-paragraph { margin: 0; }
.article-title-paragraph { text-align: center; text-indent: 0; }
.paragraph-indent { display: inline-block; width: 2em; height: 1px; }
.token { border-radius: 2px; cursor: pointer; transition: background .15s ease; }
.token:hover { background: rgba(228,127,98,.28); }
.token.is-marked { text-decoration-line: underline; text-decoration-style: dashed; text-decoration-thickness: 1.5px; text-decoration-color: var(--coral); text-underline-offset: 2px; }
.token-wrap:hover .token { background: rgba(228,127,98,.28); }
.token-wrap { position: relative; display: inline-block; vertical-align: baseline; line-height: 1; }
.translation-line { position: absolute; top: calc(100% + 2px); left: 50%; z-index: 2; display: block; margin: 0; padding: 0 0 0 2px; border-left: 1px solid var(--coral); color: var(--teal-dark); background: transparent; font-family: "Segoe UI", sans-serif; font-size: 10px; line-height: 1; text-align: center; cursor: pointer; white-space: nowrap; transform: translateX(-50%); }
.translation-line em { color: var(--muted); font-style: normal; }
.article-body.is-hidden, .editor-view.is-hidden, .empty-reading.is-hidden { display: none; }
.empty-reading { min-height: 430px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--muted); }
.empty-icon { display: grid; place-items: center; width: 60px; height: 60px; margin-bottom: 15px; border: 1px solid var(--coral-soft); border-radius: 50%; color: var(--coral); font: 20px Georgia, serif; }
.empty-reading h3 { margin: 0 0 7px; color: var(--ink); font: 700 20px Georgia, serif; }
.empty-reading p { margin: 0 0 20px; font-size: 12px; line-height: 1.7; }

.glossary-panel { display: flex; min-height: 560px; flex-direction: column; padding: 20px 20px 14px; border-left: 1px solid var(--line); background: rgba(251,249,244,.45); }
.panel-view.is-hidden { display: none; }
.glossary-heading h2 { font-size: 19px; }
.glossary-heading h2 span { display: inline-block; min-width: 23px; padding: 3px 5px; border-radius: 10px; background: var(--coral-soft); color: var(--teal-dark); font: 700 11px "Segoe UI", sans-serif; text-align: center; vertical-align: 2px; }
.icon-button { width: 29px; height: 29px; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--teal); font-size: 17px; }
.icon-button:hover { border-color: var(--teal); background: rgba(44,124,115,.06); }
.glossary-list { flex: 1; margin-top: 24px; overflow: auto; }
.glossary-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0; padding: 24px 0; gap: 10px; color: var(--muted); text-align: center; }
.glossary-empty p { margin: 0; font: 14px/1.8 Georgia, serif; }
.empty-rule { width: 28px; height: 1px; background: var(--coral); }
.glossary-item { position: relative; display: grid; grid-template-columns: 25px 1fr auto; gap: 8px; align-items: start; padding: 13px 0 12px; border-bottom: 1px solid var(--line); }
.glossary-index { padding-top: 3px; color: var(--coral); font: 11px/1 "Segoe UI", sans-serif; }
.glossary-word { margin: 0; color: var(--ink); font: 700 16px/1.3 Georgia, serif; }
.glossary-meaning { margin: 4px 0 0; color: var(--teal-dark); font-size: 12px; line-height: 1.5; }
.glossary-note { color: var(--muted); font-size: 10px; }
.glossary-remove { width: 22px; height: 22px; border: 0; background: transparent; color: #a6b0ad; font-size: 17px; }
.glossary-remove:hover { color: var(--coral); }
.article-history { margin-top: 35px; padding-top: 22px; border-top: 1px solid var(--line); }
.history-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 15px; }
.history-heading h3 { margin: 5px 0 0; font: 700 18px Georgia, serif; }
.history-heading > span { color: var(--muted); font-size: 11px; }
.history-list { display: grid; gap: 7px; max-height: 230px; margin-top: 14px; overflow: auto; }
.history-item { display: grid; grid-template-columns: 1fr auto; align-items: stretch; border: 1px solid var(--line); border-radius: 5px; background: var(--paper-light); }
.history-item.is-current { border-color: var(--teal); box-shadow: 0 0 0 2px rgba(44,124,115,.08); }
.history-select { display: flex; min-width: 0; flex-direction: column; align-items: flex-start; gap: 4px; padding: 11px 12px; border: 0; background: transparent; color: var(--ink); text-align: left; }
.history-title { width: 100%; overflow: hidden; font: 700 13px Georgia, serif; text-overflow: ellipsis; white-space: nowrap; }
.history-meta { color: var(--muted); font-size: 10px; }
.history-delete { width: 34px; border: 0; border-left: 1px solid var(--line); background: transparent; color: #a6b0ad; font-size: 17px; }
.history-delete:hover { color: var(--coral); background: rgba(228,127,98,.06); }
.history-empty { margin-top: 14px; padding: 20px; border: 1px dashed var(--line); color: var(--muted); font-size: 11px; text-align: center; }
.article-library-panel .history-heading { align-items: flex-start; }
.article-library-panel .history-heading h2 { margin: 5px 0 0; font: 700 19px Georgia, serif; }
.article-library-panel .history-list { max-height: none; }

.export-dialog { width: min(480px, calc(100vw - 28px)); padding: 0; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: var(--paper-light); box-shadow: 0 24px 70px rgba(32,51,56,.22); }
.export-dialog::backdrop { background: rgba(32,51,56,.28); }
.export-dialog form { padding: 24px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.dialog-heading h2 { margin: 5px 0 0; font: 700 21px Georgia, serif; }
.dialog-copy { margin: 15px 0; color: var(--muted); font-size: 12px; }
.export-options { display: grid; gap: 8px; max-height: 280px; overflow: auto; }
.export-option { display: flex; align-items: center; gap: 11px; padding: 12px; border: 1px solid var(--line); border-radius: 5px; background: var(--paper); cursor: pointer; }
.export-option:has(input:checked) { border-color: var(--teal); background: rgba(44,124,115,.06); }
.export-option input { width: 16px; height: 16px; accent-color: var(--teal); }
.export-option span { display: flex; min-width: 0; flex-direction: column; gap: 3px; }
.export-option strong { overflow: hidden; font: 700 13px Georgia, serif; text-overflow: ellipsis; white-space: nowrap; }
.export-option small { color: var(--muted); font-size: 10px; }
.dialog-footer { display: flex; justify-content: flex-end; gap: 9px; padding-top: 20px; }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 10; padding: 10px 16px; border: 1px solid var(--line); border-radius: 5px; background: var(--ink); color: white; font-size: 12px; opacity: 0; pointer-events: none; transform: translate(-50%, 10px); transition: .25s ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .app-shell { padding: 0 20px 24px; }
  .reading-toolbar { flex-wrap: wrap; padding: 12px 0; gap: 10px 14px; }
  .toolbar-spacer { display: none; }
  .selection-hint { margin-left: auto; }
  .workspace { grid-template-columns: 1fr; }
  .glossary-panel { min-height: 300px; border-top: 1px solid var(--line); border-left: 0; padding: 20px 0 0; }
  .glossary-list { max-height: 320px; }
}

@media (max-width: 570px) {
  .app-shell { padding: 0 14px 20px; }
  .topbar { align-items: flex-start; flex-direction: column; padding: 18px 0 15px; gap: 15px; }
  .topbar-actions { width: 100%; }
  .topbar-actions .button { flex: 1; }
  .article-header h2 { font-size: 20px; }
  .article-header > div:first-child { text-align: center; }
  .article-meta { display: block; line-height: 1.8; text-align: right; }
  .meta-dot { display: none; }
  .selection-hint { width: 100%; margin-left: 0; }
  .toolbar-divider { display: none; }
  .editor-view textarea { min-height: 430px; padding: 18px; font-size: 17px; }
  .article-body { font-size: 18px; }
}
