:root {
  --paper: #f7f3eb;
  --paper-deep: #ebe4d6;
  --ink: #2c2419;
  --ink-muted: #6b6256;
  --accent: #c45c3e;
  --accent-soft: #e8a48f;
  --sage: #5a7d6a;
  --sage-soft: #d4e4db;
  --card: #fffcf7;
  --shadow: 0 8px 28px rgba(44, 36, 25, 0.08);
  --radius: 14px;
  --font-ui: "DM Sans", system-ui, sans-serif;
  --font-serif: "Noto Serif TC", "Noto Serif", serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.45;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(72px + var(--safe-bottom));
}

.top-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 8px;
}

.settings-btn {
  flex-shrink: 0;
  margin-top: 4px;
}

.file-banner {
  margin: 0 16px 8px;
  padding: 12px 14px;
  background: #f0ddd8;
  color: #6b2e22;
  border-radius: var(--radius);
  font-size: 0.85rem;
  line-height: 1.45;
}

.file-banner code {
  font-size: 0.8rem;
}

.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  color: var(--ink);
}

.checkbox-field input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.ocr-progress {
  margin-top: 8px;
  height: 6px;
  background: var(--paper-deep);
  border-radius: 999px;
  overflow: hidden;
}

.ocr-progress span {
  display: block;
  height: 100%;
  background: var(--sage);
  width: 0%;
  transition: width 0.2s ease;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--accent), #a84832);
  color: #fff;
  font-family: var(--font-serif);
  font-size: 1.35rem;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--ink-muted);
}

.due-pill {
  flex-shrink: 0;
  background: var(--sage-soft);
  color: var(--sage);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
}

.view-root {
  flex: 1;
  padding: 8px 16px 24px;
  outline: none;
}

.tab-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(12px + var(--safe-bottom));
  width: min(480px, calc(100% - 24px));
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 6px;
  background: rgba(255, 252, 247, 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--paper-deep);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.tab {
  border: none;
  background: transparent;
  color: var(--ink-muted);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 10px 4px;
  border-radius: 999px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.tab-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.tab.is-active {
  background: var(--ink);
  color: var(--paper);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.btn {
  border: none;
  font: inherit;
  font-weight: 600;
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.secondary {
  background: var(--paper-deep);
  color: var(--ink);
}

.btn.ghost {
  background: transparent;
  color: var(--ink-muted);
}

.btn.full {
  width: 100%;
}

.icon-btn {
  border: none;
  background: var(--paper-deep);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.note-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.note-card {
  border: none;
  padding: 0;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
}

.note-card img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  display: block;
  background: var(--paper-deep);
}

.note-card figcaption {
  padding: 10px 10px 12px;
}

.note-card time {
  display: block;
  font-size: 0.7rem;
  color: var(--ink-muted);
}

.note-card strong {
  display: block;
  font-size: 0.85rem;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-card .auto-badge {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--sage);
  background: var(--sage-soft);
  padding: 3px 8px;
  border-radius: 999px;
}

.note-card .auto-badge.is-pending {
  color: var(--ink-muted);
  background: var(--paper-deep);
}

.auto-section {
  margin-top: 20px;
  padding: 14px;
  background: var(--paper);
  border-radius: var(--radius);
  border: 1px solid var(--paper-deep);
}

.auto-section h3 {
  margin: 0 0 8px;
  font-size: 0.9rem;
}

.auto-section .ocr-snippet {
  font-size: 0.82rem;
  color: var(--ink-muted);
  line-height: 1.55;
  max-height: 100px;
  overflow-y: auto;
  margin: 0;
}

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--ink-muted);
}

.empty p {
  margin: 0 0 16px;
  font-size: 0.95rem;
}

.vocab-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.vocab-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.vocab-row main {
  flex: 1;
  min-width: 0;
}

.vocab-row .lang-badge {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sage);
  font-weight: 700;
}

.vocab-row h3 {
  margin: 4px 0 0;
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 600;
}

.vocab-row .meaning {
  margin: 4px 0 0;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.vocab-row .context {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: var(--ink-muted);
  font-style: italic;
}

.vocab-row button.delete {
  border: none;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 4px;
  font-size: 1.1rem;
}

.review-card {
  background: var(--card);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  padding: 24px 20px 20px;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.review-card .lang-badge {
  font-size: 0.7rem;
  color: var(--sage);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.review-term {
  margin: 16px 0 0;
  font-family: var(--font-serif);
  font-size: clamp(1.8rem, 8vw, 2.4rem);
  font-weight: 600;
  line-height: 1.2;
}

.review-reading {
  margin: 8px 0 0;
  color: var(--ink-muted);
}

.review-answer {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px dashed var(--paper-deep);
  width: 100%;
}

.review-answer[hidden] {
  display: none;
}

.review-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  margin-top: auto;
  padding-top: 20px;
}

.review-actions.three {
  grid-template-columns: repeat(3, 1fr);
}

.review-actions .btn.forgot {
  background: #f0ddd8;
  color: #8b3d2f;
}

.review-actions .btn.got {
  background: var(--sage-soft);
  color: var(--sage);
}

.sheet-dialog {
  border: none;
  padding: 0;
  max-width: min(520px, 100%);
  width: 100%;
  margin: auto;
  background: transparent;
}

.sheet-dialog::backdrop {
  background: rgba(44, 36, 25, 0.45);
}

.sheet {
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
  border-bottom: 1px solid var(--paper-deep);
}

.sheet-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.sheet-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

.sheet-foot {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 12px 16px calc(16px + var(--safe-bottom));
  border-top: 1px solid var(--paper-deep);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-muted);
}

.field input,
.field select,
.field textarea {
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  border: 1px solid var(--paper-deep);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--paper);
}

.camera-preview,
.capture-preview {
  width: 100%;
  border-radius: var(--radius);
  background: #000;
  max-height: 50vh;
  object-fit: contain;
}

.capture-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.file-label {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

.vocab-note-thumb {
  width: 100%;
  max-height: 160px;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--paper-deep);
  margin-bottom: 12px;
}

.hint {
  font-size: 0.78rem;
  color: var(--ink-muted);
  margin: 8px 0 0;
}

.ocr-result {
  margin-top: 10px;
  padding: 12px;
  background: var(--paper);
  border-radius: 10px;
  font-size: 0.88rem;
  line-height: 1.6;
  max-height: 160px;
  overflow-y: auto;
  user-select: text;
}

.ocr-result .word-chip {
  display: inline;
  cursor: pointer;
  border-bottom: 1px dashed var(--accent-soft);
}

.ocr-result .word-chip:hover {
  background: var(--accent-soft);
  color: #fff;
}

.detail-view img {
  width: 100%;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.filter-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 8px;
}

.filter-chip {
  border: 1px solid var(--paper-deep);
  background: var(--card);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.filter-chip.is-active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

@media (min-width: 520px) {
  .sheet-dialog {
    border-radius: var(--radius);
  }

  .sheet {
    border-radius: var(--radius);
  }
}
