:root {
  color-scheme: light dark;
  --bg: #f6f6f3;
  --panel: #ffffff;
  --text: #171717;
  --muted: #8a8a84;
  --line: #e7e7e2;
  --soft: #f0f0ec;
  --accent: #1f1f1f;
  --danger: #b42318;
  --translation-bg: #e2cf9f;
  --translation-border: #bca472;
  --translation-text: #332a1d;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101010;
    --panel: #171717;
    --text: #f4f4f1;
    --muted: #8d8d87;
    --line: #2b2b2b;
    --soft: #222222;
    --accent: #f4f4f1;
    --danger: #ff6b5e;
    --translation-bg: #8f7b52;
    --translation-border: #a99468;
    --translation-text: #fff8e8;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { overflow: hidden; overscroll-behavior: none; }
button, textarea, input { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  gap: 8px;
  align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}
.title-wrap { text-align: center; min-width: 0; }
.article-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress-text { margin-top: 2px; color: var(--muted); font-size: 12px; }
.icon-btn { width: 42px; height: 42px; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 14px; font-size: 22px; }

.reader-view {
  position: fixed;
  inset: 0;
  padding: calc(88px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: minmax(110px, 1fr) auto minmax(110px, 1fr);
  gap: 20px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.context-line {
  display: flex;
  justify-content: center;
  text-align: center;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(16px, 4vw, 22px);
  line-height: 1.55;
  opacity: .45;
  padding: 8px 12px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}
.context-prev { align-items: flex-end; }
.context-next { align-items: flex-start; }
.muted { color: var(--muted); }

.sentence-card {
  position: relative;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 8px 0;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  box-shadow: none;
  touch-action: none;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

.mode-badge {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .10em;
  padding: 6px 9px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  margin-bottom: 16px;
}

.sentence-text {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(28px, 6.3vw, 46px);
  line-height: 1.42;
  letter-spacing: -.012em;
  text-align: center;
  width: 100%;
}
.word-token { display: inline; border-radius: 7px; transition: background .12s ease; user-select: none; -webkit-user-select: none; }
.word-token:active { background: var(--soft); }

.word-popover {
  position: absolute;
  z-index: 6;
  left: 50%;
  top: calc(100% + 8px);
  transform: translateX(-50%);
  width: min(680px, calc(100vw - 40px));
  margin: 0;
  background: var(--translation-bg);
  color: var(--translation-text);
  border: 1px solid var(--translation-border);
  border-radius: 14px;
  padding: 12px 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
  text-align: center;
}
.popover-word { font-weight: 800; font-size: 13px; color: #6f5a36; }
.popover-meaning { margin-top: 4px; font-size: 17px; line-height: 1.5; }

@media (prefers-color-scheme: dark) {
  .popover-word { color: #ead9af; }
}

.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: end center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.48); backdrop-filter: blur(5px); }
.modal-card { position: relative; width: min(680px, 100%); max-height: 86dvh; overflow-y: auto; background: var(--panel); border-radius: 28px 28px 0 0; padding: 26px 20px calc(24px + env(safe-area-inset-bottom)); z-index: 1; }
.modal-close { position: absolute; right: 16px; top: 14px; width: 38px; height: 38px; border: 0; border-radius: 999px; background: var(--soft); color: var(--text); font-size: 22px; }
.detail-word { font-family: Georgia, serif; font-size: 34px; font-weight: 800; margin-bottom: 24px; padding-right: 48px; }
.detail-section { padding: 16px 0; border-top: 1px solid var(--line); }
.detail-label { color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 8px; }
.detail-body { line-height: 1.65; }
.chip-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--soft); border-radius: 999px; padding: 8px 10px; }
.detail-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.primary-btn, .sort-btn, .secondary-btn, .danger-btn { border: 1px solid var(--line); background: var(--soft); color: var(--text); border-radius: 14px; padding: 11px 14px; font-weight: 700; }
.primary-btn { background: var(--text); color: var(--bg); text-align: center; text-decoration: none; }
.link-btn { display: flex; align-items: center; justify-content: center; }

.dashboard-view { position: fixed; inset: 0; overflow-y: auto; max-width: 980px; margin: 0 auto; padding: calc(18px + env(safe-area-inset-top)) 18px calc(28px + env(safe-area-inset-bottom)); background: var(--bg); }
.dashboard-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dashboard-header h1 { font-size: clamp(26px, 7vw, 42px); margin: 10px 0 18px; }
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat-card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 16px; }
.stat-card span { display: block; color: var(--muted); font-size: 12px; }
.stat-card strong { display: block; margin-top: 4px; font-size: 28px; }
.dashboard-toolbar { display: flex; gap: 8px; overflow-x: auto; margin: 18px 0 12px; }
.sort-btn.active { outline: 2px solid var(--text); }
.vocab-list { display: grid; gap: 8px; }
.vocab-row { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px; display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; }
.vocab-main strong { display: block; font-size: 18px; }
.vocab-main span { color: var(--muted); font-size: 12px; }
.mastery { font-weight: 800; }
.dashboard-actions { display: grid; gap: 10px; margin-top: 20px; }
.secondary-btn { background: var(--panel); }
.danger-btn { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
.import-card textarea { width: 100%; min-height: 280px; resize: vertical; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.import-card input { margin-top: 12px; width: 100%; }
.import-actions { margin-top: 14px; }
.small { font-size: 13px; }

@media (min-width: 760px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .modal { place-items: center; }
  .modal-card { border-radius: 28px; margin: 20px; }
}
