/* ═══ Country Card Redesign ═══════════════════════════════ */
.country-grid-redesign {
  gap: 16px;
}

.country-card-rich {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 !important;
  overflow: hidden;
}

.country-card-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 0;
}

.country-card-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: var(--primary-alpha, rgba(99, 102, 241, 0.1));
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  flex-shrink: 0;
}

.country-card-title {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.country-card-title strong {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.country-card-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 12px;
}

.country-stat {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-2);
  background: var(--bg-2);
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.country-card-desc {
  padding: 0 12px;
  line-height: 1.4;
}

.country-section {
  padding: 4px 12px 8px;
  border-top: 1px solid var(--border);
}

.country-section-title {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-3);
  margin-bottom: 4px;
}

/* ── Government influence bars ── */
.country-gov-bars {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.country-gov-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}

.country-gov-name {
  min-width: 90px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-2);
}

.country-gov-track {
  flex: 1;
  height: 6px;
  background: var(--bg-3);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.country-gov-fill {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width 0.3s;
}

.country-gov-pct {
  font-size: 10px;
  color: var(--text-3);
  min-width: 28px;
  text-align: right;
}

/* ── Race distribution bars ── */
.country-race-bars {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.country-race-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}

.country-race-name {
  min-width: 70px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-2);
}

.country-race-track {
  flex: 1;
  height: 6px;
  background: var(--bg-3);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.country-race-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.3s;
}

.country-race-pct {
  font-size: 10px;
  color: var(--text-3);
  min-width: 24px;
  text-align: right;
}

.country-race-status {
  font-size: 9px;
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Diplomacy mini badges ── */
.country-diplo-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.country-diplo-badge {
  font-size: 10px;
  padding: 1px 6px;
  border: 1px solid;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.country-diplo-badge b {
  margin-left: 2px;
}

/* ═══ Diplomacy Panel ═════════════════════════════════════ */
.diplo-panel {
  padding: 12px 16px;
}

.diplo-summary {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  padding: 12px;
  background: var(--bg-2);
  border-radius: var(--radius);
}

.diplo-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.diplo-stat-num {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.diplo-stat-label {
  font-size: 11px;
  color: var(--text-3);
}

/* ── Diplomacy matrix ── */
.diplo-matrix-wrap {
  overflow-x: auto;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.diplo-matrix {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.diplo-matrix th,
.diplo-matrix td {
  padding: 4px 6px;
  text-align: center;
  white-space: nowrap;
  border: 1px solid var(--border);
}

.diplo-matrix th {
  background: var(--bg-2);
  font-weight: 600;
  font-size: 10px;
}

.diplo-matrix-label {
  text-align: left !important;
  font-weight: 600;
  background: var(--bg-2);
}

.diplo-cell {
  font-weight: 600;
  font-size: 11px;
  cursor: default;
}

.diplo-self {
  background: var(--bg-3) !important;
  color: var(--text-3) !important;
}

/* ── Diplomacy pair list ── */
.diplo-pairs-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.diplo-pair-card {
  background: var(--bg-2);
  border-radius: var(--radius);
  padding: 10px 12px;
  border: 1px solid var(--border);
}

.diplo-pair-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.diplo-pair-country {
  font-weight: 600;
  font-size: 13px;
}

.diplo-pair-arrow {
  font-size: 16px;
}

.diplo-pair-val {
  font-weight: 700;
  font-size: 14px;
  margin-left: auto;
}

.diplo-pair-bar {
  margin-top: 6px;
}

.diplo-pair-bar-track {
  height: 4px;
  background: var(--bg-3);
  border-radius: var(--radius-full);
  overflow: hidden;
  position: relative;
}

.diplo-pair-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.3s;
}

.diplo-bar-right {
  margin-left: 0;
}

.diplo-bar-left {
  margin-left: auto;
}

.diplo-pair-type {
  margin-top: 4px;
}

.diplo-pair-desc {
  margin-top: 2px;
  line-height: 1.4;
}

/* ═══ Country History Timeline ════════════════════════════ */
.country-hist-wrap {
  padding: 12px 16px;
}

.country-hist-selector {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.country-hist-selector select {
  max-width: 240px;
}

.country-hist-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  padding: 8px 12px;
  background: var(--bg-2);
  border-radius: var(--radius);
}

.country-hist-stat {
  font-size: 11px;
  font-weight: 600;
}

/* ── Timeline line ── */
.country-hist-timeline {
  position: relative;
  padding-left: 24px;
}

.country-hist-timeline::before {
  content: '';
  position: absolute;
  left: 11px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

.country-hist-event {
  position: relative;
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.country-hist-line {
  position: absolute;
  left: -24px;
  top: 4px;
}

.country-hist-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  position: relative;
}

.country-hist-card {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
}

.country-hist-year {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-3);
  margin-bottom: 2px;
}

.country-hist-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}

.country-hist-desc {
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.4;
  margin-top: 4px;
}

.country-hist-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-3);
  margin-top: 3px;
}

/* ═══ City History (Timeline) ═════════════════════════════ */
.citylife-wrap {
  padding: 12px 16px;
}

.citylife-selector {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.citylife-select {
  flex: 1;
  max-width: 260px;
}

.citylife-gen-btn {
  white-space: nowrap;
}

.citylife-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--city-color, #06b6d4) 8%, var(--bg-2));
  border: 1px solid color-mix(in srgb, var(--city-color, #06b6d4) 25%, var(--border));
  border-radius: 12px;
  margin-bottom: 12px;
}

.citylife-profile-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--city-color, #06b6d4) 15%, var(--bg-1));
  border: 2px solid var(--city-color, #06b6d4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--city-color, #06b6d4);
  flex-shrink: 0;
}

.citylife-profile-info {
  flex: 1;
  min-width: 0;
}

.citylife-profile-name {
  display: block;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-0);
}

.citylife-profile-meta {
  display: flex;
  gap: 10px;
  font-size: 11px;
  color: var(--text-3);
  margin-top: 3px;
}

.citylife-event-count {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  background: var(--bg-3);
  padding: 3px 10px;
  border-radius: 10px;
}

.citylife-info-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--bg-2);
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 11px;
  color: var(--text-3);
}

.citylife-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  padding: 8px 12px;
  background: var(--bg-2);
  border-radius: var(--radius);
}

.citylife-stat {
  font-size: 11px;
  font-weight: 600;
}

/* ── City Timeline line ── */
.citylife-timeline {
  position: relative;
  padding-left: 24px;
}

.citylife-timeline::before {
  content: '';
  position: absolute;
  left: 11px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(180deg, #06b6d4 0%, var(--border) 100%);
  border-radius: 2px;
}

.citylife-event {
  position: relative;
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.citylife-line {
  position: absolute;
  left: -24px;
  top: 4px;
}

.citylife-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  position: relative;
  border: 2px solid var(--bg-1);
  box-shadow: 0 0 8px color-mix(in srgb, currentColor 30%, transparent);
}

.citylife-card {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  transition: border-color .2s;
}

.citylife-card:hover {
  border-color: var(--city-color, #06b6d4);
}

.citylife-card-global {
  border-left: 3px solid #f59e0b;
}

.citylife-event-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.citylife-event-year {
  font-size: 11px;
  font-weight: 700;
  color: var(--city-color, #06b6d4);
  background: color-mix(in srgb, var(--city-color, #06b6d4) 12%, transparent);
  padding: 1px 8px;
  border-radius: 6px;
}

.citylife-event-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-1);
  margin-bottom: 2px;
}

.citylife-event-desc {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 4px;
  line-height: 1.4;
}

.citylife-event-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-3);
  margin-top: 3px;
}

/* ═══ List Editor (Modal) ═════════════════════════════════ */
.list-editor-group {
  width: 100%;
}

.list-editor {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  background: var(--bg-2);
  max-height: 200px;
  overflow-y: auto;
}

.list-editor-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.list-editor-table th {
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  padding: 2px 4px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.list-editor-table td {
  padding: 2px 4px;
}

.list-editor-table .le-input {
  font-size: 12px;
  padding: 3px 6px;
  width: 100%;
}

.list-editor-table .le-remove-row {
  color: var(--text-3);
  padding: 2px 4px !important;
  min-width: 0 !important;
}

.list-editor-table .le-remove-row:hover {
  color: var(--danger, #ef4444);
}

.le-add-row {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
}

/* ═══ Country list redesign (list view) ═══════════════════ */
.country-row-rich .location-row {
  flex-wrap: wrap;
  gap: 6px;
}

/* ── Trash panel ─────────────────────────────────────── */
.trash-item:hover {
  background: var(--bg-2);
}

.culture-bar {
  display: flex;
  height: 4px;
  width: 80px;
  border-radius: var(--radius-full);
  overflow: hidden;
  background: var(--bg-4);
  margin-left: auto;
}

.culture-segment {
  height: 100%;
}

/* ── Panel: Races ──────────────────────────────────────── */
.races-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.race-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all var(--transition);
  cursor: pointer;
}

.race-card:hover {
  border-color: var(--border-light);
  transform: translateY(-2px);
}

.race-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: var(--text-2);
}

.race-body {
  padding: 20px;
}

.race-body h4 {
  margin-bottom: 8px;
}

.race-meta {
  display: flex;
  gap: 12px;
  margin-bottom: 8px;
}

.race-meta span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--text-2);
}

.race-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.race-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-3);
  color: var(--text-2);
  border: 1px solid var(--border);
}

/* ── Race Modal ────────────────────────────────────────── */
.race-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, .6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn .15s ease;
}

.race-modal {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 720px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: slideUp .2s ease;
}

.race-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 28px;
  border-bottom: 1px solid var(--border);
}

.race-modal-header h2 {
  margin: 0;
  font-size: 1.4rem;
}

.race-modal-body {
  padding: 24px 28px;
  overflow-y: auto;
  flex: 1;
}

.rm-section {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.rm-section summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  background: var(--bg-2);
  color: var(--text-1);
  user-select: none;
}

.rm-section summary:hover {
  background: var(--bg-3);
}

.rm-section-body {
  padding: 12px 14px;
}

.rm-kv {
  display: flex;
  gap: 8px;
  padding: 4px 0;
  font-size: 0.82rem;
  border-bottom: 1px solid var(--border);
}

.rm-kv:last-child {
  border-bottom: none;
}

.rm-k {
  min-width: 130px;
  color: var(--text-2);
  font-weight: 500;
  flex-shrink: 0;
}

.rm-v {
  color: var(--text-1);
  flex: 1;
}

.rm-list-block {
  margin-bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.rm-list-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-2);
  margin-right: 4px;
}

.rm-chip {
  display: inline-block;
  font-size: 0.72rem;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--bg-3);
  color: var(--text-1);
  border: 1px solid var(--border);
}

.rm-chip-accent {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.rm-subrace {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.rm-subrace:last-child {
  border-bottom: none;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* ── Panel: Culture ────────────────────────────────────── */
.culture-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.culture-card {
  padding: 24px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: all var(--transition);
}

.culture-card:hover {
  border-color: var(--border-light);
}

.culture-card-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.culture-card-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--accent-dim);
  color: var(--accent);
  flex-shrink: 0;
}

.culture-values {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.value-chip {
  padding: 3px 10px;
  font-size: 0.6875rem;
  font-weight: 500;
  border-radius: var(--radius-full);
  background: var(--bg-4);
  color: var(--text-2);
}

.culture-population {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.culture-pop-bar {
  height: 4px;
  margin-top: 6px;
  border-radius: var(--radius-full);
  background: var(--bg-4);
  overflow: hidden;
}

.pop-segment {
  height: 100%;
  background: var(--accent);
}

/* Culture visual renderer */
.cv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 20px;
  padding: 4px;
}

.cv-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0;
  overflow: hidden;
  transition: all 0.2s ease;
  position: relative;
}

.cv-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--cv-color, var(--accent));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.cv-card:hover {
  border-color: var(--cv-color, var(--accent));
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.cv-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 12px;
}

.cv-card-icon {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: color-mix(in srgb, var(--cv-color, var(--accent)) 15%, transparent);
  color: var(--cv-color, var(--accent));
  flex-shrink: 0;
}

.cv-card-title-wrap {
  flex: 1;
  min-width: 0;
}

.cv-card-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-1);
  line-height: 1.3;
}

.cv-type-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--cv-color, var(--accent)) 15%, transparent);
  color: var(--cv-color, var(--accent));
  margin-top: 4px;
  letter-spacing: 0.02em;
}

.cv-card-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.cv-card:hover .cv-card-actions {
  opacity: 1;
}

.cv-card-desc {
  padding: 0 20px 12px;
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--text-2);
}

.cv-values {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 20px 14px;
}

.cv-value-chip {
  padding: 3px 12px;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 999px;
  background: color-mix(in srgb, var(--cv-color, var(--accent)) 12%, transparent);
  color: var(--cv-color, var(--accent));
  border: 1px solid color-mix(in srgb, var(--cv-color, var(--accent)) 25%, transparent);
}

.cv-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  margin: 0 20px 14px;
  background: var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.cv-info-item {
  background: var(--bg-1);
  padding: 10px 12px;
}

.cv-info-item:only-child,
.cv-info-grid>.cv-info-item:nth-last-child(1):nth-child(odd) {
  grid-column: 1 / -1;
}

.cv-info-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.cv-info-text {
  font-size: 0.78rem;
  color: var(--text-2);
  line-height: 1.45;
}

.cv-section {
  padding: 0 20px 14px;
}

.cv-section-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-3);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.cv-section-text {
  font-size: 0.8rem;
  color: var(--text-2);
  line-height: 1.5;
  margin: 0;
}

.cv-taboos {
  padding: 0 20px 14px;
}

.cv-taboo-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.cv-taboo-chip {
  padding: 3px 10px;
  font-size: 0.7rem;
  font-weight: 500;
  border-radius: 999px;
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.cv-festivals {
  padding: 0 20px 14px;
}

.cv-festival-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
  margin-top: 6px;
  background: var(--bg-3);
  border-radius: var(--radius);
  border-left: 3px solid var(--cv-color, var(--accent));
}

.cv-festival-name {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-1);
}

.cv-festival-desc {
  font-size: 0.72rem;
  color: var(--text-3);
  line-height: 1.4;
}

.cv-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.cv-link-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  font-size: 0.68rem;
  font-weight: 500;
  border-radius: 999px;
  background: var(--bg-3);
  color: var(--text-2);
  border: 1px solid var(--border);
}

.cv-link-country {
  background: rgba(168, 85, 247, 0.1);
  color: #a855f7;
  border-color: rgba(168, 85, 247, 0.2);
}

.cv-link-city {
  background: rgba(59, 130, 246, 0.1);
  color: #3b82f6;
  border-color: rgba(59, 130, 246, 0.2);
}

/* Culture distribution bar in country cards */
.cv-distribution-bar {
  display: flex;
  height: 8px;
  width: 100%;
  border-radius: var(--radius-full);
  overflow: hidden;
  background: var(--bg-4);
  margin: 8px 0 4px;
}

.cv-dist-segment {
  height: 100%;
  transition: width 0.3s ease;
  position: relative;
}

.cv-dist-segment:first-child {
  border-radius: var(--radius-full) 0 0 var(--radius-full);
}

.cv-dist-segment:last-child {
  border-radius: 0 var(--radius-full) var(--radius-full) 0;
}

.cv-dist-segment:only-child {
  border-radius: var(--radius-full);
}

.cv-dist-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.cv-dist-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  color: var(--text-2);
}

.cv-dist-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Panel: Timeline ───────────────────────────────────── */
/* .timeline-view — reserved */

.timeline-era {
  margin-bottom: 8px;
}

.era-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--accent);
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.era-label .text-muted {
  font-weight: 400;
}

.timeline-line {
  position: relative;
  padding-left: 32px;
  margin-bottom: 24px;
}

.timeline-line::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 10px;
  width: 2px;
  background: var(--border);
}

.timeline-event {
  position: relative;
  padding: 16px 0;
}

.event-dot {
  position: absolute;
  left: -28px;
  top: 22px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-0);
}

.importance-medium .event-dot {
  background: var(--blue);
}

.event-content {
  padding: 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all var(--transition);
}

.event-content:hover {
  border-color: var(--border-light);
}

.event-year {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.event-content h4 {
  margin-bottom: 6px;
}

.event-content p {
  margin-bottom: 8px;
}

/* ── Visual Timeline (EntityPanel) ─────────────────────── */
.tl-visual {
  position: relative;
  padding: 16px 0 16px 40px;
}

.tl-visual::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 18px;
  width: 2px;
  background: linear-gradient(180deg, var(--accent) 0%, var(--border) 30%, var(--border) 70%, var(--accent) 100%);
}

/* Era block */
.tl-era-block {
  position: relative;
  margin-bottom: 8px;
}

.tl-era-header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin-left: -40px;
  padding-left: 48px;
  background: linear-gradient(90deg, rgba(124, 92, 252, 0.12) 0%, transparent 100%);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
}

.tl-era-header::before {
  content: '';
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--accent);
  border: 2px solid var(--bg-1);
  z-index: 1;
}

.tl-era-name {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--accent);
}

.tl-era-range {
  font-size: 0.75rem;
  color: var(--text-3);
  font-weight: 500;
}

/* Single event item */
.tl-event {
  position: relative;
  margin-bottom: 12px;
  animation: tlFadeIn 0.3s ease;
}

@keyframes tlFadeIn {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.tl-event::before {
  content: '';
  position: absolute;
  left: -28px;
  top: 18px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-3);
  border: 2px solid var(--bg-1);
  z-index: 1;
  transition: all var(--transition);
}

.tl-event:hover::before {
  transform: scale(1.3);
}

/* Importance colors */
.tl-event[data-importance="low"]::before {
  background: var(--text-3);
}

.tl-event[data-importance="medium"]::before {
  background: var(--blue);
}

.tl-event[data-importance="high"]::before {
  background: #f59e0b;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.4);
}

.tl-event[data-importance="critical"]::before,
.tl-event[data-importance="world_changing"]::before {
  background: #ef4444;
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

/* Source entity (auto-generated from world) */
.tl-event[data-source]::before {
  border-radius: 2px;
}

.tl-event-card {
  padding: 12px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all var(--transition);
  cursor: default;
}

.tl-event-card:hover {
  border-color: var(--border-light);
  background: var(--bg-3);
}

.tl-event-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.tl-event-year {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
  white-space: nowrap;
  padding: 2px 8px;
  background: rgba(124, 92, 252, 0.12);
  border-radius: var(--radius-sm);
}

.tl-event-type {
  font-size: 0.625rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.tl-event-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-1);
  margin-bottom: 4px;
}

.tl-event-desc {
  font-size: 0.8125rem;
  color: var(--text-2);
  line-height: 1.45;
}

.tl-event-source {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.625rem;
  color: var(--accent);
  opacity: 0.7;
  margin-top: 6px;
}

/* No-era events section */
.tl-section-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-2);
  padding: 8px 0;
  margin-bottom: 8px;
  border-bottom: 1px dashed var(--border);
}

/* Empty state */
.tl-empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-3);
}

.tl-empty i {
  opacity: 0.2;
  margin-bottom: 12px;
}

/* ── Panel: Characters ─────────────────────────────────── */
.characters-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.character-card {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 20px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: all var(--transition);
}

.character-card:hover {
  border-color: var(--border-light);
}

.character-avatar {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: #fff;
  flex-shrink: 0;
}

.character-info {
  flex: 1;
}

.character-name {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.character-info>p {
  margin-bottom: 10px;
}

.character-traits {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.trait {
  padding: 3px 10px;
  font-size: 0.6875rem;
  font-weight: 500;
  border-radius: var(--radius-full);
}

.trait-positive {
  background: var(--green-dim);
  color: var(--green);
}

.trait-negative {
  background: var(--red-dim);
  color: var(--red);
}

.trait-minor {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-3);
}

/* ── Panel: Magic ──────────────────────────────────────── */
.magic-system-info {
  margin-bottom: 24px;
}

.system-card {
  padding: 24px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.system-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--accent);
}

.system-card-header h3 {
  color: var(--text-1);
}

.system-card p {
  font-size: 0.875rem;
}

.abilities-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.ability-card {
  padding: 20px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all var(--transition);
}

.ability-card:hover {
  border-color: var(--border-light);
}

.ability-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.ability-rank {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 800;
  flex-shrink: 0;
}

.rank-s {
  background: var(--red-dim);
  color: var(--red);
}

.rank-a {
  background: var(--yellow-dim);
  color: var(--yellow);
}

.rank-b {
  background: var(--blue-dim);
  color: var(--blue);
}

.ability-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 14px;
  padding: 10px;
  background: var(--bg-3);
  border-radius: var(--radius-sm);
}

.ability-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  font-size: 0.875rem;
  font-weight: 600;
}

.ability-stat .text-muted {
  font-weight: 400;
}

.ability-owner {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
  font-size: 0.8125rem;
}

.rank-c {
  background: var(--bg-3);
  color: var(--text-2);
}

/* ── Magic System UI ─────────────────────────────────── */
.ability-card {
  cursor: pointer;
}

.ms-rank-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ms-chip {
  padding: 3px 10px;
  border: 1px solid var(--border-light);
  border-radius: 20px;
  font-size: 0.75rem;
  color: var(--text-2);
  background: var(--bg-3);
  white-space: nowrap;
}

.ms-tier-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ms-tier-item {
  padding: 10px 14px;
  background: var(--bg-3);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}

.ms-tier-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.ms-scaling-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ms-scaling-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: var(--bg-3);
  border-radius: var(--radius-sm);
}

/* ── Panel: Generators ──────────────────────────────────── */
/* .names-generator — reserved */

.gen-tab-content {
  display: none;
}

.gen-tab-content.active {
  display: block;
}

.names-generator {
  padding: 20px;
}

.names-controls {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 28px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--border);
}

.names-controls .input-group {
  flex: 1;
}

.names-controls .btn {
  height: 42px;
}

.names-results {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.name-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 500;
  transition: background var(--transition);
}

.name-result:hover {
  background: var(--bg-2);
}

.name-result:nth-child(odd) {
  background: var(--bg-2);
}

/* ── Panel: Chapters ───────────────────────────────────── */
.chapters-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.chapters-progress .progress-bar {
  flex: 1;
}

.chapters-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chapter-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all var(--transition);
}

.chapter-item:hover {
  border-color: var(--border-light);
}

.chapter-item.ch-dragging {
  opacity: 0.45;
}

.chapter-item.ch-drag-over {
  border-color: var(--accent);
  background: var(--bg-3);
}

.chapter-drag-handle {
  flex-shrink: 0;
  opacity: 0.4;
  transition: opacity var(--transition);
}

.chapter-item:hover .chapter-drag-handle {
  opacity: 1;
}

.chapter-num {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  min-width: 24px;
}

.chapter-info {
  flex: 1;
}

.chapter-info h4 {
  font-size: 0.9375rem;
  margin-bottom: 4px;
}

.chapter-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chapter-scenes {
  display: flex;
  gap: 6px;
}

.scene-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: 0.625rem;
  font-weight: 500;
  border-radius: var(--radius-xs);
  background: var(--bg-4);
  color: var(--text-3);
}

/* ── Panel: Writing ────────────────────────────────────── */
.editor-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 120px);
  min-height: 0;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
}

.editor-tab-bar {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
  flex-shrink: 0;
}

.editor-tab {
  padding: 10px 18px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-2);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s;
}

.editor-tab:hover {
  color: var(--text-1);
}

.editor-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.editor-tab-content {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.editor-tab-content.active {
  display: flex;
}

/* Plan tab */
.editor-plan-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.editor-plan-area {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  padding: 14px 16px;
  background: transparent;
  color: var(--text-1);
  font-size: 0.92rem;
  line-height: 1.75;
  font-family: inherit;
  overflow-y: auto;
}

/* Status badges (no emojis) */
.ch-status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 5px;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s;
  user-select: none;
}

.ch-status-badge:hover {
  opacity: 0.75;
}

.ch-status-badge.ch-status-idea {
  background: rgba(130, 130, 130, .15);
  color: var(--text-2);
}

.ch-status-badge.ch-status-outline {
  background: rgba(247, 197, 94, .18);
  color: #c49a10;
}

.ch-status-badge.ch-status-draft {
  background: rgba(247, 197, 94, .18);
  color: #c49a10;
}

.ch-status-badge.ch-status-written {
  background: rgba(94, 147, 247, .18);
  color: #4e87e7;
}

.ch-status-badge.ch-status-editing {
  background: rgba(247, 147, 94, .18);
  color: #d07030;
}

.ch-status-badge.ch-status-final {
  background: rgba(74, 200, 74, .18);
  color: #3a9e3a;
}

/* Status select dropdown */
.ch-status-select {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  outline: none;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 18px 2px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.6;
  transition: opacity 0.15s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 5px center;
  background-size: 8px 5px;
}

.ch-status-select:hover {
  opacity: 0.75;
}

.ch-status-select.ch-status-idea {
  background-color: rgba(130, 130, 130, .15);
  color: var(--text-2);
}

.ch-status-select.ch-status-outline {
  background-color: rgba(247, 197, 94, .18);
  color: #c49a10;
}

.ch-status-select.ch-status-draft {
  background-color: rgba(247, 197, 94, .18);
  color: #c49a10;
}

.ch-status-select.ch-status-written {
  background-color: rgba(94, 147, 247, .18);
  color: #4e87e7;
}

.ch-status-select.ch-status-editing {
  background-color: rgba(247, 147, 94, .18);
  color: #d07030;
}

.ch-status-select.ch-status-final {
  background-color: rgba(74, 200, 74, .18);
  color: #3a9e3a;
}

.ch-status-select option {
  background: var(--bg-1);
  color: var(--text-1);
}

.editor-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.editor-container {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.floating-window {
  position: absolute;
  right: 24px;
  top: 60px;
  width: 320px;
  max-height: calc(100% - 80px);
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.editor-sidebar-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-2);
  background: var(--bg-1);
}

.editor-terms-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.editor-term-item {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  background: var(--bg-2);
  border: 1px solid var(--border);
  margin-bottom: 6px;
  cursor: default;
  position: relative;
  transition: border-color 0.15s;
}

.editor-term-item:hover {
  border-color: var(--accent);
}

.editor-term-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.editor-term-name {
  font-weight: 600;
  color: var(--text-1);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-term-def {
  color: var(--text-3);
  font-size: 0.75rem;
  line-height: 1.4;
  margin-top: 4px;
}

.editor-term-context {
  color: var(--accent);
  font-size: 0.7rem;
  margin-top: 3px;
  opacity: 0.8;
}

.editor-term-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.editor-body {
  flex: 1;
  overflow-y: auto;
}

.editor-chapter-select {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.editor-chapter-select .input {
  max-width: 320px;
  padding: 8px 12px;
  font-size: 0.8125rem;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
}

.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  color: var(--text-2);
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: all var(--transition);
}

.toolbar-btn-ai {
  width: auto;
  padding: 0 10px;
  color: var(--accent);
  border: 1px solid currentColor;
  opacity: 0.8;
}

.toolbar-btn-ai:hover {
  opacity: 1;
  background: rgba(var(--accent-rgb, 124, 92, 252), 0.1) !important;
  color: var(--accent) !important;
}

.toolbar-btn:hover {
  color: var(--text-1);
  background: var(--bg-3);
}

/* ── Editor AI overlay / result ────────────────────────── */

#editor-ai-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  border-radius: inherit;
}

.editor-ai-box {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.editor-ai-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.editor-ai-result {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-2);
  border-top: 2px solid var(--accent);
  padding: 12px 16px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 260px;
  overflow: hidden;
}

.editor-ai-result-preview {
  flex: 1;
  overflow-y: auto;
  font-size: 0.85rem;
  color: var(--text-2);
  white-space: pre-wrap;
  line-height: 1.55;
  max-height: 180px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--bg-1);
}

.editor-ai-result-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}



.toolbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.editor-body {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
  min-height: 200px;
  font-size: 1rem;
  line-height: 1.8;
  color: var(--text-1);
  outline: none;
}

.editor-body p {
  margin-bottom: 16px;
}

.editor-body strong {
  color: var(--accent);
  font-weight: 600;
}

.editor-body em {
  color: var(--text-2);
}

/* ── Writing Tabs (Editor / Terms) ─────────────────────── */
.writing-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
}

.writing-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-3);
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.writing-tab-btn:hover {
  color: var(--text-1);
  background: var(--bg-3);
}

.writing-tab-btn.active {
  color: var(--accent);
  background: var(--accent-dim);
  border-color: var(--accent);
}

.writing-tab-content {
  display: none;
}

.writing-tab-content.active {
  display: block;
}

/* ── Terms ─────────────────────────────────────────────── */
.terms-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.terms-list {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.terms-empty {
  text-align: center;
  padding: 48px 20px;
}

.term-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color var(--transition);
}

.term-card:hover {
  border-color: var(--accent);
}

.term-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
}

.term-card-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--accent);
}

.term-card-actions {
  display: flex;
  gap: 4px;
}

.term-card-body {
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.term-field {
  display: flex;
  gap: 8px;
  font-size: 0.8125rem;
  line-height: 1.5;
}

.term-label {
  flex-shrink: 0;
  font-weight: 500;
  color: var(--text-3);
  min-width: 90px;
}

.term-value {
  color: var(--text-2);
}

/* ── Panel: Memory ─────────────────────────────────────── */
.memory-search {
  margin-bottom: 16px;
}

.memory-search .search-box {
  max-width: 400px;
}

.memory-categories {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
}

.cat-chip {
  padding: 6px 14px;
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-2);
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition);
}

.cat-chip:hover {
  border-color: var(--accent);
  color: var(--text-1);
}

.cat-chip.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.memory-facts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.memory-stats-bar {
  display: flex;
  gap: 16px;
  padding: 8px 0;
  margin-bottom: 12px;
  font-size: 0.8125rem;
  color: var(--text-3);
}

.memory-stat-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.fact-card {
  padding: 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition);
}

.fact-card:hover {
  border-color: var(--accent-dim);
}

.fact-card.fact-locked {
  border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 4%, var(--bg-2));
}

.fact-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.fact-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition);
}

.fact-card:hover .fact-actions {
  opacity: 1;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-icon:hover {
  background: var(--bg-3);
  color: var(--text-1);
}

.btn-fact-delete:hover {
  color: var(--red);
  background: var(--red-dim);
}

.btn-fact-lock:hover {
  color: var(--accent);
}

.fact-source-ai {
  display: inline-block;
  font-size: 0.625rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 1px 5px;
  border-radius: var(--radius-full);
  margin-left: 6px;
  letter-spacing: 0.03em;
  vertical-align: middle;
}

.fact-card.fact-warning {
  border-color: rgba(251, 191, 36, 0.3);
  background: var(--yellow-dim);
}

.fact-category {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.fact-key {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  font-family: 'SFMono-Regular', 'Fira Code', monospace;
  margin-bottom: 4px;
}

.fact-value {
  font-size: 0.875rem;
  color: var(--text-2);
  line-height: 1.5;
}

/* ── Panel: Analyzer ───────────────────────────────────── */
.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px;
  text-align: center;
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 28px;
  color: var(--text-3);
  transition: all var(--transition);
}

.drop-zone:hover {
  border-color: var(--accent);
  color: var(--text-2);
}

.drop-zone h4 {
  color: var(--text-1);
}

.analysis-stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.analysis-stat {
  text-align: center;
  padding: 18px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.analysis-stat-num {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.analysis-issues h4 {
  margin-bottom: 12px;
}

.issue-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 4px;
}

.issue-warning {
  background: var(--yellow-dim);
  color: var(--yellow);
}

.issue-info {
  background: var(--blue-dim);
  color: var(--blue);
}

/* ── Panel: Genre ──────────────────────────────────────── */

/* Genre selector */
.genre-select {
  background: var(--bg-2);
  color: var(--text-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.8125rem;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
}
.genre-select:hover,
.genre-select:focus { border-color: var(--accent); }
.genre-select-sm { padding: 4px 8px; font-size: 0.75rem; }

/* Genre tabs */
.genre-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.genre-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-2);
  font-size: 0.8125rem;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}
.genre-tab-btn:hover { color: var(--text-1); background: var(--bg-2); }
.genre-tab-btn.active { color: var(--accent); background: rgba(124, 92, 252, 0.1); font-weight: 600; }

/* Tab content */
.genre-tab-content { display: none; }
.genre-tab-content.active { display: block; }

/* Empty state */
.genre-empty {
  color: var(--text-2);
  font-size: 0.8125rem;
  text-align: center;
  padding: 32px 16px;
  opacity: 0.7;
}

/* Tropes */
.tropes-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.trope-item {
  padding: 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all var(--transition);
}

.trope-item:hover {
  border-color: var(--border-light);
}

.trope-header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-1);
  margin-bottom: 6px;
}

.trope-header i {
  color: var(--accent);
}

.trope-subversion {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 24px;
}

.trope-subversion i {
  color: var(--accent);
  flex-shrink: 0;
}

/* Scene cards */
.scenes-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.scene-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color var(--transition);
}
.scene-card:hover { border-color: var(--accent); }

.scene-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(124, 92, 252, 0.06);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-1);
}
.scene-card-header i { color: var(--accent); }

.scene-card-body { padding: 14px 16px; }

.scene-section { margin-bottom: 10px; }
.scene-section:last-child { margin-bottom: 0; }

.scene-label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: 4px;
}

.scene-section p {
  font-size: 0.8125rem;
  color: var(--text-2);
  line-height: 1.6;
  margin: 0;
  white-space: pre-line;
}

/* Atmosphere */
.atmosphere-section {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 8px;
}
.atmosphere-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.atmosphere-header h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-1);
  margin: 0;
}

.atmosphere-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.atmosphere-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.atmosphere-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--text-1);
  margin-bottom: 8px;
}
.atmosphere-card-header i { color: var(--accent); }

.atmosphere-items {
  list-style: none;
  padding: 0;
  margin: 0;
}
.atmosphere-items li {
  font-size: 0.75rem;
  color: var(--text-2);
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.atmosphere-items li:last-child { border-bottom: none; }

/* Tips */
.tips-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tips-section {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}
.tips-section h4 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-1);
  margin: 0 0 10px 0;
}
.tips-section h4 i { color: var(--accent); }
.tips-section-warn h4 i { color: var(--warning, #fbbf24); }

.tips-section ul {
  list-style: disc;
  padding-left: 20px;
  margin: 0;
}
.tips-section ul li {
  font-size: 0.8125rem;
  color: var(--text-2);
  padding: 3px 0;
  line-height: 1.5;
}

/* Genre extra sections (romance, cultivation, system) */
.genre-extra-section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.genre-extra-section h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-1);
  margin: 0 0 12px 0;
}

/* Romance beats */
.beats-list {
  list-style: decimal;
  padding-left: 24px;
  margin: 8px 0 0 0;
}
.beats-list li {
  font-size: 0.8125rem;
  color: var(--text-2);
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  line-height: 1.5;
}
.beats-list li:last-child { border-bottom: none; }

/* Cultivation stages */
.cultivation-stages-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
.cultivation-stage {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.cultivation-stage-num {
  min-width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(124, 92, 252, 0.12);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.875rem;
  border-radius: 50%;
  flex-shrink: 0;
}
.cultivation-stage-body { flex: 1; }
.cultivation-stage-name {
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--text-1);
  margin-bottom: 2px;
}
.cultivation-stage-desc {
  font-size: 0.75rem;
  color: var(--text-2);
  line-height: 1.5;
}
.cultivation-stage-chapters {
  display: inline-block;
  margin-top: 4px;
  font-size: 0.6875rem;
  color: var(--accent);
  opacity: 0.8;
}

/* System message templates */
.system-messages-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}
.system-msg-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.system-msg-label {
  padding: 8px 12px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  background: rgba(124, 92, 252, 0.06);
  border-bottom: 1px solid var(--border);
}
.system-msg-template {
  margin: 0;
  padding: 12px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.75rem;
  color: var(--text-2);
  white-space: pre;
  overflow-x: auto;
  line-height: 1.5;
}

/* Combat */
.combat-type-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.combat-type-btn {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 0.75rem;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}
.combat-type-btn:hover { color: var(--text-1); border-color: var(--border-light); }
.combat-type-btn.active { color: var(--accent); border-color: var(--accent); background: rgba(124, 92, 252, 0.08); font-weight: 600; }

.combat-tips-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.combat-tip-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  color: var(--text-2);
  line-height: 1.5;
}
.combat-tip-item i {
  color: var(--accent);
  flex-shrink: 0;
  margin-top: 2px;
}


/* ═══════════════════════════════════════════════════════════
   Proofreader — TipTap decorations & tooltip
   ═══════════════════════════════════════════════════════════ */

/* Волнистое подчёркивание */
.proofread-error {
  text-decoration-line: underline;
  text-decoration-style: wavy;
  text-decoration-color: rgba(248, 113, 113, 0.85);
  text-underline-offset: 3px;
}
.proofread-error-spelling { text-decoration-color: rgba(248, 113, 113, 0.85); }
.proofread-error-grammar  { text-decoration-color: rgba(251, 191, 36, 0.85); }
.proofread-error-style    { text-decoration-color: rgba(124, 92, 252, 0.85); text-decoration-style: dotted; }

.proofread-term {
  border-bottom: 1.5px dashed rgba(124, 92, 252, 0.6);
  cursor: help;
}

/* Слово подсвечивается при наведении */
[data-proof].proof-active {
  background: rgba(248, 113, 113, 0.15);
  border-radius: 3px;
}
[data-proof="term"].proof-active {
  background: rgba(124, 92, 252, 0.12);
}

/* ── Попап корректора ─────────────────────────────────────── */

.proof-tooltip {
  position: fixed;
  z-index: 9999;
  width: 280px;
  background: #181832;
  border-radius: 10px;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.07),
    0 8px 16px rgba(0, 0, 0, 0.5),
    0 24px 48px rgba(0, 0, 0, 0.4);
  font-family: var(--font);
  color: var(--text-1);
  animation: proofIn .15s ease;
  overflow: hidden;
  pointer-events: auto;
}

/* Карет-стрелка */
.proof-tooltip::after {
  content: '';
  position: absolute;
  top: -4px;
  left: var(--caret-x, 16px);
  width: 8px;
  height: 8px;
  background: #181832;
  box-shadow: -1px -1px 0 rgba(255, 255, 255, 0.07);
  transform: rotate(45deg);
  border-radius: 1px;
}

.proof-tooltip--error { border-top: 2px solid var(--red); }
.proof-tooltip--term  { border-top: 2px solid var(--accent); }

@keyframes proofIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Бейдж — тип */
.proof-tooltip__badge {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 14px 5px;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.proof-tooltip--error .proof-tooltip__badge { color: var(--red); }
.proof-tooltip--term  .proof-tooltip__badge { color: var(--accent); }
.proof-tooltip__badge svg { flex-shrink: 0; }

/* Текст сообщения */
.proof-tooltip__msg {
  padding: 0 14px 12px;
  font-size: 0.84rem;
  font-weight: 400;
  line-height: 1.6;
  color: var(--text-1, #e8e8f0);
}

/* Разделитель */
.proof-tooltip__sep {
  height: 1px;
  background: rgba(255, 255, 255, 0.06);
}

/* Кнопки замены */
.proof-tooltip__fixes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 14px 12px;
}

.proof-tooltip__fix {
  all: unset;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  padding: 5px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1;
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: var(--red, #f87171);
  transition: background 0.12s, color 0.12s, border-color 0.12s, transform 0.1s;
}
.proof-tooltip__fix:hover {
  background: var(--red, #f87171);
  border-color: var(--red, #f87171);
  color: #fff;
  transform: translateY(-1px);
}
.proof-tooltip__fix:active {
  transform: translateY(0);
}

/* Термин */
.proof-tooltip__term-name {
  padding: 6px 14px 2px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-1, #e8e8f0);
}
.proof-tooltip__term-def {
  padding: 2px 14px 12px;
  font-size: 0.8rem;
  line-height: 1.55;
  color: var(--text-2, #9494b8);
}

/* ── TipTap Placeholder ───────────────────────────────────── */
.editor-body .ProseMirror p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  color: var(--text-3);
  pointer-events: none;
  height: 0;
  font-style: italic;
  opacity: 0.55;
}
/* Не показывать placeholder на НЕ-первых пустых параграфах */
.editor-body .ProseMirror p.is-empty:not(.is-editor-empty)::before {
  content: none;
}

/* ═══════════════════════════════════════════════════════════
   Backup Manager — вкладка бэкапов
   ═══════════════════════════════════════════════════════════ */

.backup-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.backup-counter {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 7px;
  letter-spacing: 0.03em;
}

/* Шапка вкладки */
.backup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
  flex-wrap: wrap;
}
.backup-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Список */
.backup-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

/* Пустое состояние */
.backup-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 48px 24px;
  color: var(--text-3);
  text-align: center;
}
.backup-empty p { margin: 0; font-size: 0.88rem; }
.backup-empty-hint {
  font-size: 0.78rem !important;
  opacity: 0.6;
  max-width: 340px;
}

/* Строка бэкапа */
.backup-entry {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}
.backup-entry:last-child { border-bottom: none; }
.backup-entry:hover { background: var(--surface); }
.backup-entry--preview { background: var(--surface); }

.backup-entry-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.backup-entry-time {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-2);
  font-size: 0.82rem;
}
.backup-entry-date { font-weight: 500; }
.backup-entry-clock { opacity: 0.6; }
.backup-entry-info {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Экшны */
.backup-entry-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}
.btn-xs {
  font-size: 0.75rem;
  padding: 3px 9px;
  height: 26px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.backup-btn-delete {
  color: var(--text-3);
  padding: 3px 6px;
}
.backup-btn-delete:hover { color: var(--red); }
.backup-btn-preview { color: var(--text-2); }

/* Бейдж триггера */
.backup-trigger-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 4px;
  opacity: 0.85;
}
.backup-trigger-badge--auto    { background: rgba(124,92,252,0.12); color: var(--accent); }
.backup-trigger-badge--manual  { background: rgba(52,211,153,0.12); color: #34d399; }
.backup-trigger-badge--leave   { background: rgba(251,191,36,0.12);  color: #fbbf24; }
.backup-trigger-badge--chapter { background: rgba(96,165,250,0.12);  color: #60a5fa; }

.backup-words {
  font-size: 0.76rem;
  color: var(--text-3);
}

/* Превью */
.backup-preview-body {
  margin-top: 10px;
  padding: 12px 14px;
  background: var(--bg2);
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.85rem;
  line-height: 1.7;
  color: var(--text-1);
  max-height: 280px;
  overflow-y: auto;
}
.backup-preview-body p { margin: 0 0 0.5em; }
.backup-preview-body h2,
.backup-preview-body h3,
.backup-preview-body h4 { margin: 0.8em 0 0.3em; font-weight: 700; }
.backup-preview-body blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 0.5em 0;
  opacity: 0.8;
}

/* ═══════════════════════════════════════════════════════════
   Panel: Market Analytics — Аналитика рынка
   ═══════════════════════════════════════════════════════════ */

/* Tabs */
.ma-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.ma-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-2);
  font-size: 0.8125rem;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}
.ma-tab-btn:hover { color: var(--text-1); background: var(--bg-2); }
.ma-tab-btn.active { color: var(--accent); background: var(--accent-dim); font-weight: 600; }

.ma-tab-content { display: none; }
.ma-tab-content.active { display: block; }

/* Stats grid */
.ma-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.ma-stat-card {
  text-align: center;
  padding: 20px 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color 0.15s ease;
}
.ma-stat-card:hover { border-color: var(--border-hover); }
.ma-stat-num {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}
.ma-stat-label {
  font-size: 0.75rem;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Sections */
.ma-section {
  margin-bottom: 24px;
}
.ma-section h3 {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-1);
  margin-bottom: 12px;
}

/* Genre bar rows */
.ma-list-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ma-genre-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.ma-genre-info {
  min-width: 140px;
  flex-shrink: 0;
}
.ma-genre-name {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-1);
}
.ma-genre-meta {
  font-size: 0.7rem;
  color: var(--text-3);
}
.ma-bar-track {
  flex: 1;
  height: 6px;
  background: var(--bg-3);
  border-radius: 3px;
  overflow: hidden;
}
.ma-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* Tags cloud */
.ma-tags-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.ma-tag {
  display: inline-block;
  padding: 4px 10px;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
}
.ma-tag-positive {
  background: var(--green-dim);
  color: var(--green);
}
.ma-tag-negative {
  background: var(--red-dim);
  color: var(--red);
}

/* Genre chips (comparison) */
.ma-comparison-controls {
  margin-bottom: 16px;
}
.ma-comparison-controls label {
  display: block;
  font-size: 0.8125rem;
  color: var(--text-2);
  margin-bottom: 8px;
}
.ma-genre-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.ma-chip {
  padding: 5px 12px;
  font-size: 0.75rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.15s ease;
}
.ma-chip:hover { border-color: var(--accent); color: var(--text-1); }
.ma-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* Comparison table */
.ma-table-container { overflow-x: auto; }
.ma-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}
.ma-table th {
  text-align: left;
  padding: 8px 12px;
  color: var(--text-2);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.ma-table td {
  padding: 10px 12px;
  color: var(--text-1);
  border-bottom: 1px solid var(--border);
}
.ma-table tr:hover td { background: var(--bg-2); }
.ma-cell-genre { font-weight: 500; color: var(--accent); }

/* Author comparison — project header */
.ma-project-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.ma-project-header h3 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-1);
  margin: 0;
}
.ma-genre-badge {
  display: inline-block;
  padding: 3px 10px;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 20px;
  background: var(--accent-dim);
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Metrics grid */
.ma-metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.ma-metric-card {
  padding: 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.ma-metric-label {
  font-size: 0.75rem;
  color: var(--text-3);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.ma-metric-values {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.ma-metric-author,
.ma-metric-market { text-align: center; }
.ma-metric-val {
  display: block;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-1);
}
.ma-metric-sub {
  font-size: 0.65rem;
  color: var(--text-3);
  text-transform: uppercase;
}
.ma-metric-author .ma-metric-val { color: var(--accent); }
.ma-metric-diff {
  text-align: center;
  margin-top: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-xs);
}
.ma-diff-up { color: var(--green); background: var(--green-dim); }
.ma-diff-down { color: var(--red); background: var(--red-dim); }

/* Recommendations list (inside author tab) */
.ma-rec-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ma-rec-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  color: var(--text-1);
  line-height: 1.5;
}
.ma-rec-icon { font-size: 1.1rem; flex-shrink: 0; }

/* Recommendation cards (dedicated tab) */
.ma-recommendations-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.ma-rec-card {
  display: flex;
  gap: 12px;
  padding: 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color 0.15s ease;
}
.ma-rec-card:hover { border-color: var(--border-hover); }
.ma-rec-card-icon { font-size: 1.5rem; flex-shrink: 0; }
.ma-rec-card-body { flex: 1; min-width: 0; }
.ma-rec-card-text {
  font-size: 0.875rem;
  color: var(--text-1);
  line-height: 1.5;
}
.ma-rec-card-detail {
  font-size: 0.75rem;
  color: var(--text-3);
  margin-top: 6px;
  line-height: 1.4;
}

/* Author section placeholder */
.ma-author-section { min-height: 200px; }

.ma-market-summary {
  font-size: 0.875rem;
  color: var(--text-2);
  line-height: 1.6;
  margin: 0;
}
.ma-market-summary strong {
  color: var(--accent);
  font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════
   MOBILE OVERRIDES — panels
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* ── Country card compact ── */
  .country-card-top {
    padding: 10px 10px 0;
    gap: 8px;
  }
  .country-card-icon {
    width: 32px;
    height: 32px;
  }
  .country-card-stats {
    padding: 0 10px;
    gap: 6px;
  }
  .country-card-desc {
    padding: 0 10px;
    font-size: 0.82rem;
  }
  .country-section {
    padding: 4px 10px 8px;
  }
  .country-gov-name {
    min-width: 60px;
    font-size: 10px;
  }
  .country-race-name {
    min-width: 50px;
    font-size: 10px;
  }
  .country-grid-redesign {
    gap: 12px;
  }

  /* ── Diplomacy panel ── */
  .diplo-panel {
    padding: 8px 12px;
  }
  .diplo-summary {
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px;
  }
  .diplo-stat {
    flex: 1;
    min-width: 60px;
  }
  .diplo-stat-num {
    font-size: 16px;
  }
  .diplo-matrix-wrap {
    margin-bottom: 12px;
  }
  .diplo-matrix th,
  .diplo-matrix td {
    padding: 3px 4px;
    font-size: 10px;
  }
  .diplo-pair-header {
    gap: 6px;
  }
  .diplo-pair-country {
    font-size: 12px;
  }

  /* ── Country/City History timeline ── */
  .country-hist-wrap,
  .citylife-wrap {
    padding: 8px 12px;
  }
  .country-hist-selector,
  .citylife-selector {
    flex-wrap: wrap;
    gap: 6px;
  }
  .country-hist-selector select,
  .citylife-select {
    max-width: 100%;
    flex: 1;
  }
  .country-hist-timeline,
  .citylife-timeline {
    padding-left: 18px;
  }
  .country-hist-timeline::before,
  .citylife-timeline::before {
    left: 7px;
  }
  .country-hist-card,
  .citylife-card {
    padding: 8px 10px;
  }
  .citylife-profile {
    flex-wrap: wrap;
    padding: 10px 12px;
  }
  .citylife-profile-icon {
    width: 40px;
    height: 40px;
  }

  /* ── Races grid single column ── */
  .races-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .race-header {
    padding: 16px;
  }
  .race-body {
    padding: 14px;
  }

  /* ── List Editor ── */
  .list-editor-table th,
  .list-editor-table td {
    font-size: 11px;
    padding: 3px 4px;
  }

  /* ── Backup manager ── */
  .backup-header {
    padding: 10px 12px;
  }
  .backup-entry {
    padding: 8px 12px;
  }
  .backup-entry-meta {
    gap: 6px;
  }

  /* ── Market analytics tabs ── */
  .ma-tabs {
    gap: 2px;
    padding-bottom: 6px;
  }
  .ma-tab-btn {
    padding: 6px 10px;
    font-size: 0.75rem;
  }

  /* ── Timeline mobile compact ── */
  .tl-visual {
    padding-left: 18px;
  }
  .tl-visual::before {
    left: 7px;
  }
  .tl-event {
    padding-left: 18px;
    margin-bottom: 10px;
  }
  .tl-event::before {
    left: -4px;
  }
  .tl-event-card {
    padding: 10px 12px;
  }
  .tl-event-top {
    flex-wrap: wrap;
    gap: 4px;
  }
  .tl-event-actions {
    gap: 2px;
  }
  .tl-event-actions .btn {
    min-width: 30px;
    min-height: 30px;
  }
  .tl-era-header {
    padding: 8px 10px;
    flex-wrap: wrap;
    gap: 4px;
  }
  .tl-era-name {
    font-size: 13px;
  }
  .tl-era-actions .btn {
    min-width: 30px;
    min-height: 30px;
  }

  /* ── Grimoire (Magic) mobile compact ── */
  .grimoire-scroll {
    gap: 12px;
    padding: 8px 12px;
  }
  .grimoire-card {
    padding: 14px;
  }
  .grimoire-card-header {
    flex-wrap: wrap;
    gap: 8px;
  }
  .grimoire-card-icon {
    width: 40px;
    height: 40px;
  }
  .grimoire-card-title h3 {
    font-size: 1rem;
  }
  .grimoire-props {
    gap: 8px;
  }
  .grimoire-prop {
    flex: 1 1 100%;
  }
  .grimoire-prop-wide {
    flex: 1 1 100%;
  }
  .grimoire-prop-icon {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
  }
  .grimoire-section {
    margin-top: 12px;
  }
}
