:root {
  --bg: #f4f2ee;
  --panel-bg: #ffffff;
  --text: #1c1c1c;
  --text-muted: #6b6b6b;
  --border: #d8d4cc;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --accent-white-fill: #f8fafc;
  --accent-white-line: #2b2b2b;
  --black-accent: #1f1f23;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --panel-bg: #212327;
    --text: #ecebe8;
    --text-muted: #9a9a9a;
    --border: #35373b;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --accent-white-fill: #e6e6e6;
    --accent-white-line: #e6e6e6;
    --black-accent: #d4d4d8;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title h1 {
  margin: 0;
  font-size: 1.6rem;
}
.subtitle {
  margin: 4px 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.topbar-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 180px;
}
.progress-track {
  flex: 1;
  max-width: 320px;
  height: 10px;
  border-radius: 5px;
  background: var(--border);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #6366f1, #22c55e);
  transition: width 0.3s ease;
}
#global-progress-label {
  font-size: 0.9rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.save-status {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 60px;
  text-align: right;
}

.btn {
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
}
.btn:hover { border-color: var(--text-muted); }
.btn-primary {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}
.btn-primary:hover { background: #1d4ed8; }

.faction-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(490px, 1fr));
  gap: 28px;
  padding: 32px;
  max-width: 1600px;
  margin: 0 auto;
}
@media (max-width: 560px) {
  .faction-grid { padding: 20px; gap: 20px; }
}

.faction-panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.faction-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}
.faction-header h2 {
  margin: 0;
  font-size: 1.4rem;
}
.faction-header .faction-subtitle {
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.faction-count {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.tier-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px dashed var(--border);
}
.tier-row:first-of-type { border-top: none; }

.tier-label {
  width: 22px;
  flex-shrink: 0;
  line-height: 48px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
}

.slots {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
}

.slot {
  position: relative;
  width: 54px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.slot-shape-btn {
  position: relative;
  width: 48px;
  height: 48px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  display: block;
}
.slot-shape-btn svg { width: 100%; height: 100%; display: block; }
.slot-shape-btn:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }

.slot-icon-thumb {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--panel-bg);
  background: var(--panel-bg);
}

.slot-edit-btn {
  position: absolute;
  bottom: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.slot:hover .slot-edit-btn,
.slot:focus-within .slot-edit-btn {
  opacity: 1;
}

.slot-label {
  font-size: 11px;
  line-height: 1.25;
  color: var(--text-muted);
  width: 68px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  overflow-wrap: break-word;
  text-align: center;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-backdrop[hidden] {
  display: none;
}
.modal {
  background: var(--panel-bg);
  border-radius: 14px;
  padding: 26px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
.modal h2 { margin: 0 0 4px; font-size: 1.3rem; }
.modal-subtitle { margin: 0 0 18px; font-size: 0.85rem; color: var(--text-muted); }

.field {
  display: block;
  margin-bottom: 16px;
  font-size: 0.9rem;
}
.field > span {
  display: block;
  margin-bottom: 5px;
  color: var(--text-muted);
}
.field input[type="text"],
.field input[type="date"] {
  width: 100%;
  padding: 9px 11px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
.anim-inputs {
  display: flex;
  align-items: center;
  gap: 8px;
}
.anim-inputs input[type="number"] {
  width: 72px;
  padding: 9px 11px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
.anim-sep {
  color: var(--text-muted);
}

.icon-field {
  display: flex;
  align-items: center;
  gap: 10px;
}
.icon-preview {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
}
.icon-placeholder {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  color: var(--text-muted);
  text-align: center;
}
.icon-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.icon-buttons .btn { padding: 5px 10px; font-size: 0.8rem; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}
