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

:root {
  --bg: #1a1a2e;
  --bg-card: #16213e;
  --bg-hover: #1e2a4a;
  --text: #e0e0e0;
  --text-dim: #8a8a9a;
  --accent: #c4a35a;
  --accent-dim: #8a7340;
  --border: #2a2a4a;
  --green: #66bb6a;
  --red: #e57373;
  --font-display: 'Cinzel', 'Georgia', serif;
  --font-body: 'Alegreya', 'Georgia', serif;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse at 15% 80%, rgba(138, 115, 64, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 20%, rgba(72, 52, 140, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, rgba(22, 33, 62, 0.4) 0%, transparent 80%);
  background-attachment: fixed;
}

/* ── Custom scrollbar ───────────────────────────────── */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }
* { scrollbar-width: thin; scrollbar-color: var(--border) var(--bg); }

header {
  text-align: center;
  padding: 1.5rem 1rem 0.5rem;
  position: relative;
  transition: padding 0.2s;
}

#header-toggle {
  position: absolute;
  top: 0.5rem;
  left: 1rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  font-size: 0.7rem;
  cursor: pointer;
  padding: 0.15rem 0.4rem;
  line-height: 1;
  transition: all 0.15s;
}

#header-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

#lang-switcher {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: var(--bg-card);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  font-size: 0.8rem;
  cursor: pointer;
}

#lang-switcher:hover {
  border-color: var(--accent);
}

header h1 {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.08em;
  transition: all 0.2s;
  text-shadow: 0 0 20px rgba(196, 163, 90, 0.3), 0 0 40px rgba(196, 163, 90, 0.1);
}

.subtitle {
  font-family: var(--font-body);
  font-style: italic;
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-top: 0.25rem;
  transition: all 0.2s;
  letter-spacing: 0.03em;
}

/* Collapsed header */
header.collapsed {
  padding: 0.3rem 1rem;
}

header.collapsed h1 {
  font-size: 1rem;
  display: inline;
  margin-right: 0.5rem;
}

header.collapsed .subtitle {
  display: none;
}

header.collapsed #lang-switcher {
  top: 0.3rem;
}

header.collapsed #header-toggle {
  top: 0.3rem;
}

/* ── Tabs ─────────────────────────────────────────── */

#tabs {
  display: flex;
  justify-content: center;
  gap: 0.25rem;
  padding: 1rem 1rem 0;
  flex-wrap: wrap;
}

.tab {
  font-family: var(--font-display);
  background: var(--bg-card);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px 6px 0 0;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  transition: all 0.2s;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--bg);
  background: var(--bg);
  font-weight: 600;
  text-shadow: 0 0 10px rgba(196, 163, 90, 0.2);
}

/* ── Sub-tabs (Preparati → Incantesimi, Appresi → Talenti) ── */

.tab[data-tab="prepared"],
.tab[data-tab="learned"] {
  border-top-left-radius: 0;
  margin-left: -2px;
  font-size: 0.72rem;
  opacity: 0.7;
  margin-right: 1rem;
  position: relative;
}

.tab[data-tab="prepared"]:hover,
.tab[data-tab="learned"]:hover,
.tab[data-tab="prepared"].active,
.tab[data-tab="learned"].active {
  opacity: 1;
}

.tab[data-tab="prepared"]::after,
.tab[data-tab="learned"]::after {
  content: '';
  position: absolute;
  right: -0.6rem;
  top: 20%;
  height: 60%;
  width: 1px;
  background: var(--border);
}

/* ── Search + Filters ─────────────────────────────── */

#search-bar {
  padding: 0.75rem 1rem;
  max-width: 900px;
  margin: 0 auto;
}

.search-wrapper {
  position: relative;
  width: 100%;
}

#search {
  width: 100%;
  padding: 0.6rem 2.2rem 0.6rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 1rem;
  outline: none;
}

#search:focus {
  border-color: var(--accent);
}

.search-clear {
  position: absolute;
  right: 0.4rem;
  top: 0;
  height: calc(0.6rem * 2 + 1rem + 2px); /* match #search height: padding + font + border */
  display: flex;
  align-items: center;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 0.4rem;
  line-height: 1;
  border-radius: 3px;
}

.search-clear:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.search-clear.hidden {
  display: none;
}

#search::placeholder {
  color: var(--text-dim);
}

.fulltext-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  cursor: pointer;
  margin-top: 0.4rem;
  padding: 0.15rem 0;
  white-space: nowrap;
}

.fulltext-toggle:hover {
  color: var(--text);
}

.fulltext-toggle:has(input:checked) {
  color: var(--accent);
}

mark {
  background: rgba(255, 224, 102, 0.45);
  color: inherit;
  padding: 0 1px;
  border-radius: 2px;
}

#filters {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

#filters select {
  padding: 0.35rem 0.6rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}

#filters select:focus {
  border-color: var(--accent);
}

#result-count {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-left: auto;
  align-self: center;
}

/* ── Level checkboxes ─────────────────────────────── */

.level-checkboxes {
  display: flex;
  gap: 0.15rem;
  align-items: center;
  flex-wrap: wrap;
  width: 100%;
  margin-top: 0.25rem;
}

.level-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-right: 0.3rem;
}

.level-check {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  transition: all 0.15s;
}

.level-check:has(input:checked) {
  background: var(--accent-dim);
  color: #fff;
  border-color: var(--accent);
}

.level-check input {
  display: none;
}

.level-toggle {
  font-size: 0.75rem;
  color: var(--text-dim);
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  margin-left: 0.25rem;
}

.level-toggle:hover {
  color: var(--text);
  border-color: var(--accent);
}

.edition-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  cursor: pointer;
  margin-left: 0.5rem;
  padding: 0.15rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.edition-toggle:hover {
  color: var(--text);
  border-color: var(--accent);
}

.edition-toggle:has(input:checked) {
  background: var(--accent-dim);
  color: #fff;
  border-color: var(--accent);
}

/* ── Layout ───────────────────────────────────────── */

main {
  display: flex;
  gap: 1rem;
  padding: 0 1rem 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

#results-list {
  flex: 1;
  min-width: 0;
  max-height: var(--content-height, calc(100vh - 260px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.vs-spacer {
  contain: layout style;
  will-change: contents;
}

#detail-panel {
  position: relative;
  flex: 1.8;
  min-width: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  max-height: var(--content-height, calc(100vh - 260px));
  overflow-y: auto;
  overflow-x: hidden;
  position: sticky;
  top: 1rem;
}

.detail-close {
  position: sticky;
  top: 0;
  float: right;
  background: var(--bg-card);
  border: none;
  color: var(--text-dim);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  line-height: 1;
  border-radius: 4px;
  z-index: 1;
}

.detail-close:hover {
  color: var(--text);
  background: var(--bg-hover);
}

#detail-panel.hidden {
  display: none;
}

/* ── Level group headers ──────────────────────────── */

.level-group-header {
  padding: 0.4rem 0.8rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  gap: 0.4rem;
  transition: color 0.15s, background 0.15s;
}

.level-group-header:hover {
  color: var(--accent);
  background: rgba(255, 255, 255, 0.03);
}

.level-group-header.collapsed {
  border-bottom-color: transparent;
}

.level-chevron {
  font-size: 0.7rem;
  display: inline-flex;
  align-items: center;
  width: 0.8rem;
  flex-shrink: 0;
}

.level-count {
  margin-left: auto;
  font-weight: 400;
  font-size: 0.7rem;
  opacity: 0.6;
}

/* ── Result items ─────────────────────────────────── */

.result-item {
  padding: 0.6rem 0.8rem;
  margin-bottom: 2px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, border-left-color 0.2s, transform 0.15s;
  border-left: 3px solid var(--school-clr, transparent);
  overflow: hidden;
}

.result-item:hover {
  background: var(--bg-hover);
  transform: translateX(2px);
}

.result-item.selected {
  background: var(--bg-hover);
  border-left-color: var(--accent);
}

.result-item .meta {
  color: var(--school-clr, var(--text-dim));
}

.result-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.result-text {
  flex: 1;
  min-width: 0;
}

.result-item .name {
  font-weight: 500;
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
  overflow: hidden;
  white-space: nowrap;
}

.result-item .name-text {
  flex-shrink: 0;
}

.result-item .source-badge {
  font-size: 0.6rem;
  padding: 0.05rem 0.3rem;
  vertical-align: baseline;
  flex-shrink: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.result-item .edition-badge {
  flex-shrink: 0;
}

.result-item .name-en {
  flex-shrink: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--text-dim);
  opacity: 0.6;
  font-style: italic;
}

.name-en {
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--text-dim);
  opacity: 0.6;
  margin-left: 0.5rem;
  font-style: italic;
}

.result-item .meta {
  font-size: 0.8rem;
  margin-top: 0.15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.no-results {
  text-align: center;
  color: var(--text-dim);
  padding: 2rem;
  line-height: 1.6;
}

/* ── Prepare button (in spell list) ───────────────── */

.prep-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--accent-dim);
  background: transparent;
  color: var(--accent);
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  line-height: 1;
}

.prep-btn:hover {
  background: var(--accent);
  color: var(--bg);
}

.prep-btn-active {
  border-color: var(--green);
  color: var(--green);
}

.prep-btn-active:hover {
  background: var(--green);
  color: var(--bg);
}

/* ── Prepared badge (in spell list) ───────────────── */

.prep-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--green);
  background: rgba(102, 187, 106, 0.15);
  border: 1px solid rgba(102, 187, 106, 0.3);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  white-space: nowrap;
}

.prep-badge.exhausted {
  color: var(--red);
  background: rgba(229, 115, 115, 0.15);
  border-color: rgba(229, 115, 115, 0.3);
}

.result-item.is-prepared {
  border-left-color: var(--green);
}

.result-item.is-prepared .name {
  color: var(--green);
}

/* ── Prepared spells tab ──────────────────────────── */

.prepared-item {
  cursor: default;
  padding: 0.5rem 0.8rem;
  border-left: 3px solid var(--school-clr, transparent);
}

.prepared-item .prep-info {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.prepared-item .prep-name {
  font-weight: 500;
}

.prepared-item .meta {
  font-size: 0.75rem;
  color: var(--school-clr, var(--text-dim));
}

.prepared-item .prep-info:hover .prep-name {
  color: var(--accent);
}

.prepared-item .prep-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.prepared-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.prepared-item.all-used {
  opacity: 0.5;
}

.prep-counter,
.prep-adjust {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.prep-usage {
  font-size: 0.9rem;
  font-weight: 600;
  min-width: 2.5rem;
  text-align: center;
  color: var(--green);
}

.prep-usage.exhausted {
  color: var(--red);
}

.prep-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
}

.counter-btn {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
}

.counter-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.remove-btn {
  width: 22px;
  height: 22px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.remove-btn:hover {
  color: var(--red);
}

/* ── Learned feats (in feat list) ────────────────── */

.learn-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--accent-dim);
  background: transparent;
  color: var(--text-dim);
  font-size: 0.9rem;
  font-weight: bold;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  line-height: 1;
}

.learn-btn:hover {
  border-color: var(--green);
  color: var(--green);
}

.learn-btn-active {
  border-color: var(--green);
  color: var(--green);
  background: rgba(102, 187, 106, 0.15);
}

.learn-btn-active:hover {
  background: var(--green);
  color: var(--bg);
}

.result-item.is-learned {
  border-left-color: var(--green);
}

.result-item.is-learned .name {
  color: var(--green);
}

/* ── Learned feats tab ───────────────────────────── */

.learned-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.8rem;
  cursor: default;
}

.learned-item .learned-name {
  font-weight: 500;
  cursor: pointer;
  flex: 1;
  min-width: 0;
}

.learned-item .learned-name:hover {
  color: var(--accent);
}

/* ── Detail panel ─────────────────────────────────── */

#detail-panel h2 {
  font-family: var(--font-display);
  color: var(--accent);
  margin-bottom: 0.3rem;
  font-size: 1.4rem;
  letter-spacing: 0.04em;
  overflow-wrap: break-word;
  word-break: break-word;
}

.detail-name-en {
  font-style: italic;
  color: var(--text-dim);
  opacity: 0.6;
  font-size: 0.95rem;
  margin-bottom: 1rem;
  text-shadow: 0 0 15px rgba(196, 163, 90, 0.15);
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

#detail-panel .fields-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.3rem 1rem;
  margin-bottom: 1rem;
}

#detail-panel .field {
  display: contents;
}

#detail-panel .field-label {
  font-weight: 600;
  color: var(--accent-dim);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.2rem 0;
  white-space: nowrap;
}

#detail-panel .field-value {
  padding: 0.2rem 0;
  font-size: 0.95rem;
}

#detail-panel .spell-summary {
  margin-top: 0.5rem;
  padding: 0.4rem 0.6rem;
  color: var(--text-secondary, #888);
  font-size: 0.9em;
  border-left: 3px solid var(--accent);
}

#detail-panel .desc-html {
  margin-top: 1rem;
  line-height: 1.6;
}

#detail-panel .desc-html p {
  margin-bottom: 0.5rem;
}

#detail-panel .desc-html ul,
#detail-panel .desc-html ol {
  margin: 0.5rem 0;
  padding-left: 1.25rem;
}

#detail-panel .desc-html li {
  margin-bottom: 0.3rem;
}

#detail-panel .desc-html table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0;
  font-size: 0.85rem;
}

#detail-panel .desc-html th,
#detail-panel .desc-html td {
  border: 1px solid var(--border);
  padding: 0.3rem 0.5rem;
  text-align: left;
}

#detail-panel .desc-html th {
  background: var(--bg);
  color: var(--accent);
}

#detail-panel .desc-html h3,
#detail-panel .desc-html h4 {
  color: var(--accent);
  margin: 1rem 0 0.4rem;
}

/* ── Source badge ─────────────────────────────────── */

.source-badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  background: var(--accent-dim);
  color: var(--text);
  margin-left: 0.5rem;
  vertical-align: middle;
  font-weight: 600;
  letter-spacing: 0.03em;
}

/* ── Edition badge ───────────────────────────────── */

.edition-badge {
  display: inline-block;
  font-size: 0.6rem;
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
  margin-left: 0.3rem;
  vertical-align: middle;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.edition-35 { background: #2a6b3c; color: #fff; }
.edition-30 { background: #8b6914; color: #fff; }

.result-item .edition-badge {
  font-size: 0.55rem;
  padding: 0.02rem 0.2rem;
}

/* ── Source footer (bottom of detail panel) ──────── */

.source-footer {
  margin-top: 1.5rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-dim);
  opacity: 0.7;
}
.source-footer-line {
  margin-bottom: 0.15rem;
}
.source-footer-lang {
  display: inline-block;
  width: 1.6rem;
  font-weight: 600;
  color: var(--accent);
  opacity: 0.8;
}
.source-footer-site {
  font-style: italic;
  opacity: 0.6;
  margin-top: 0.2rem;
}
.source-footer-site a {
  color: var(--accent);
  text-decoration: none;
  opacity: 0.8;
  transition: opacity 0.15s;
}
.source-footer-site a:hover {
  opacity: 1;
  text-decoration: underline;
}

/* ── Translation status dashboard ────────────────── */

.status-dashboard {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1rem 0;
  font-size: 1.25rem;
}

.status-lang-selector {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.status-lang-btn {
  background: var(--bg-card);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 1rem;
  cursor: pointer;
  font-size: 0.85rem;
}

.status-lang-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.status-lang-btn.active {
  background: var(--accent-dim);
  color: var(--text);
  border-color: var(--accent);
}

.status-lang-label {
  text-align: center;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.status-overall {
  margin-bottom: 1.5rem;
  text-align: center;
}

.status-overall h3 {
  color: var(--accent);
  margin-bottom: 0.5rem;
  font-size: 1.4rem;
}

.status-overall .status-pct {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--accent);
}

.status-bar-outer {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  height: 18px;
  overflow: hidden;
  margin-top: 0.5rem;
}

.status-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 5px;
  transition: width 0.3s;
}

.status-bar-fill.complete {
  background: var(--green);
}

.status-category {
  margin-bottom: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.status-cat-header {
  padding: 0.6rem 1rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  color: var(--accent);
}

.status-cat-header:hover {
  background: var(--bg-hover);
}

.status-cat-header .cat-pct {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.status-cat-body {
  padding: 0 1rem 0.75rem;
  display: none;
}

.status-category.open .status-cat-body {
  display: block;
}

.status-field-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0;
  font-size: 1rem;
}

.status-field-row .field-name {
  width: 140px;
  flex-shrink: 0;
  color: var(--text-dim);
}

.status-field-row .field-bar {
  flex: 1;
  height: 12px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
}

.status-field-row .field-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
}

.status-field-row .field-bar-fill.complete {
  background: var(--green);
}

.status-field-row .field-stats {
  width: 130px;
  flex-shrink: 0;
  text-align: right;
  font-size: 0.9rem;
  color: var(--text-dim);
}

.status-field-row.has-issues {
  cursor: pointer;
  flex-wrap: wrap;
}

.status-field-row.has-issues:hover {
  background: var(--bg-hover);
  border-radius: 4px;
}

.field-badges {
  display: flex;
  gap: 0.3rem;
  margin-left: auto;
  flex-shrink: 0;
}

.badge {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-identical {
  background: #f59e0b22;
  color: #d97706;
  border: 1px solid #f59e0b44;
}

.badge-ocr {
  background: #ef444422;
  color: #dc2626;
  border: 1px solid #ef444444;
}

.badge-english {
  background: #8b5cf622;
  color: #7c3aed;
  border: 1px solid #8b5cf644;
}

.field-issues-list {
  display: none;
  width: 100%;
  margin: 0.3rem 0 0.5rem;
  padding: 0.5rem 0.8rem;
  background: var(--bg);
  border-radius: 4px;
  border: 1px solid var(--border);
  max-height: 300px;
  overflow-y: auto;
}

.field-issues-list.open {
  display: block;
}

/* ── Per-source breakdown ── */
.status-by-source {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
}

.source-breakdown-title {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 0.5rem 0;
  user-select: none;
}

.source-breakdown-title:hover {
  color: var(--accent);
}

.source-breakdown-title .toggle-arrow {
  font-size: 0.7rem;
  transition: transform 0.2s;
  display: inline-block;
}

.source-breakdown-body {
  display: none;
}

.source-breakdown-body.open {
  display: block;
}

.source-breakdown-body.open + .source-breakdown-title .toggle-arrow,
.source-breakdown-title:has(+ .source-breakdown-body.open) .toggle-arrow {
  transform: rotate(90deg);
}

.source-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.25rem 0;
  font-size: 0.85rem;
}

.source-name {
  font-weight: 600;
  min-width: 3.5rem;
  color: var(--accent);
}

.source-count {
  min-width: 2rem;
  text-align: right;
  color: var(--text-dim);
  font-size: 0.8rem;
}

.source-row .field-bar {
  flex: 1;
  height: 8px;
  min-width: 60px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
}

.source-row .field-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
}

.source-row .field-bar-fill.complete {
  background: var(--green);
}

.source-row .field-stats {
  min-width: 120px;
  text-align: right;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.source-row.clickable {
  cursor: pointer;
}
.source-row.clickable:hover .source-name {
  text-decoration: underline;
}

.source-desc-badge {
  font-size: 0.75rem;
  margin-left: 0.3rem;
  opacity: 0.7;
}

/* Expandable spell list per source */
.source-spell-list {
  display: none;
  margin: 0.2rem 0 0.8rem 1rem;
  max-height: 300px;
  overflow-y: auto;
  border-left: 2px solid var(--border);
  padding-left: 0.6rem;
}
.source-spell-list.open {
  display: block;
}

.source-spell-entry {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.15rem 0;
  font-size: 0.8rem;
  color: var(--text);
}

.source-spell-entry .desc-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.source-spell-entry.has-desc .desc-dot {
  background: var(--green);
}
.source-spell-entry.no-desc .desc-dot {
  background: var(--red, #e74c3c);
}
.source-spell-entry.no-desc {
  opacity: 0.75;
}

.source-spell-entry .spell-entry-name {
  font-weight: 500;
}
.source-spell-entry .spell-entry-en {
  color: var(--text-dim);
  font-size: 0.75rem;
  font-style: italic;
}

/* Translation quality section */
.status-quality {
  margin-top: 0.8rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(255,255,255,0.02);
}
.quality-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  margin: 0 0 0.4rem 0;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.quality-stats {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}
.quality-reviewed {
  font-weight: 500;
}
.quality-sources {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.quality-source-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-dim);
}
.quality-source-label {
  opacity: 0.8;
}
.quality-source-count {
  font-weight: 500;
}
.badge-reviewed {
  background: #2d6a4f;
  color: #d8f3dc;
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-size: 0.65rem;
  margin-left: 0.3rem;
}

/* CSV export button */
.status-export {
  margin-top: 0.8rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  text-align: right;
}
.export-csv-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.3rem 0.8rem;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.export-csv-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.issue-item {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.4rem 0;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.issue-item:last-child {
  border-bottom: none;
}

.issue-slug {
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
  min-width: 140px;
}

.issue-type {
  font-size: 0.75rem;
  padding: 0.1rem 0.4rem;
  border-radius: 2px;
  flex-shrink: 0;
}

.issue-type.issue-missing {
  background: #6b728022;
  color: var(--text-dim);
}

.issue-type.issue-identical {
  background: #f59e0b22;
  color: #d97706;
}

.issue-type.issue-ocr {
  background: #ef444422;
  color: #dc2626;
}

.issue-type.issue-english {
  background: #8b5cf622;
  color: #7c3aed;
}

.issue-values {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex: 1;
  min-width: 0;
}

.issue-en, .issue-it {
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.issue-en b, .issue-it b {
  font-size: 0.7rem;
  margin-right: 0.3rem;
}

.issue-en {
  opacity: 0.6;
}

.issue-detail {
  color: var(--text-dim);
  font-style: italic;
  font-size: 0.8rem;
  width: 100%;
  padding-left: 140px;
}

.status-generated {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.75rem;
  margin-top: 1rem;
}

/* ── Loading ──────────────────────────────────────── */

.loading {
  text-align: center;
  color: var(--text-dim);
  padding: 2rem;
}

/* ── Responsive ───────────────────────────────────── */

@media (max-width: 768px) {
  main {
    flex-direction: column;
  }

  #tabs {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.5rem;
    scrollbar-width: none;
  }

  #tabs::-webkit-scrollbar { display: none; }

  .tab {
    flex-shrink: 0;
    font-size: 0.75rem;
    padding: 0.4rem 0.75rem;
  }

  #detail-panel {
    position: static;
    max-height: none;
  }

  #results-list {
    max-height: var(--content-height, 40vh);
  }

  /* Mobile master-detail: hide list + search when detail is shown (pure CSS) */
  body:has(#detail-panel:not(.hidden)) #search-bar,
  body:has(#detail-panel:not(.hidden)) #results-list {
    display: none;
  }

  body:has(#detail-panel:not(.hidden)) #detail-panel {
    border-top: none;
    margin-top: 0;
  }

  #detail-panel .fields-grid {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }

  #detail-panel .field-label {
    padding-bottom: 0;
  }

  #detail-panel .field-value {
    padding-top: 0;
    margin-bottom: 0.4rem;
  }

  .prepared-item {
    flex-wrap: wrap;
  }

  .prep-controls {
    width: 100%;
    justify-content: flex-end;
  }

  /* Touch-friendly targets (min 44x44px per WCAG) */
  .counter-btn {
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }

  .remove-btn {
    width: 36px;
    height: 36px;
    font-size: 1.3rem;
  }

  .prep-btn, .learn-btn {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
  }

  .level-check {
    padding: 0.3rem 0.15rem;
  }
}
