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

/* ── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1117;
  --bg2:       #1a1d27;
  --bg3:       #23263a;
  --border:    #2e3250;
  --accent:    #7b8cde;
  --accent2:   #b48cde;
  --text:      #e0e4f0;
  --muted:     #6b7094;
  --new:       #e07b5a;
  --learning:  #e0c45a;
  --known:     #5ae07b;
  --highlight: #c084fc;
}

[data-theme="light"] {
  --bg:        #dce7e3;
  --bg2:       #e8f1ed;
  --bg3:       #cfdbd6;
  --border:    #a8bcb4;
  --accent:    #a84030;
  --accent2:   #3e5e4a;
  --text:      #18110a;
  --muted:     #4a6460;
  --new:       #a83828;
  --learning:  #906a18;
  --known:     #386040;
  --highlight: #784858;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Header ───────────────────────────────────────────────────── */
header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 50px;
  flex-shrink: 0;
}

header h1 { font-size: 1rem; font-weight: 700; color: var(--accent); letter-spacing: .5px; white-space: nowrap; }
.subtitle  { color: var(--muted); font-size: .82rem; white-space: nowrap; }
#dict-status { margin-left: auto; font-size: .78rem; color: var(--muted); white-space: nowrap; }

.toggle-row { display: flex; align-items: center; gap: 6px; font-size: .83rem; color: var(--muted); cursor: pointer; white-space: nowrap; }
.toggle-row input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

#theme-toggle {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 4px 11px;
  font-size: .78rem;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
#theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* ── Main navigation ──────────────────────────────────────────── */
.main-nav {
  display: flex;
  gap: 2px;
  margin: 0 6px;
}

.nav-btn {
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--muted);
  padding: 5px 12px;
  font-size: .87rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.nav-btn:hover  { color: var(--text); background: var(--bg3); }
.nav-btn.active { color: var(--accent); background: rgba(123,140,222,.12); }

/* ── Nav dropdown ─────────────────────────────────────────────── */
.nav-dropdown { position: relative; display: inline-flex; }

.nav-dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  min-width: 152px;
  z-index: 200;
  box-shadow: 0 4px 16px rgba(0,0,0,.35);
}

.nav-dropdown-item {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--muted);
  padding: 7px 12px;
  font-size: .85rem;
  cursor: pointer;
  border-radius: 5px;
  text-align: left;
  transition: background .12s, color .12s;
}
.nav-dropdown-item:hover { background: var(--bg3); color: var(--text); }


/* ── Views ────────────────────────────────────────────────────── */
.view {
  height: calc(100vh - 50px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Game view layout (sidebar + content) ─────────────────────── */
.game-view {
  flex-direction: row !important;
}

.char-sidebar {
  width: 200px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.char-sidebar-header {
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 14px 14px 8px;
  flex-shrink: 0;
}

.char-sidebar-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
}

.char-sidebar-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  border-left: 2px solid transparent;
  color: var(--muted);
  padding: 9px 10px 9px 12px;
  font-size: .87rem;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  transition: color .15s, border-color .15s, background .15s;
}
.char-sidebar-item:hover { color: var(--text); background: var(--bg3); }
.char-sidebar-item.active { color: var(--accent); border-left-color: var(--accent); background: rgba(123,140,222,.08); }

.char-sidebar-name { flex: 1; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }

.char-sidebar-close {
  font-size: .8rem;
  color: var(--muted);
  opacity: 0;
  border-radius: 3px;
  padding: 1px 4px;
  line-height: 1;
  flex-shrink: 0;
  transition: opacity .12s, color .12s;
}
.char-sidebar-item:hover .char-sidebar-close { opacity: 1; }
.char-sidebar-close:hover { color: var(--new) !important; }

.add-char-sidebar-btn {
  display: block;
  width: calc(100% - 20px);
  margin: 4px 10px 8px;
  background: none;
  border: 1px dashed var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: .8rem;
  cursor: pointer;
  text-align: left;
  transition: all .15s;
}
.add-char-sidebar-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Character content area ───────────────────────────────────── */
.char-main {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 80px;
}

.no-chars {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 8px;
  color: var(--muted);
  text-align: center;
}
.no-chars p { font-size: .95rem; }
.no-chars strong { color: var(--text); }

/* ── Character page header ────────────────────────────────────── */
.char-page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.char-page-name {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid transparent;
  padding: 2px 4px;
  border-radius: 4px;
  outline: none;
  transition: border-color .15s;
}
.char-page-name:focus { border-bottom-color: var(--accent); }
.char-page-name:hover:not(:focus) { border-bottom-color: var(--border); }

/* ── Fields grid ──────────────────────────────────────────────── */
.fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 900px) { .fields-grid { grid-template-columns: 1fr; } }

.add-field-btn {
  margin-top: 14px;
  background: none;
  border: 1px dashed var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 8px 18px;
  font-size: .83rem;
  cursor: pointer;
  transition: all .15s;
}
.add-field-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Skill field ──────────────────────────────────────────────── */
.skill-field {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color .15s;
}
.skill-field:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }

.field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.field-label {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  outline: none;
  border-bottom: 1px solid transparent;
  padding: 1px 3px;
  border-radius: 3px;
  cursor: text;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: border-color .15s, color .15s;
}
.field-label:focus { border-bottom-color: var(--accent); color: var(--text); white-space: normal; }
.field-label:hover:not(:focus) { border-bottom-color: var(--border); }

.field-actions { display: flex; gap: 4px; flex-shrink: 0; }

.field-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--muted);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: .75rem;
  cursor: pointer;
  transition: all .12s;
  opacity: 0;
}
.skill-field:hover .field-btn { opacity: 1; }
.field-btn:hover { border-color: var(--border); color: var(--text); }
.field-del:hover { border-color: var(--new) !important; color: var(--new) !important; }

/* ── Field subtitle ───────────────────────────────────────────── */
.field-subtitle {
  padding: 5px 12px 4px;
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
  outline: none;
  border-bottom: 1px solid transparent;
  transition: border-color .15s, color .15s;
  cursor: text;
  min-height: 1.5em;
}
.field-subtitle:hover { border-bottom-color: var(--border); }
.field-subtitle:focus { border-bottom-color: var(--accent); }
.field-subtitle.empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  font-weight: 400;
  font-size: .82rem;
  pointer-events: none;
}
.field-subtitle.empty { color: transparent; min-height: 1.6em; }
.field-subtitle.empty:focus { color: var(--text); }
.field-subtitle.empty:focus::before { display: none; }

/* ── Field body ───────────────────────────────────────────────── */
.field-body { padding: 12px; }
.field-body.editing { padding: 10px; }

.field-textarea {
  width: 100%;
  min-height: 90px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: .95rem;
  padding: 8px 10px;
  resize: vertical;
  font-family: inherit;
  line-height: 1.7;
}
.field-textarea:focus { outline: none; border-color: var(--accent); }
.field-textarea::placeholder { color: var(--muted); }

.field-editor-btns { display: flex; gap: 6px; margin-top: 7px; flex-direction: row-reverse; }

/* ── Buttons ──────────────────────────────────────────────────── */
button.primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: 7px 18px;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
button.primary:hover { opacity: .85; }

button.secondary {
  background: var(--bg3);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 14px;
  font-size: .88rem;
  cursor: pointer;
  transition: all .15s;
}
button.secondary:hover { border-color: var(--accent); color: var(--accent); }

button.primary.small   { padding: 5px 12px; font-size: .8rem; border-radius: 5px; }
button.secondary.small { padding: 5px 10px; font-size: .8rem; border-radius: 5px; }

/* ── Rendered text ────────────────────────────────────────────── */
.output-text {
  font-size: 1.15rem;
  line-height: 1.8;
  letter-spacing: .02em;
  white-space: pre-wrap;
  word-break: break-word;
}
.output-text ruby rt { display: none; }
body.pinyin-visible .output-text { line-height: 3; }
body.pinyin-visible .output-text ruby rt { display: revert; }

ruby { display: inline-ruby; position: relative; cursor: pointer; border-radius: 4px; padding: 0 1px; transition: background .12s; }
ruby rt { font-size: .52em; color: var(--accent2); text-align: center; line-height: 1.1; }
ruby:hover { background: var(--bg3); }
ruby.known-dict:hover { background: rgba(123,140,222,.15); }
ruby.unknown-dict { opacity: .65; }

ruby.vocab-saved    { background: rgba(123,140,222,.13); }
ruby.vocab-new      { background: rgba(224,123,90,.28); }
ruby.vocab-learning { background: rgba(224,196,90,.28); }
ruby.vocab-known    { background: rgba(90,224,123,.22); }

ruby.vocab-new rt      { color: var(--new); }
ruby.vocab-learning rt { color: var(--learning); }
ruby.vocab-known rt    { color: var(--known); }

ruby.glossary-highlight { background: rgba(192,132,252,.3) !important; }
.non-cjk { color: var(--muted); font-size: .88rem; }

/* ── Ability-ref token ────────────────────────────────────────── */
ruby.ability-ref { border-bottom: 2px solid var(--accent2); cursor: pointer; }
ruby.ability-ref:hover { background: rgba(180,140,222,.18); }
ruby.ability-ref rt { color: var(--accent2); }

/* ── Ability descriptions section ─────────────────────────────── */
.abilities-divider {
  margin: 28px 0 14px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
}
.abilities-divider::before, .abilities-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

.ability-field { border-color: color-mix(in srgb, var(--accent2) 40%, var(--border)); }
.ability-field .field-header { background: color-mix(in srgb, var(--accent2) 8%, var(--bg3)); }

.ability-title {
  padding: 8px 12px 6px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  outline: none;
  border-bottom: 1px solid transparent;
  transition: border-color .15s;
  cursor: text;
  min-height: 2em;
}
.ability-title:hover { border-bottom-color: var(--border); }
.ability-title:focus { border-bottom-color: var(--accent2); }
.ability-title.empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  font-weight: 400;
  font-size: .88rem;
  pointer-events: none;
}
.ability-title.empty { color: transparent; }
.ability-title.empty:focus { color: var(--text); }
.ability-title.empty:focus::before { display: none; }

/* ── Popup (fixed) ────────────────────────────────────────────── */
#popup {
  display: none;
  position: fixed;
  z-index: 1000;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  width: 300px;
  box-shadow: 0 8px 32px rgba(0,0,0,.45);
}

.popup-word   { font-size: 2rem; font-weight: 700; color: var(--text); }
.popup-trad   { font-size: 1.5rem; font-weight: 400; color: var(--muted); }
.popup-pinyin { font-size: .95rem; color: var(--accent2); margin-bottom: 6px; }
.popup-defs   { font-size: .85rem; color: var(--text); padding-left: 16px; }
.popup-defs li { margin-bottom: 3px; }

.popup-divider { border: none; border-top: 1px solid var(--border); margin: 10px 0 8px; }

.popup-in-glossary {
  font-size: .8rem; color: var(--muted); display: flex; align-items: center; gap: 4px;
}
.pig-check { color: var(--known); font-size: .95rem; }

.popup-remove-word {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--muted);
  font-size: .75rem;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  transition: color .12s;
}
.popup-remove-word:hover { color: var(--new); }

.popup-add-glossary { font-size: .82rem; }
.pag-toggle {
  background: none; border: 1px dashed var(--border); color: var(--muted);
  border-radius: 5px; padding: 4px 10px; font-size: .78rem; cursor: pointer; width: 100%;
  transition: all .12s;
}
.pag-toggle:hover { border-color: var(--accent); color: var(--accent); }
.pag-form { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.pag-form input, .pag-form select {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 5px; color: var(--text); padding: 5px 8px; font-size: .8rem; font-family: inherit;
}
.pag-form input:focus, .pag-form select:focus { outline: none; border-color: var(--accent); }
.pag-form select option { background: var(--bg2); }
.pag-bottom { display: flex; gap: 6px; align-items: center; }
.pag-bottom select { flex: 1; }
.pag-submit {
  background: var(--accent); border: none; color: #fff; border-radius: 5px;
  padding: 5px 12px; font-size: .78rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.pag-submit:hover { opacity: .85; }

.vocab-btns { margin-top: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.vocab-btn {
  border: 1px solid var(--border); background: var(--bg3); color: var(--muted);
  border-radius: 5px; padding: 4px 10px; font-size: .78rem; cursor: pointer; transition: all .12s;
}
.vocab-btn:hover { border-color: var(--accent); color: var(--accent); }
.vocab-btn.active[data-status="new"]      { background: rgba(224,123,90,.25); border-color: var(--new);      color: var(--new); }
.vocab-btn.active[data-status="learning"] { background: rgba(224,196,90,.25); border-color: var(--learning); color: var(--learning); }
.vocab-btn.active[data-status="known"]    { background: rgba(90,224,123,.2);  border-color: var(--known);    color: var(--known); }
.vocab-clear { border-color: transparent; color: var(--muted); }

/* ── Ability popup ────────────────────────────────────────────── */
#ability-popup {
  display: none;
  position: fixed;
  z-index: 950;
  top: 50%;
  left: calc(50% - 160px);
  transform: translate(-50%, -50%);
  width: 520px;
  max-width: calc(100vw - 360px);
  max-height: 70vh;
  background: var(--bg2);
  border: 1px solid var(--accent2);
  border-radius: 12px;
  box-shadow: 0 12px 48px rgba(0,0,0,.5);
  flex-direction: column;
  overflow: hidden;
}

.ap-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--accent2) 10%, var(--bg3));
  border-bottom: 1px solid color-mix(in srgb, var(--accent2) 30%, var(--border));
  flex-shrink: 0;
}
.ap-title-wrap { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.ap-label {
  font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
  color: var(--accent2); flex-shrink: 0;
}
.ap-title {
  font-size: 1.1rem; font-weight: 700; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ap-close {
  background: none; border: none; color: var(--muted); font-size: 1.1rem; cursor: pointer;
  padding: 2px 6px; border-radius: 4px; flex-shrink: 0; transition: color .12s;
}
.ap-close:hover { color: var(--text); }
.ap-body { padding: 14px 16px; overflow-y: auto; flex: 1; }
.ap-body .output-text { font-size: 1.1rem; }

/* ── Modal ────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  z-index: 2000; display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 12px;
  padding: 24px; width: 340px; display: flex; flex-direction: column; gap: 16px;
  box-shadow: 0 16px 48px rgba(0,0,0,.5);
}
.modal-box h3 { font-size: 1rem; font-weight: 700; color: var(--text); }
.modal-field { display: flex; flex-direction: column; gap: 5px; }
.modal-field label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.modal-field input, .modal-field select {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 7px;
  color: var(--text); padding: 8px 10px; font-size: .9rem; font-family: inherit;
}
.modal-field input:focus, .modal-field select:focus { outline: none; border-color: var(--accent); }
.modal-field select option { background: var(--bg2); }
.modal-btns { display: flex; gap: 8px; justify-content: flex-end; }
#nc-cancel {
  background: var(--bg3); border: 1px solid var(--border); color: var(--muted);
  border-radius: 7px; padding: 7px 16px; font-size: .88rem; cursor: pointer; transition: all .15s;
}
#nc-cancel:hover { border-color: var(--accent); color: var(--accent); }

/* ── Game tags (shared) ───────────────────────────────────────── */
.gr-tag {
  font-size: .65rem; padding: 2px 5px; border-radius: 4px; font-weight: 600; white-space: nowrap;
}
.tag-general { background: rgba(107,112,148,.25); color: var(--muted); }
.tag-genshin { background: rgba(58,123,213,.2);   color: #6ba8f5; }
.tag-r1999   { background: rgba(124,58,237,.2);   color: #b48cde; }
.tag-song    { background: rgba(236,72,153,.18);   color: #f472b6; }
.tag-story   { background: rgba(20,184,166,.18);   color: #2dd4bf; }

/* ── Text tab (Songs / Story) ─────────────────────────────────── */
.text-tab-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px 80px;
  max-width: 860px;
  width: 100%;
}

.text-tab-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  outline: none;
  border-bottom: 2px solid transparent;
  padding: 2px 4px;
  border-radius: 4px;
  margin-bottom: 18px;
  display: block;
  transition: border-color .15s;
}
.text-tab-title:focus { border-bottom-color: var(--accent); }
.text-tab-title:hover:not(:focus) { border-bottom-color: var(--border); }
.text-tab-title.empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  font-weight: 400;
  font-size: 1rem;
  pointer-events: none;
}
.text-tab-title.empty { color: transparent; }
.text-tab-title.empty:focus { color: var(--text); }
.text-tab-title.empty:focus::before { display: none; }

.yt-section { margin-bottom: 20px; }

.yt-embed-wrap {
  position: relative;
  width: 100%;
  max-width: 700px;
  aspect-ratio: 16 / 9;
  margin-bottom: 10px;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
}

.yt-embed-poster {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: #000 center/cover no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
}

.yt-embed-poster::after {
  content: '▶';
  font-size: 52px;
  color: rgba(255,255,255,0.9);
  text-shadow: 0 2px 12px rgba(0,0,0,0.7);
  pointer-events: none;
}

/* Floating video player */
#video-float {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 320px;
  height: 214px;
  min-width: 180px;
  min-height: 130px;
  background: #000;
  border-radius: 8px;
  box-shadow: 0 6px 32px rgba(0,0,0,0.55);
  z-index: 500;
  display: flex;
  flex-direction: column;
}

#video-float-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  height: 34px;
  flex-shrink: 0;
  background: rgba(30,30,30,0.95);
  border-radius: 8px 8px 0 0;
  cursor: grab;
  user-select: none;
}

#video-float-bar:active { cursor: grabbing; }

#video-float-label {
  font-size: 12px;
  color: #aaa;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#video-float-close {
  background: none;
  border: none;
  color: #ccc;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  flex-shrink: 0;
}

#video-float-close:hover { color: #fff; }

#video-float-frame {
  flex: 1;
  overflow: hidden;
}

#video-float-frame iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

#video-float-controls {
  flex-shrink: 0;
  background: rgba(18,18,18,0.97);
  padding: 5px 8px 6px;
  border-radius: 0 0 8px 8px;
  display: none;
  flex-direction: column;
  gap: 4px;
}

.vfc-progress-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.vfc-time {
  font-size: 10px;
  color: #999;
  white-space: nowrap;
  min-width: 80px;
}

.vfc-seek {
  flex: 1;
  height: 3px;
  cursor: pointer;
  accent-color: #fff;
}

.vfc-btn-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.vfc-btn {
  background: none;
  border: none;
  color: #ddd;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 4px;
  line-height: 1;
}

.vfc-btn:hover { background: rgba(255,255,255,0.12); color: #fff; }

.vfc-vol {
  flex: 1;
  height: 3px;
  cursor: pointer;
  accent-color: #fff;
  margin-left: 4px;
}

#video-float-resize {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 18px;
  height: 18px;
  cursor: se-resize;
  background: linear-gradient(135deg, transparent 40%, rgba(255,255,255,0.25) 40%);
  border-radius: 0 0 8px 0;
}

.yt-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  max-width: 700px;
}

.yt-input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 10px;
  font-size: .85rem;
  font-family: inherit;
}
.yt-input:focus { outline: none; border-color: var(--accent); }
.yt-input::placeholder { color: var(--muted); }

.text-tab-field { margin-top: 4px; }
.text-tab-field .field-label { font-size: .75rem; }

.text-tab-textarea { min-height: 240px; }

/* ── Flashcard context sentence ───────────────────────────────── */
.fc-context {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-top: 6px;
  max-width: 100%;
  word-break: break-word;
}

.fc-context .output-text {
  font-size: 1.25rem;
  color: var(--text);
  line-height: 1.8;
}

ruby.fc-focus-word { color: var(--accent); font-weight: 700; }

/* ── Light-mode tag overrides ─────────────────────────────────── */
[data-theme="light"] .tag-song  { background: rgba(219,39,119,.12); color: #be185d; }
[data-theme="light"] .tag-story { background: rgba(13,148,136,.12); color: #0f766e; }

/* ── Song/Story filter button active states ───────────────────── */
.game-filter-btn.tag-song.active  { background: #db2777; border-color: #db2777; }
.game-filter-btn.tag-story.active { background: #0d9488; border-color: #0d9488; }

/* ── Vocabulary view ──────────────────────────────────────────── */
.vocab-sub-nav {
  display: flex;
  align-items: center;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  gap: 2px;
  flex-shrink: 0;
}

.vocab-tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 11px 14px;
  font-size: .87rem;
  cursor: pointer;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}
.vocab-tab-btn:hover { color: var(--text); }
.vocab-tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.fc-due-badge {
  background: var(--new); color: #fff; border-radius: 10px;
  font-size: .68rem; font-weight: 700; padding: 2px 7px;
  margin-left: 4px; display: inline-flex; align-items: center;
}

/* ── Word list ────────────────────────────────────────────────── */
#vtab-wordlist {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.wl-toolbar {
  padding: 10px 16px 0;
  flex-shrink: 0;
}

.wl-add-bar { margin-bottom: 8px; }

#add-word-toggle {
  background: none;
  border: 1px dashed var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 5px 12px;
  font-size: .8rem;
  cursor: pointer;
  transition: all .12s;
}
#add-word-toggle:hover { border-color: var(--accent); color: var(--accent); }

#add-word-form {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; margin-bottom: 8px;
}
.aw-row { display: flex; gap: 6px; flex-wrap: wrap; }
.aw-row input, .aw-row select {
  flex: 1; background: var(--bg2); border: 1px solid var(--border); border-radius: 5px;
  color: var(--text); padding: 5px 8px; font-size: .82rem; font-family: inherit; min-width: 80px;
}
.aw-row input:focus, .aw-row select:focus { outline: none; border-color: var(--accent); }
.aw-row input::placeholder { color: var(--muted); }
.aw-row select option { background: var(--bg2); }

.wl-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 10px;
  align-items: center;
}

#wl-search {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); padding: 5px 10px; font-size: .85rem; width: 180px;
}
#wl-search:focus { outline: none; border-color: var(--accent); }
#wl-search::placeholder { color: var(--muted); }

.game-filters { display: flex; gap: 5px; flex-wrap: wrap; }
.game-filter-btn {
  background: var(--bg3); border: 1px solid var(--border); color: var(--muted);
  border-radius: 5px; padding: 3px 10px; font-size: .75rem; cursor: pointer; transition: all .12s;
}
.game-filter-btn:hover { border-color: var(--accent); color: var(--accent); }
.game-filter-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.game-filter-btn.tag-genshin.active { background: #3a7bd5; border-color: #3a7bd5; }
.game-filter-btn.tag-r1999.active   { background: #7c3aed; border-color: #7c3aed; }

.status-filters { display: flex; gap: 5px; flex-wrap: wrap; }
.status-filter-btn {
  background: var(--bg3); border: 1px solid var(--border); color: var(--muted);
  border-radius: 5px; padding: 3px 10px; font-size: .75rem; cursor: pointer; transition: all .12s;
}
.status-filter-btn:hover { border-color: var(--accent); color: var(--accent); }
.status-filter-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.wl-header-row {
  display: grid;
  grid-template-columns: 80px 110px 1fr 70px 80px 55px 52px;
  padding: 4px 16px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}

#wordlist-container { flex: 1; overflow-y: auto; }

.wl-row {
  display: grid;
  grid-template-columns: 80px 110px 1fr 70px 80px 55px 52px;
  padding: 6px 16px;
  align-items: center;
  font-size: .85rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, transparent);
  transition: background .1s;
}
.wl-row:hover { background: var(--bg3); }

.wl-zh { font-size: 1.05rem; font-weight: 600; color: var(--text); line-height: 1.3; }
.wl-trad { display: block; font-size: .72rem; font-weight: 400; color: var(--muted); }
.wl-py { color: var(--accent2); font-size: .82rem; }
.wl-en { color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.wl-status { font-size: .75rem; color: var(--muted); }
.wl-s-new      { color: var(--new); }
.wl-s-learning { color: var(--learning); }
.wl-s-known    { color: var(--known); }

.wl-srs { font-size: .75rem; color: var(--muted); }
.wl-due { color: var(--new); font-weight: 700; }

.wl-actions { display: flex; gap: 2px; justify-content: flex-end; }

.wl-del, .wl-edit {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: .75rem; padding: 2px 4px;
  border-radius: 3px; opacity: 0; transition: opacity .1s, color .1s;
}
.wl-row:hover .wl-del,
.wl-row:hover .wl-edit { opacity: 1; }
.wl-del:hover { color: var(--new); }
.wl-edit:hover { color: var(--accent); }

/* ── Edit word modal ────────────────────────────────────────────── */
#edit-word-modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.ewm-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.55); backdrop-filter: blur(2px);
}
.ewm-dialog {
  position: relative; z-index: 1;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; padding: 24px 28px; width: 340px;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
}
.ewm-dialog h3 { margin: 0 0 16px; font-size: 1rem; color: var(--text); }
.ewm-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.ewm-row label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.ewm-row input, .ewm-row select {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px; padding: 6px 10px; font-size: .9rem;
}
.ewm-row input:focus, .ewm-row select:focus { outline: 1px solid var(--accent); }
.ewm-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.ewm-actions button { padding: 6px 16px; border-radius: 6px; font-size: .85rem; cursor: pointer; }
.ewm-actions button:not(.primary) {
  background: none; border: 1px solid var(--border); color: var(--muted);
}
.ewm-actions button:not(.primary):hover { color: var(--text); border-color: var(--text); }

.wl-empty { padding: 32px; color: var(--muted); text-align: center; font-size: .9rem; }

/* ── Flashcards ───────────────────────────────────────────────── */
#vtab-flashcards { flex: 1; overflow-y: auto; }

#flashcard-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 20px;
  min-height: 100%;
}
#flashcard-container:has(.fc-complete-img) {
  padding: 0;
  height: 100%;
}

.fc-progress {
  color: var(--muted);
  font-size: .85rem;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.fc-undo-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: .78rem;
  cursor: pointer;
  transition: all .12s;
}
.fc-undo-btn:hover { border-color: var(--accent); color: var(--accent); }

.fc-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  padding: 48px 40px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  box-shadow: 0 4px 24px rgba(0,0,0,.2);
}

.fc-front { display: flex; flex-direction: column; align-items: center; gap: 12px; }

.fc-word {
  font-size: 3.5rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}
.fc-trad { font-size: 2.2rem; font-weight: 400; color: var(--muted); }

.fc-divider { width: 100%; border: none; border-top: 1px solid var(--border); margin: 8px 0; }

.fc-pinyin { font-size: 1.2rem; color: var(--accent2); }
.fc-meaning { font-size: 1rem; color: var(--muted); max-width: 380px; }

.fc-reveal-btn {
  margin-top: 20px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 32px;
  font-size: .9rem;
  cursor: pointer;
  transition: all .15s;
}
.fc-reveal-btn:hover { border-color: var(--accent); color: var(--accent); }

.fc-rating-btns {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.fc-rate-btn {
  border: 1px solid var(--border);
  background: var(--bg3);
  border-radius: 8px;
  padding: 9px 20px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .12s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.fc-rate-btn:hover { opacity: .8; }

.fc-iv { font-size: .68rem; font-weight: 400; opacity: .75; }

.fc-again { background: rgba(224,123,90,.15); border-color: var(--new);      color: var(--new); }
.fc-hard  { background: rgba(224,196,90,.15); border-color: var(--learning); color: var(--learning); }
.fc-good  { background: rgba(90,224,123,.1);  border-color: var(--known);    color: var(--known); }
.fc-easy  { background: rgba(123,140,222,.15); border-color: var(--accent);  color: var(--accent); }

.fc-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 60px 20px;
  color: var(--muted);
  text-align: center;
}
.fc-empty-icon  { font-size: 3rem; }
.fc-empty-title { font-size: 1.25rem; font-weight: 700; color: var(--text); }
.fc-empty-sub   { font-size: .88rem; max-width: 340px; line-height: 1.7; }

.fc-complete-img {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
}
.fc-complete-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
}
.fc-complete-img .primary {
  position: absolute;
  bottom: 28px;
  right: 28px;
  background: rgba(255,255,255,.18);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,.35);
  color: #fff;
  font-size: .9rem;
  padding: 8px 22px;
  border-radius: 8px;
  transition: background .2s;
}
.fc-complete-img .primary:hover {
  background: rgba(255,255,255,.30);
  opacity: 1;
}

/* ── Misc ─────────────────────────────────────────────────────── */
.muted { color: var(--muted); }

/* ── Light-mode overrides (Reverse: 1999 parchment palette) ─── */

/* Subtle paper-grain texture */
[data-theme="light"] body {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='400' height='400' filter='url(%23n)' opacity='0.045'/%3E%3C/svg%3E");
}

/* Header — soft sage-sky gradient */
[data-theme="light"] header {
  background: linear-gradient(to bottom, #e4efeb, #dce7e3);
  border-bottom-color: #a8bcb4;
}

/* App title — classical serif */
[data-theme="light"] header h1 {
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--accent);
}

/* Nav active state — subtle terracotta wash */
[data-theme="light"] .nav-btn.active {
  background: rgba(168,64,48,.10);
}

/* Skill cards — gentle warm shadow */
[data-theme="light"] .skill-field {
  box-shadow: 0 2px 8px rgba(100,75,30,.08);
}
[data-theme="light"] .skill-field:hover {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--border));
  box-shadow: 0 4px 16px rgba(100,75,30,.14);
}

/* Ability fields — terracotta tint instead of purple */
[data-theme="light"] .ability-field {
  border-color: color-mix(in srgb, var(--accent2) 35%, var(--border));
}
[data-theme="light"] .ability-field .field-header {
  background: color-mix(in srgb, var(--accent2) 7%, var(--bg3));
}

/* Popups & modals */
[data-theme="light"] #popup {
  box-shadow: 0 8px 32px rgba(100,75,30,.20);
}
[data-theme="light"] .fc-card {
  box-shadow: 0 4px 24px rgba(100,75,30,.14);
}
[data-theme="light"] #ability-popup {
  border-color: color-mix(in srgb, var(--accent2) 50%, var(--border));
  box-shadow: 0 12px 48px rgba(100,75,30,.24);
}
[data-theme="light"] .modal-box {
  box-shadow: 0 16px 48px rgba(100,75,30,.22);
}
[data-theme="light"] .modal-overlay {
  background: rgba(34,20,8,.45);
}

/* Ruby / text highlights */
[data-theme="light"] ruby:hover             { background: rgba(168,64,48,.10); }
[data-theme="light"] ruby.known-dict:hover  { background: rgba(168,64,48,.14); }
[data-theme="light"] ruby.vocab-saved       { background: rgba(168,64,48,.12); }
[data-theme="light"] ruby.vocab-new         { background: rgba(168,56,40,.20); }
[data-theme="light"] ruby.vocab-learning    { background: rgba(144,106,24,.18); }
[data-theme="light"] ruby.vocab-known       { background: rgba(56,96,64,.16); }

/* Divider lines */
[data-theme="light"] .abilities-divider::before,
[data-theme="light"] .abilities-divider::after {
  background: linear-gradient(to right, transparent, var(--border), transparent);
}

/* Game tags — earthy tones */
[data-theme="light"] .tag-genshin { background: rgba(120,100,30,.15); color: #6a5810; }
[data-theme="light"] .tag-r1999   { background: rgba(178,78,56,.14);  color: #8a3828; }
[data-theme="light"] .tag-song    { background: rgba(219,39,119,.10); color: #be185d; }
[data-theme="light"] .tag-story   { background: rgba(13,148,136,.10); color: #0f766e; }

/* Flashcard rating buttons */
[data-theme="light"] .fc-again { background: rgba(168,56,40,.10); }
[data-theme="light"] .fc-hard  { background: rgba(144,106,24,.10); }
[data-theme="light"] .fc-good  { background: rgba(56,96,64,.09);   }
[data-theme="light"] .fc-easy  { background: rgba(168,64,48,.10);  }

/* Ability popup accent (terracotta instead of purple) */
[data-theme="light"] .ap-label { color: var(--accent2); }
[data-theme="light"] .ap-header {
  background: color-mix(in srgb, var(--accent2) 7%, var(--bg3));
  border-bottom-color: color-mix(in srgb, var(--accent2) 25%, var(--border));
}

/* Char sidebar — slightly warmer shade */
[data-theme="light"] .char-sidebar {
  background: color-mix(in srgb, var(--bg2) 80%, var(--bg3));
}

/* Focus word in flashcards */
[data-theme="light"] ruby.fc-focus-word { color: var(--accent); }

/* Flashcard context sentence — very light for contrast */
[data-theme="light"] .fc-context {
  background: #ecf2ef;
  border-color: #b4c8c0;
}

/* ── Study Pet ────────────────────────────────────────────────────── */
#study-pet {
  position: fixed;
  z-index: 800;
  cursor: grab;
  user-select: none;
  width: 48px;
  height: 68px;
  transition: left 2s ease-in-out, top 2s ease-in-out;
}
#study-pet:active { cursor: grabbing; }

#pet-sprite { display: block; image-rendering: pixelated; }
#pet-sprite svg { display: block; }

#pet-bubble {
  position: absolute;
  bottom: calc(100% + 5px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 11px;
  white-space: nowrap;
  color: var(--text);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
#pet-bubble.pet-bubble-show { opacity: 1; }

.pet-particle {
  position: absolute;
  pointer-events: none;
  line-height: 1;
}

/* Mood animations */
.pet-idle       #pet-sprite { animation: pet-bob    3s    ease-in-out infinite; }
.pet-happy      #pet-sprite { animation: pet-bob    1.8s  ease-in-out infinite; }
.pet-sleepy     #pet-sprite { animation: pet-sway   4s    ease-in-out infinite; }
.pet-excited    #pet-sprite { animation: pet-bounce 0.65s ease-in-out infinite; }
.pet-curious    #pet-sprite { animation: pet-tilt   2.5s  ease-in-out infinite; }
.pet-celebrating #pet-sprite { animation: pet-jump  0.5s  ease-in-out infinite; }

@keyframes pet-bob {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-4px); }
}
@keyframes pet-bounce {
  0%, 100% { transform: translateY(0) scale(1); }
  50%       { transform: translateY(-9px) scale(1.06); }
}
@keyframes pet-sway {
  0%, 100% { transform: rotate(-4deg) translateY(0); }
  50%       { transform: rotate(4deg)  translateY(-2px); }
}
@keyframes pet-tilt {
  0%, 100% { transform: rotate(13deg); }
  50%       { transform: rotate(11deg) translateY(-2px); }
}
@keyframes pet-jump {
  0%, 100% { transform: translateY(0)   rotate(0deg)  scale(1); }
  40%       { transform: translateY(-14px) rotate(-6deg) scale(1.1); }
  60%       { transform: translateY(-14px) rotate(6deg)  scale(1.1); }
}
@keyframes pet-float-up {
  0%   { transform: translateY(0)    scale(1);   opacity: 1; }
  100% { transform: translateY(-30px) scale(0.6); opacity: 0; }
}
@keyframes pet-burst {
  0%   { transform: translate(0, 0)                    scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}

/* Pet toggle button in header */
#pet-toggle-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 4px 9px;
  font-size: .78rem;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
#pet-toggle-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Light mode: slightly deepen the orange */
[data-theme="light"] #study-pet { filter: saturate(1.15) brightness(0.88); }
