:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #5d6470;
  --border: #e2ded4;
  --accent: #2f5d50;
  --accent-hover: #264c41;
  --error-bg: #fbeeec;
  --error-text: #8a2a1f;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  overflow-x: hidden;
}

body.center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

h1 { font-size: 1.5rem; line-height: 1.25; font-weight: 600; margin: 8px 0; }
.muted { color: var(--muted); margin: 0 0 24px; }

.brand {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  box-shadow: 0 1px 2px rgba(31, 35, 40, 0.04);
}

form { display: flex; flex-direction: column; }
label { font-size: 0.875rem; font-weight: 500; margin: 0 0 4px; }

input {
  min-height: 44px;
  padding: 8px 12px;
  margin: 0 0 16px;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

input[type="file"] { max-width: 100%; min-width: 0; }
.panel + .panel { margin-top: 16px; }

input:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  min-height: 44px;
  padding: 8px 16px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

button:hover { background: var(--accent-hover); }
form > button { margin-top: 8px; }

button.ghost {
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--border);
}

button.ghost:hover { background: var(--bg); }

.error {
  margin: 0 0 16px;
  padding: 12px;
  font-size: 0.875rem;
  color: var(--error-text);
  background: var(--error-bg);
  border-radius: 8px;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.page { max-width: 720px; margin: 0 auto; padding: 24px 16px; }

/* Translate page and library (#2) */
h2 { font-size: 1.125rem; font-weight: 600; margin: 32px 0 12px; }
h3 { font-size: 1rem; font-weight: 600; margin: 0 0 4px; }
main, .book, .meta dd { overflow-wrap: anywhere; }

.nav { display: flex; gap: 4px; }
.nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  color: var(--muted);
  text-decoration: none;
  border-radius: 8px;
}
.nav a[aria-current="page"] { color: var(--accent); font-weight: 600; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

textarea {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  margin: 0 0 16px;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
}
textarea:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.label { font-size: 0.875rem; font-weight: 500; margin: 0 0 4px; }
.service {
  margin: 0 0 16px;
  padding: 8px 12px;
  color: var(--muted);
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 8px;
}

.books { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.book {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.status { margin: 0 0 8px; font-size: 0.875rem; color: var(--muted); }
.status-done { color: var(--accent); }
.status-error { color: var(--error-text); font-weight: 600; }
.warn { margin: 0 0 8px; font-size: 0.875rem; color: var(--error-text); }

.meta { margin: 0 0 12px; font-size: 0.875rem; }
.meta dt { color: var(--muted); margin-top: 4px; }
.meta dd { margin: 0; }
.meta dd a { display: block; color: var(--accent); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
a.button {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 16px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border-radius: 8px;
  text-decoration: none;
}
a.button:hover { background: var(--accent-hover); }

/* Compare page: two columns, one grid row per paragraph id, so a tall cell makes the row tall on both sides. */
.page.wide { max-width: 1100px; }
.switch { display: none; gap: 8px; margin: 0 0 16px; }
.switch button { flex: 1; min-width: 0; padding: 8px 4px; font-size: 0.875rem; }
.switch button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; }
.cell { min-width: 0; overflow-wrap: anywhere; padding: 8px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.cell.pending { color: var(--muted); font-style: italic; }
.compare[data-view="original"] .trans, .compare[data-view="translation"] .orig { display: none; }
.compare[data-view="original"], .compare[data-view="translation"] { grid-template-columns: 1fr; }

@media (max-width: 640px) {
  .switch { display: flex; }
  .compare { grid-template-columns: 1fr; gap: 0; }
  .cell.orig { background: var(--bg); color: var(--muted); border-bottom: 0; border-radius: 8px 8px 0 0; }
  .cell.trans { border-radius: 0 0 8px 8px; margin-bottom: 12px; }
  .compare[data-view="original"] .cell, .compare[data-view="translation"] .cell { border-radius: 8px; border-bottom: 1px solid var(--border); }
}

/* Preprompt history and re-translate (#4) */
.history { margin: 8px 0 16px; }
.history summary { display: flex; align-items: center; min-height: 44px; cursor: pointer; }
.history-list, .history-item { list-style: none; margin: 0; padding: 0; }
.history-item { padding: 8px 0; border-top: 1px solid var(--border); }
.history-use { width: 100%; text-align: left; white-space: normal; }
select { width: 100%; min-height: 44px; margin-bottom: 8px; }
.again { margin: 8px 0; }
