@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,600;1,400&family=Nunito+Sans:wght@400;600;700;800&display=swap');

:root {
  --bg-color: #fbf5ec;
  --bg-elevated: #ffffff;
  --text-color: #3a2e26;
  --text-muted: #8a7a6d;
  --header-bg: #7a4a30;
  --header-bg-2: #9a6543;
  --header-text: #fff8ef;
  --nav-bg: #fffaf2;
  --border-color: #e7dac8;
  --highlight: #ffd76a;
  --accent: #c9762f;
  --accent-2: #4c7a5e;
  --danger: #c0533a;
  --shadow: 0 2px 10px rgba(90, 60, 30, 0.08);
  --shadow-lift: 0 6px 20px rgba(90, 60, 30, 0.14);
  --radius: 16px;
  --radius-sm: 10px;
  --font-ui: 'Nunito Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-read: 'Lora', Georgia, 'Times New Roman', serif;
}

body[data-theme="dark"] {
  --bg-color: #1c1712;
  --bg-elevated: #26201a;
  --text-color: #f1e7da;
  --text-muted: #b4a493;
  --header-bg: #2a2019;
  --header-bg-2: #3a281c;
  --header-text: #f6ead9;
  --nav-bg: #201a15;
  --border-color: #3a3026;
  --highlight: #e0a83f;
  --accent: #e0965a;
  --accent-2: #6fae8a;
  --shadow: 0 2px 10px rgba(0,0,0,0.35);
  --shadow-lift: 0 6px 20px rgba(0,0,0,0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-ui);
  background: var(--bg-color);
  color: var(--text-color);
  transition: background 0.2s ease, color 0.2s ease;
}
#app { display: flex; flex-direction: column; min-height: 100vh; }

/* ---------- Header ---------- */
.app-header {
  background: linear-gradient(135deg, var(--header-bg), var(--header-bg-2));
  color: var(--header-text);
  padding: 1.1rem 1rem 0.9rem;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.app-header:active { opacity: 0.9; }
.app-main-title { font-size: 2rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.short-hyphen { letter-spacing: -0.35em; margin-right: 0.05em; opacity: 0.7; }
.app-sub-title { font-size: 0.85rem; font-weight: 600; opacity: 0.85; margin-top: 0.15rem; letter-spacing: 0.02em; }

/* ---------- Layout ---------- */
#content { flex: 1; overflow-y: auto; padding: 1.1rem 1rem 5.5rem; max-width: 720px; width: 100%; margin: 0 auto; }

.page-head { margin-bottom: 1rem; }
.page-head h2 { font-size: 1.5rem; font-weight: 800; }
.page-sub { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.15rem; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  display: flex; justify-content: space-around; background: var(--nav-bg);
  border-top: 1px solid var(--border-color); position: fixed; bottom: 0; left: 0; right: 0;
  padding-bottom: env(safe-area-inset-bottom, 0);
  box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
  z-index: 50;
}
.bottom-nav button {
  background: none; border: none; flex: 1; cursor: pointer; color: var(--text-muted);
  font-size: 0.68rem; font-family: var(--font-ui); font-weight: 700;
  padding: 0.5rem 0.2rem 0.55rem; display: flex; flex-direction: column; align-items: center; gap: 0.2rem;
}
.nav-icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.bottom-nav button svg [fill] { fill: currentColor; }
.bottom-nav button.active { color: var(--accent); }
.bottom-nav button.active .nav-icon { transform: translateY(-1px); }

/* ---------- Cards & chips ---------- */
.card {
  background: var(--bg-elevated); border: 1px solid var(--border-color); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.filter-row { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border-color); background: var(--bg-elevated); color: var(--text-color);
  padding: 0.4rem 0.9rem; border-radius: 999px; font-family: var(--font-ui); font-weight: 700;
  font-size: 0.85rem; cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Library ---------- */
.library-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.book-card { display: flex; flex-direction: column; gap: 0.35rem; }
.book-card-top { display: flex; justify-content: space-between; align-items: center; }
.flag-badge { font-size: 1.3rem; }
.level-badge {
  font-size: 0.7rem; font-weight: 800; padding: 0.25rem 0.6rem; border-radius: 999px;
  background: #eee2cf; color: #7a4a30; letter-spacing: 0.02em;
}
body[data-theme="dark"] .level-badge { background: #3a2e1f; color: #e0c79a; }
.level-badge.level-absolute-beginner { background: #dff0e4; color: #2e6b45; }
.level-badge.level-beginner { background: #e6efd9; color: #4c7a2f; }
.level-badge.level-intermediate { background: #fdeccb; color: #a06a1c; }
.level-badge.level-advanced { background: #f6dad2; color: #a3402a; }
body[data-theme="dark"] .level-badge.level-absolute-beginner { background: #1e3327; color: #8fd6a8; }
body[data-theme="dark"] .level-badge.level-beginner { background: #2a3320; color: #b7d68f; }
body[data-theme="dark"] .level-badge.level-intermediate { background: #3a2c15; color: #f0c37e; }
body[data-theme="dark"] .level-badge.level-advanced { background: #3a2019; color: #f0a48e; }
.book-card-title { font-size: 1.15rem; font-weight: 700; margin-top: 0.15rem; }
.book-card-author { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.3rem; }

@media (min-width: 640px) {
  .library-grid { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 980px) {
  .library-grid { grid-template-columns: 1fr 1fr 1fr; }
  #content { max-width: 1080px; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
  padding: 0.7rem 1.1rem; background: var(--bg-elevated); color: var(--text-color);
  border: 1px solid var(--border-color); border-radius: var(--radius-sm); cursor: pointer;
  margin: 0.3rem 0.3rem 0.3rem 0; font-size: 0.95rem; font-family: var(--font-ui); font-weight: 700;
  min-height: 44px; transition: transform 0.08s ease, box-shadow 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-outline { background: transparent; }
.btn-active { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn-block { display: flex; width: 100%; }
.btn-icon-only { padding: 0.6rem; min-width: 44px; }
.btn-speak { background: var(--accent-2); border-color: var(--accent-2); color: #fff; font-size: 0.85rem; padding: 0.5rem 0.9rem; margin: 0; }

/* ---------- Reader ---------- */
.reader-header { margin-bottom: 1.2rem; }
.reader-book-title { font-size: 0.8rem; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.reader-chapter-title { font-size: 1.3rem; font-weight: 800; margin: 0.15rem 0 0.2rem; font-family: var(--font-read); }
.reader-progress { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.7rem; }
.reader-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; padding: 0.7rem 0.8rem; background: var(--bg-elevated); border: 1px solid var(--border-color); border-radius: var(--radius-sm); }
.speed-control { display: flex; align-items: center; gap: 0.5rem; flex: 1; min-width: 140px; }
.speed-control input[type=range] { flex: 1; accent-color: var(--accent); }
.speed-label { font-size: 1rem; }

/* Each reader-unit groups one paragraph with its own "read aloud" button.
   Tight gap above (between the button and its own text) and a much bigger
   gap below (before the next paragraph) makes the ownership unambiguous. */
.reader-unit { margin-bottom: 1.9rem; }
.reader-unit:last-child { margin-bottom: 0; }
.reader-body p.reader-para {
  font-family: var(--font-read);
  font-size: 1.25rem;
  line-height: 2.1;
  margin-bottom: 0.5rem;
  position: relative;
}
.word-token {
  display: inline-block; margin: 0 1px; cursor: pointer; border-radius: 4px; padding: 0 1px;
  -webkit-user-select: none; user-select: none;
}
.word-token:hover { background: var(--border-color); }
.word-token.drag-active { background: var(--highlight) !important; color: #402c00 !important; box-shadow: 0 0 0 2px var(--highlight); }
.nav-buttons { display: flex; justify-content: space-between; margin: 1.5rem 0 1rem; gap: 0.5rem; }
.nav-buttons .btn { flex: 1; }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(30, 20, 10, 0.45); display: flex; align-items: flex-end; z-index: 1000; }
.modal {
  background: var(--bg-elevated); width: 100%; padding: 1.4rem 1.3rem calc(1.4rem + env(safe-area-inset-bottom, 0));
  border-radius: 20px 20px 0 0; max-height: 78vh; overflow-y: auto; box-shadow: var(--shadow-lift);
}
.modal p { margin-bottom: 0.55rem; line-height: 1.5; }
.modal-word { font-family: var(--font-read); font-size: 1.6rem; margin-bottom: 0.6rem; color: var(--accent); }
.modal-sentence { font-style: italic; color: var(--text-muted); }
.modal-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.8rem; }
.hidden { display: none; }

/* ---------- Vocab / Review ---------- */
.vocab-card { display: flex; align-items: center; justify-content: space-between; padding: 0.85rem 1rem; }
.vocab-card-main { display: flex; align-items: center; gap: 0.7rem; }
.vocab-word { font-family: var(--font-read); font-size: 1.05rem; display: block; }
.vocab-meaning { color: var(--text-muted); font-size: 0.85rem; }

.review-card { text-align: center; padding: 1.6rem 1.2rem; }
.review-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.review-word { font-family: var(--font-read); font-size: 2rem; margin: 0.3rem 0 0.8rem; color: var(--accent); }
.review-sentence { font-style: italic; color: var(--text-muted); margin: 0.6rem 0 1rem; }
.rating-row { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: center; margin-top: 1rem; }
.rating-btn { color: #fff; border: none; flex: 1 1 auto; min-width: 90px; }
.rating-again { background: #b8503a; }
.rating-hard { background: #c98a3a; }
.rating-ok { background: #c9a63a; color: #402c00; }
.rating-easy { background: #6a9a4c; }
.rating-known { background: #4c7a5e; }

/* ---------- Settings ---------- */
.settings-label { display: block; font-weight: 700; margin-bottom: 0.5rem; }
.settings-hint { color: var(--text-muted); font-size: 0.8rem; margin-top: 0.4rem; }
.select-input {
  width: 100%; padding: 0.6rem 0.7rem; border-radius: var(--radius-sm); border: 1px solid var(--border-color);
  background: var(--bg-color); color: var(--text-color); font-family: var(--font-ui); font-size: 0.95rem;
}
.about-card p { margin-bottom: 0.3rem; color: var(--text-muted); font-size: 0.85rem; }
.about-card p:first-child { color: var(--text-color); font-weight: 700; font-size: 1rem; }

/* ---------- Misc ---------- */
.empty-state { text-align: center; color: var(--text-muted); padding: 2.5rem 1rem; line-height: 1.6; }
.error-text { color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: 5.5rem; transform: translate(-50%, 12px); opacity: 0;
  background: var(--text-color); color: var(--bg-color); padding: 0.7rem 1.2rem; border-radius: 999px;
  font-weight: 700; font-size: 0.9rem; box-shadow: var(--shadow-lift); transition: all 0.25s ease; z-index: 2000;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
