:root {
  --bg: #0f1220;
  --surface: #1a1e33;
  --surface-2: #232842;
  --border: #2e3454;
  --text: #e7e9f3;
  --muted: #9aa0bf;
  --accent: #6c8cff;
  --accent-2: #4ad6a0;
  --danger: #ff6b6b;
  --radius: 10px;
}

/* Light theme — applied when <html data-theme="light"> */
:root[data-theme="light"] {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eceff6;
  --border: #d7dce8;
  --text: #191d2b;
  --muted: #5c6377;
  --accent: #4257d0;
  --accent-2: #12946a;
  --danger: #d64141;
}
/* A few chips are tuned for dark; boost contrast on light. */
:root[data-theme="light"] .g-m { background: rgba(66,87,208,0.14); color: #3346c0; }
:root[data-theme="light"] .g-f { background: rgba(214,65,65,0.12); color: #c23b3b; }
:root[data-theme="light"] .g-n { background: rgba(18,148,106,0.12); color: #0f7d5a; }
:root[data-theme="light"] .topbar { box-shadow: 0 1px 3px rgba(0,0,0,0.04); }

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Single-instance block ---- */
.single-overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 1.5rem; z-index: 1000; }
.single-card { max-width: 420px; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem 1.75rem; }
.single-card h1 { margin-top: 0; }
.single-card p { color: var(--muted); line-height: 1.6; }

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); }
.brand:hover { text-decoration: none; color: var(--accent); }
.topnav { display: flex; gap: 1rem; margin-left: 1.5rem; flex: 1; }
/* Sections that require an account are hidden until signed in (body.authed is
   toggled by renderAuthArea). Hidden by default so they never flash pre-auth. */
body:not(.authed) .auth-only { display: none !important; }
.topnav a { color: var(--muted); font-size: 0.9rem; }
.topnav a:hover { color: var(--text); text-decoration: none; }
.topnav a.active { color: var(--text); font-weight: 600; }
.topnav a { position: relative; }
.due-badge {
  display: inline-block; margin-left: 0.3rem; background: var(--accent-2); color: #04160f;
  border-radius: 999px; font-size: 0.68rem; font-weight: 700; padding: 0.02rem 0.35rem; vertical-align: middle;
}

/* ---- Familiarity rundown (profile) ---- */
.familiarity-rundown { margin-top: 1.5rem; }
.fam-row { display: flex; align-items: center; gap: 1rem; padding: 0.6rem 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.fam-lang { font-weight: 600; min-width: 140px; }
.fam-stats { display: flex; gap: 1.1rem; flex-wrap: wrap; }
.fam-stat { text-align: center; }
.fam-value { font-weight: 700; color: var(--accent-2); }
.fam-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }

/* ---- Correction diff ---- */
.diff-del { text-decoration: line-through; color: var(--danger); opacity: 0.8; }
.diff-ins { color: var(--accent-2); font-weight: 600; }
.search-form { flex: 0 1 240px; margin: 0 0.75rem; }
.search-form input {
  width: 100%; padding: 0.4rem 0.7rem; font-size: 0.9rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 999px; color: var(--text);
}
.search-result { display: block; color: var(--text); }
.search-result:hover { border-color: var(--accent); text-decoration: none; }
@media (max-width: 680px) { .search-form { flex-basis: 140px; margin: 0 0.4rem; } }
.auth-area { display: flex; align-items: center; gap: 0.6rem; }
.avatar.sm { width: 28px; height: 28px; font-size: 0.72rem; }
.person-card .card-top { align-items: center; }
.person-name { display: flex; align-items: center; gap: 0.5rem; color: var(--text); }
.person-name:hover { text-decoration: none; color: var(--accent); }
.prof-counts { font-size: 0.85rem; margin-bottom: 1rem; }
.auth-area .who { color: var(--muted); font-size: 0.9rem; }
.welcome-steps { margin: 0.5rem 0 0; padding-left: 1.25rem; }
.welcome-steps li { margin: 0.4rem 0; }
.native-picker { display: flex; align-items: center; gap: 0.35rem; }
.native-select { width: auto; padding: 0.3rem 0.5rem; font-size: 0.85rem; }

/* ---- Layout ---- */
.layout {
  min-height: calc(100vh - 57px);
}
/* Languages: a horizontal bar under the header (was a left sidebar). */
.lang-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.lang-bar-label {
  flex-shrink: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
/* Hide the language carousel inside the immersive World so you can't
   accidentally navigate out of it by clicking a language. */
body.in-world .lang-bar { display: none; }
/* Carousel viewport: scrolls horizontally, scrollbar hidden (arrows drive it). */
.lang-viewport {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
}
.lang-viewport::-webkit-scrollbar { display: none; }
/* Prev / next arrow buttons. */
.lang-nav {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0 2px;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}
.lang-nav:hover { border-color: var(--accent); color: var(--accent); }
.lang-nav[hidden] { display: none; }
.lang-nav:disabled { opacity: 0.3; cursor: default; border-color: var(--border); color: var(--muted); }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1rem;
}
.sidebar-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 0.75rem;
  background: none;
  border: none;
  padding: 0.25rem 0;
  cursor: pointer;
  font-family: inherit;
}
.sidebar-title:hover { color: var(--text); }
.sidebar-title .caret { transition: transform 0.12s; }
.sidebar-title.collapsed .caret { transform: rotate(-90deg); }
/* Horizontal padding keeps the first/last pill clear of the viewport fade mask. */
.language-list { display: flex; flex-direction: row; align-items: center; gap: 0.4rem; padding: 2px 14px; }
.language-list a {
  display: block;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  color: var(--text);
  white-space: nowrap;
}
.language-list a:hover { background: var(--surface-2); text-decoration: none; }
.language-list a.active { background: var(--accent); color: #fff; }
.lang-row { display: inline-flex; align-items: center; gap: 0.2rem; flex-shrink: 0; }
/* Languages you're not (yet) learning: dimmed, click a pill to add it. */
.lang-row.not-learning a { color: var(--muted); }
.lang-row.not-learning a:hover { color: var(--text); background: var(--surface-2); }
/* Divider between your languages and the rest of the catalogue. */
.lang-divider {
  flex-shrink: 0;
  align-self: stretch;
  width: 1px;
  margin: 0.15rem 0.35rem;
  background: var(--border);
}
.lang-native-tag {
  font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--accent-2); border: 1px solid var(--accent-2); border-radius: 999px;
  padding: 0.02rem 0.35rem; flex-shrink: 0;
}
.lang-remove {
  border: none; background: none; color: var(--muted); cursor: pointer;
  font-size: 1.1rem; line-height: 1; padding: 0 0.2rem; opacity: 0; flex-shrink: 0;
}
.lang-row:hover .lang-remove { opacity: 1; }
.lang-remove:hover { color: var(--danger); }
.lang-add {
  flex-shrink: 0; white-space: nowrap; background: none;
  border: 1px dashed var(--border); color: var(--muted); border-radius: 999px;
  padding: 0.28rem 0.7rem; cursor: pointer; font: inherit; font-size: 0.82rem;
}
.lang-add:hover { border-color: var(--accent); color: var(--text); }

/* Language picker modal */
.lang-picker { width: 100%; }
.lang-picker-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  max-height: 50vh;
  overflow-y: auto;
  margin: 0.6rem 0;
}
.lang-picker-list > p { grid-column: 1 / -1; }
.lang-picker-item {
  display: flex; justify-content: space-between; align-items: center; gap: 0.4rem;
  width: 100%; box-sizing: border-box; text-align: left; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 0.45rem 0.6rem; cursor: pointer; color: var(--text); font: inherit; font-size: 0.9rem;
}
.lang-picker-item:hover { border-color: var(--accent); color: var(--accent); }
.lang-picker-custom {
  display: block; background: none; border: none; color: var(--accent);
  cursor: pointer; font: inherit; padding: 0.4rem 0;
}
@media (max-width: 480px) { .lang-picker-list { grid-template-columns: 1fr; } }

/* LINE Login button + "or" divider in the auth modal */
.auth-divider {
  display: flex; align-items: center; gap: 0.6rem;
  color: var(--muted); font-size: 0.8rem; margin: 1rem 0 0.75rem;
}
.auth-divider::before, .auth-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.line-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  background: #06c755; border-color: #06c755; color: #fff; font-weight: 600;
}
.line-btn:hover { background: #05b34c; border-color: #05b34c; }
.line-btn .line-badge {
  font-weight: 800; font-size: 0.72rem; letter-spacing: 0.02em;
  background: #fff; color: #06c755; border-radius: 4px; padding: 0.05rem 0.28rem;
}

/* Top-bar character avatar (replaces the username link) */
.me-avatar {
  display: inline-flex;
  width: 34px; height: 34px;
  border-radius: 50%; overflow: hidden;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.me-avatar:hover { border-color: var(--accent); }
.me-avatar canvas, .me-avatar .avatar { display: block; width: 100%; height: 100%; }
/* Native-language setting on the profile page */
.prof-setting { margin: 0.9rem 0; }
.prof-setting .native-picker { display: inline-flex; align-items: center; gap: 0.5rem; }

/* Progress: note shown when a language has no frequency data */
.coverage-note {
  margin-top: 1rem; padding: 0.75rem 1rem;
  background: var(--surface-2); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: 8px;
  font-size: 0.9rem;
}

/* Tips read as a comfortable column, not the full page width. */
.tips-list { max-width: 760px; }

/* Compact progress strip shown above the tips. */
.tips-progress {
  display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap;
  max-width: 760px; margin: 0.25rem 0 1rem;
  padding: 0.6rem 1rem; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface); color: var(--text);
  font-size: 0.9rem;
}
.tips-progress:hover { border-color: var(--accent); text-decoration: none; }
.tips-progress .tips-progress-link { margin-left: auto; color: var(--accent); font-weight: 600; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }

.view { padding: 1.5rem 2rem; }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 0.5rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--border); }
.tabs a {
  padding: 0.5rem 0.9rem;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* ---- Word elements (the clickable, language-tagged words) ---- */
.w {
  cursor: pointer;
  border-radius: 3px;
  /* Tight horizontal padding + a matching negative margin so the familiarity
     box still hugs the word without widening the space between words. */
  padding: 0.04em 0.12em;
  margin: 0 -0.1em;
  background: var(--seen-bg, transparent); /* red→green familiarity (set by seen.js) */
  transition: background 0.08s, color 0.08s;
}
.w:hover {
  background: var(--surface-2);
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.reader-prose { font-size: 1.15rem; line-height: 2; }
.tip-body { margin-top: 0.25rem; }
.tip-body .article-p:last-child, .tip-body .article-ul:last-child { margin-bottom: 0; }

.word-detail .lang-tag { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; }
.word-detail .headword { margin: 0.15rem 0 0.5rem; font-size: 2rem; }
.word-detail .meaning { margin: 0.5rem 0 1rem; font-size: 1.1rem; }
.definitions { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem; }
.definition { display: flex; gap: 0.6rem; align-items: flex-start; }
.def-body { flex: 1; min-width: 0; }
.def-text { font-size: 1.05rem; line-height: 1.5; }
.def-meta { font-size: 0.72rem; margin-top: 0.15rem; display: flex; gap: 0.4rem; align-items: center; }
.def-accepted { color: var(--accent-2); font-weight: 600; }
.vote-btn { display: inline-flex; flex-direction: column; align-items: center; line-height: 1; gap: 0.1rem; min-width: 34px; padding: 0.2rem 0.3rem; }
.vote-btn .vote-arrow { font-size: 0.7rem; }
.links-title { margin-top: 1.5rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.links { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.5rem; }
.link-row { display: flex; align-items: baseline; gap: 0.6rem; }
.link-type {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 4px; padding: 0.05rem 0.4rem;
}
.link-row .w { font-size: 1.1rem; }
.lang-mini { color: var(--muted); font-size: 0.75rem; }

/* ---- Cards / tips ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin-bottom: 0.9rem;
}
.card h3 { margin: 0 0 0.35rem; }
.card .meta { color: var(--muted); font-size: 0.8rem; }

/* Article cards grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.9rem;
}
.article-card {
  display: block;
  color: var(--text);
  transition: border-color 0.1s, transform 0.1s;
}
.article-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-2px); }
.article-card h3 { margin: 0.5rem 0 0.35rem; }
.card-summary { font-size: 0.9rem; margin: 0; }
.badge {
  display: inline-block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.badge.official { background: var(--accent); color: #fff; border-color: var(--accent); }
.badge.user { color: var(--muted); }
.badge.lang { color: var(--muted); font-family: ui-monospace, monospace; }
.card-badges { display: flex; gap: 0.35rem; align-items: center; flex-wrap: wrap; }

/* ---- Article page ---- */
.article { max-width: 720px; }
.article .back { display: inline-block; margin-bottom: 0.75rem; }
.article h1 { margin: 0.25rem 0 0.35rem; }
.article-meta { color: var(--muted); font-size: 0.85rem; margin-bottom: 1.25rem; }
.article-body { font-size: 1.05rem; line-height: 1.75; }
.article-h { margin: 1.75rem 0 0.6rem; font-size: 1.3rem; }
.article-p { margin: 0 0 1rem; }
.article-ul { margin: 0 0 1rem; padding-left: 1.25rem; }
.article-ul li { margin: 0.2rem 0; }
.article-ol { margin: 0 0 1rem; padding-left: 1.4rem; }
.article-ol li { margin: 0.2rem 0; }

/* "Make a flashcard deck" control shown under each list. */
.list-deck-bar {
  margin: -0.4rem 0 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.list-deck-btn { white-space: nowrap; }
.list-deck-status { font-size: 0.85rem; color: var(--muted); }
.list-deck-status.ok { color: var(--accent-2); }
.list-deck-status.err { color: var(--danger); }
.list-deck-link { font-weight: 600; white-space: nowrap; }

/* [gender-nouns] preview list */
.gender-noun-list { column-count: 2; column-gap: 1.5rem; margin-bottom: 0.4rem; }
.gender-noun-list li { break-inside: avoid; }
@media (max-width: 680px) { .gender-noun-list { column-count: 1; } }

/* ---- Coverage widget ---- */
.coverage {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin: 1.25rem 0;
}
.coverage-title { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.6rem; }
.coverage-btns { display: flex; gap: 0.4rem; margin-bottom: 0.85rem; }
.coverage-btns .btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.coverage-stat { font-size: 1.05rem; margin: 0 0 0.6rem; }
.coverage-stat strong { color: var(--accent-2); font-size: 1.15rem; }
.coverage-words {
  max-height: 220px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  font-size: 0.95rem;
  line-height: 1.9;
  margin: 0;
}

/* ---- Gender-stats widget ---- */
.stats-block { margin-top: 0.5rem; }
.bars { display: flex; flex-direction: column; gap: 0.3rem; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 52px; align-items: center; gap: 0.5rem; font-size: 0.9rem; }
.bar-label { color: var(--muted); }
.bar { background: var(--bg); border-radius: 4px; height: 14px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; }
.g-acc { color: var(--accent-2); }

.ending-table { width: 100%; border-collapse: collapse; margin-top: 0.75rem; font-size: 0.9rem; }
.ending-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 0.3rem 0.5rem; border-bottom: 1px solid var(--border); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.ending-table td { padding: 0.3rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.ending-table .mono { font-family: ui-monospace, monospace; }
.gtag { display: inline-block; padding: 0.05rem 0.4rem; border-radius: 4px; font-weight: 600; font-size: 0.82rem; }
.g-m { background: rgba(108,140,255,0.18); color: #9db2ff; }
.g-f { background: rgba(255,107,107,0.16); color: #ff9b9b; }
.g-n { background: rgba(74,214,160,0.16); color: #7fe3bf; }
.exc-bar { display: inline-block; width: 60px; height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; vertical-align: middle; margin-right: 0.4rem; }
.exc-fill { display: block; height: 100%; background: var(--danger); }
.exc-val { font-variant-numeric: tabular-nums; }

/* ---- Upvotes ---- */
.card-top { display: flex; align-items: center; justify-content: space-between; }
.vote-btn {
  display: inline-flex; align-items: center; gap: 0.25rem;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--muted); border-radius: 999px; padding: 0.12rem 0.55rem;
  cursor: pointer; font: inherit; font-size: 0.82rem;
}
.vote-btn:hover { border-color: var(--accent); color: var(--text); }
.vote-btn.voted { background: var(--accent); border-color: var(--accent); color: #fff; }
.vote-arrow { font-size: 0.7rem; }
.article-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.article-head .vote-btn { font-size: 0.95rem; padding: 0.3rem 0.8rem; }

/* ---- Settings ---- */
.settings-section { border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1rem; max-width: 620px; }
.settings-title { margin: 0 0 0.75rem; font-size: 1.05rem; }
.settings-field { margin-bottom: 0.75rem; }
.settings-field > label { display: block; margin-bottom: 0.25rem; font-size: 0.85rem; color: var(--muted); }
.ok-msg { color: var(--accent-2); font-size: 0.9rem; min-height: 1.1em; margin-top: 0.4rem; }
.prof-place { font-size: 0.9rem; margin: 0.25rem 0 0.5rem; }

/* ---- World (embedded STRANDED) ---- */
.world-bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.world-frame {
  width: 100%; height: calc(100vh - 210px); min-height: 420px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); display: block;
}

/* ---- Deck marker: word is in a study deck ---- */
.w.in-deck { box-shadow: inset 0 -2px 0 var(--accent); }

/* ---- Flashcards ---- */
.deck-card .card-top { align-items: center; }
.study-stage { display: flex; justify-content: center; margin-top: 1.5rem; }
.flash-card {
  width: min(460px, 92vw); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 2rem 1.5rem; text-align: center;
}
.flash-count { font-size: 0.8rem; margin-bottom: 1rem; }
.flash-front { font-size: 1.9rem; font-weight: 600; margin-bottom: 1rem; }
.flash-back { font-size: 1.3rem; color: var(--accent-2); margin-bottom: 1.5rem; }
.rate-row { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }
.study-done { text-align: center; margin-top: 2rem; }
.study-done h2 { margin-bottom: 0.5rem; }

/* ---- Seen / familiarity legend ---- */
.seen-legend { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; color: var(--muted); }
.seen-gradient {
  flex: 1; height: 10px; border-radius: 999px; max-width: 240px;
  background: linear-gradient(90deg, hsl(0 65% 55%), hsl(60 65% 50%), hsl(120 65% 45%));
}

/* ---- Character avatars ---- */
.char-avatar {
  image-rendering: pixelated;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.char-preview {
  image-rendering: pixelated;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.char-creator { width: 100%; }
.char-body { display: flex; gap: 1.1rem; align-items: center; margin: 1rem 0; flex-wrap: wrap; }
.char-preview-wrap { flex-shrink: 0; }
.char-controls { flex: 1; min-width: 190px; display: flex; flex-direction: column; gap: 0.4rem; }
.char-row { display: flex; align-items: center; gap: 0.5rem; }
.char-arrow {
  width: 34px; height: 34px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); cursor: pointer; font-size: 1.2rem; line-height: 1;
}
.char-arrow:hover { border-color: var(--accent); }
.char-label { flex: 1; text-align: center; text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.06em; color: var(--muted); }

/* ---- Profile ---- */
.profile { max-width: 620px; }
.profile-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.25rem; }
.avatar {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center; font-size: 1.1rem; flex-shrink: 0;
}
/* Personal-photo avatar (a separate thing from the World pixel character). */
.avatar-photo { border-radius: 50%; object-fit: cover; background: var(--surface-2); flex-shrink: 0; }
.prof-langs { display: flex; gap: 0.6rem; align-items: baseline; margin: 0.5rem 0; }
.prof-langs-label { color: var(--muted); font-size: 0.85rem; width: 80px; flex-shrink: 0; }
.lang-pill, .tag-chip {
  display: inline-block; margin: 0 0.3rem 0.3rem 0; padding: 0.15rem 0.55rem;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; font-size: 0.85rem;
}
.prof-bio { margin: 1rem 0; line-height: 1.6; white-space: pre-wrap; }
/* Learning-languages manager on the profile */
.learn-pills { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.4rem 0 0.6rem; }
.lang-pill.removable { display: inline-flex; align-items: center; gap: 0.25rem; margin: 0; }
.lang-pill-x {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 1rem; line-height: 1; padding: 0;
}
.lang-pill-x:hover { color: var(--danger); }
.lang-picker { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; padding: 0.5rem 0; }
.lang-check { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.9rem; color: var(--text); margin: 0; }
.lang-check input { width: auto; }

/* ---- Progress ---- */
.stat-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; margin-top: 0.5rem; }
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.15rem; text-align: center; }
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--accent-2); }
.stat-label { color: var(--muted); font-size: 0.85rem; }

.coverage-meter { position: relative; height: 22px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; margin-top: 0.5rem; overflow: visible; }
.coverage-meter-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; }
.milestone { position: absolute; top: -4px; height: 30px; width: 2px; background: var(--border); }
.milestone.reached { background: var(--accent-2); }
.milestone-label { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: 0.68rem; color: var(--muted); }

.progress-controls .btn.active { background: var(--accent-2); border-color: var(--accent-2); color: #04160f; }

/* ---- Chat ---- */
.chat-list {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0.75rem 0.9rem;
  height: 55vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.study-all-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.6rem 1rem; margin-bottom: 0.9rem;
  background: var(--surface); border: 1px solid var(--accent);
  border-radius: 10px; font-size: 0.92rem;
}
.chat-empty { text-align: center; padding: 2rem 1rem; margin: auto 0; }
.chat-empty-emoji { font-size: 2.5rem; margin-bottom: 0.5rem; }
.chat-empty p { margin: 0.25rem 0; }
.chat-msg { max-width: 85%; display: flex; gap: 0.5rem; align-items: flex-start; }
.chat-msg-main { min-width: 0; }
.chat-avatar-link { flex-shrink: 0; line-height: 0; }
.chat-avatar-link:hover { text-decoration: none; }
.chat-meta { display: flex; gap: 0.5rem; align-items: baseline; margin-bottom: 0.1rem; }
.chat-author { font-weight: 600; font-size: 0.85rem; }
.chat-lang { color: var(--muted); font-size: 0.72rem; font-family: ui-monospace, monospace; }
.chat-body {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px 12px 12px 12px;
  padding: 0.4rem 0.7rem;
  line-height: 1.7;
  white-space: pre-wrap;
}
.chat-form { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
.chat-form input[type="text"] { flex: 1; }
.chat-lang-select { width: auto; }
.chat-room-select { width: auto; }
.chat-msg.mine { align-self: flex-end; text-align: right; flex-direction: row-reverse; }
.chat-msg.mine .chat-body { border-radius: 12px 4px 12px 12px; background: var(--accent); color: #fff; }
.chat-msg.mine .chat-meta { justify-content: flex-end; }

/* ---- Conversations ---- */
.convo { display: block; }
.convo-top { display: flex; align-items: center; gap: 0.5rem; }
.convo-preview { margin-top: 0.3rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dm-head { margin-bottom: 0.75rem; }

/* ---- Message actions, gloss, corrections ---- */
.msg-actions { display: flex; gap: 0.75rem; margin-top: 0.2rem; }
.msg-actions .btn.link { font-size: 0.78rem; }
.gloss { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.35rem; }
.gloss-pair { font-size: 0.85rem; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 0.1rem 0.4rem; }
.gloss-src { color: var(--muted); }
.gloss-tr { color: var(--accent-2); margin-left: 0.2rem; }
.ai-translation { display: flex; align-items: baseline; gap: 0.5rem; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 0.35rem 0.6rem; font-size: 0.95rem; }
.ai-badge { font-size: 0.62rem; font-weight: 700; letter-spacing: 0.05em; background: var(--accent-2); color: #04160f; border-radius: 4px; padding: 0.05rem 0.3rem; }
.corrections { margin-top: 0.4rem; }
.correction { background: rgba(74,214,160,0.08); border-left: 3px solid var(--accent-2); border-radius: 4px; padding: 0.35rem 0.6rem; margin-top: 0.3rem; text-align: left; }
.correction-mark { color: var(--accent-2); margin-right: 0.3rem; }
.correction-note { font-size: 0.82rem; margin-top: 0.2rem; }
.correction-by { font-size: 0.72rem; margin-top: 0.15rem; }
.correct-form { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem; margin-top: 0.4rem; display: flex; flex-direction: column; gap: 0.4rem; text-align: left; }

/* ---- Forms & buttons ---- */
input, textarea, select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
}
textarea { min-height: 90px; resize: vertical; }
label { display: block; margin: 0.75rem 0 0.25rem; font-size: 0.85rem; color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.secondary { background: transparent; color: var(--text); border-color: var(--border); }
.btn.small { padding: 0.3rem 0.6rem; font-size: 0.85rem; }
.btn.link { background: none; border: none; color: var(--accent); padding: 0; }

.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 0.9rem; margin-top: 0.5rem; min-height: 1.2em; }
.row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: min(420px, 92vw);
}
.modal h2 { margin-top: 0; }
.modal .close { float: right; }

@media (max-width: 680px) {
  .view { padding: 1rem; }
  .lang-bar { padding: 0.4rem 1rem; }
}

/* Header reflows on narrow screens: brand+search+auth on top, nav below. */
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; gap: 0.5rem 0.75rem; padding: 0.6rem 0.9rem; }
  .search-form { order: 2; flex: 1 1 120px; margin: 0; }
  .auth-area { order: 3; margin-left: auto; }
  .topnav {
    order: 4; flex-basis: 100%; margin-left: 0; gap: 1.1rem;
    overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch;
    padding-bottom: 0.15rem;
  }
  .native-picker .who { display: none; }
}
/* Wide content (tables, word clouds) scrolls inside itself, never the page. */
.ending-table, .bars { overflow-x: auto; }
