:root {
  --pink: #fc0390;
  --pink-dark: #c1026e;
  --bg: #050505;
  --panel: #151515;
  --panel-soft: #1e1e1e;
  --border-subtle: #2a2a2a;
  --text-main: #f5f5f5;
  --text-muted: #a0a0a0;
  --shadow-soft: 0 14px 40px rgba(0, 0, 0, 0.7);
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-pill: 999px;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, rgba(252, 3, 144, 0.2), transparent 55%) #000;
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Top bar */

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.9);
  border-bottom: 1px solid var(--border-subtle);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.brand-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--pink);
  box-shadow: 0 0 14px rgba(252, 3, 144, 0.9);
}

.brand-text {
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 13px;
}

/* Tabs */

.tab-switch {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
}

.tab-btn {
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab-btn.active {
  background: var(--pink);
  color: #fff;
}

/* Layout */

.main-layout {
  flex: 1;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tab-view {
  display: none;
  flex-direction: column;
  gap: 10px;
  height: 100%;
}

.tab-view.active {
  display: flex;
}

/* Buttons */

.pill-btn {
  border-radius: var(--radius-pill);
  border: none;
  background: var(--pink);
  color: #fff;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 10px 22px rgba(252, 3, 144, 0.5);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.pill-btn.small {
  padding: 6px 10px;
  font-size: 12px;
  box-shadow: none;
}

.pill-btn.secondary {
  background: transparent;
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  box-shadow: none;
}

.pill-btn:active {
  transform: translateY(1px) scale(0.98);
  box-shadow: 0 4px 12px rgba(252, 3, 144, 0.4);
}

/* Characters view */

.primary-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.hidden {
  display: none !important;
}

.panel {
  background: rgba(10, 10, 10, 0.96);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-header {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-title {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.panel-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.panel-body {
  padding: 8px 10px;
  overflow: auto;
}

/* Character list */

.characters-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: calc(100vh - 190px);
}

.character-card {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 9px;
  border-radius: var(--radius-md);
  background: linear-gradient(90deg, rgba(252, 3, 144, 0.12), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(252, 3, 144, 0.3);
}

.character-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.character-name {
  font-weight: 700;
  font-size: 13px;
}

.character-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.character-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.gender-tag {
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.gender-tag.male { border-color: #4da6ff; color: #4da6ff; background: rgba(77, 166, 255, 0.1); }
.gender-tag.female { border-color: #ff80bf; color: #ff80bf; background: rgba(255, 128, 191, 0.1); }
.gender-tag.non-binary { border-color: #be80ff; color: #be80ff; background: rgba(190, 128, 255, 0.1); }

.age-tag {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  padding: 2px 5px;
  border-radius: 4px;
}

.origin-tag {
  font-size: 9px;
  font-weight: 800;
  padding: 2px 5px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

.origin-tag.wiki-crossover { border-color: #00ffcc; color: #00ffcc; background: rgba(0, 255, 204, 0.05); }
.origin-tag.custom-oc { border-color: #ffcc00; color: #ffcc00; background: rgba(255, 204, 0, 0.05); }
.origin-tag.pre-existing { border-color: #ff33ff; color: #ff33ff; background: rgba(255, 51, 255, 0.05); }

.character-role {
  font-size: 12px;
  color: var(--pink);
  font-weight: 600;
}

.character-notes {
  font-size: 11px;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.character-relations {
  font-size: 10px;
  color: var(--pink);
  margin-top: 2px;
  font-style: italic;
}

/* Field Header and Text Buttons */
.field-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.text-link-btn {
  background: transparent;
  border: none;
  color: var(--pink);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0;
  letter-spacing: 0.05em;
}

.text-link-btn:hover {
  text-decoration: underline;
}

/* Toggle and delete */

.character-toggle {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 64px;
}

.character-actions {
  display: flex;
  gap: 8px;
}

.character-action-btn {
  border: none;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  font-size: 16px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s ease;
}

.character-action-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.1);
}

.character-action-btn.delete:hover {
  color: #fff;
  background: var(--pink);
}

.character-action-btn:active {
  transform: scale(0.9);
}

.toggle-label {
  font-size: 11px;
  color: var(--text-muted);
}

/* Simulation view */

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

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

.cast-chip {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(252, 3, 144, 0.12);
  border: 1px solid rgba(252, 3, 144, 0.4);
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.cast-chip:hover {
  background: rgba(252, 3, 144, 0.2);
}

.cast-chip.deceased {
  text-decoration: line-through;
  opacity: 0.5;
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
}

.cast-chip.deceased::after {
  content: " ✕";
  color: #ff4d4d;
  font-weight: bold;
}

/* Active Roster UI */
.roster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: var(--radius-md);
  margin-bottom: 15px;
}

.roster-card {
  position: relative;
  background: var(--panel-soft);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 8px;
  text-align: center;
  transition: all 0.3s ease;
  overflow: hidden;
}

.roster-card .name {
  font-size: 11px;
  font-weight: 700;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.roster-card .talent {
  font-size: 9px;
  color: var(--pink);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.roster-card.deceased {
  filter: grayscale(1) contrast(0.8);
  opacity: 0.6;
  border-color: #ff4d4d;
}

.roster-card.deceased::before {
  content: "✕";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 60px;
  color: rgba(255, 77, 77, 0.8);
  z-index: 2;
  font-weight: 100;
  pointer-events: none;
}

.roster-card .status-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.6);
  font-size: 8px;
  font-weight: 800;
  text-transform: uppercase;
  padding: 2px 0;
}

.roster-card.deceased .status-label {
  background: #ff4d4d;
  color: white;
}

.simulation-active-body {
  border-bottom: 1px solid var(--border-subtle);
}

.panel-inner {
  border-top: 1px solid var(--border-subtle);
}

.cast-chip:not(.deceased)::after {
  content: " ✎";
  font-size: 9px;
  opacity: 0.6;
}

.scenario-body {
  max-height: calc(100vh - 280px);
  display: flex;
  flex-direction: column;
}

.scenario-output {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-main);
}

.game-controls {
  padding: 8px 12px;
  background: rgba(252, 3, 144, 0.05);
  border-bottom: 1px solid var(--border-subtle);
}

.game-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#game-phase-label {
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--pink);
}

.fte-input-wrap {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-top: 1px solid rgba(252, 3, 144, 0.2);
  padding-top: 8px;
}

.fte-input-wrap label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
}

.fte-input-wrap textarea {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 8px;
  color: var(--text-main);
  font-size: 12px;
  resize: vertical;
  min-height: 40px;
}

.fte-input-wrap textarea:focus {
  outline: none;
  border-color: var(--pink);
}

.game-event {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px dashed var(--border-subtle);
}

.game-event:last-child {
  border-bottom: none;
}

.phase-header {
  font-size: 18px;
  font-weight: 800;
  color: var(--pink);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-style: italic;
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* Planner Sheet */
.planner-sheet {
  max-width: 600px;
}

.planner-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  margin-bottom: 12px;
}

.planner-tabs .tab-btn {
  flex: 1;
  text-align: center;
}

.planner-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: rgba(255, 255, 255, 0.02);
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
}

/* Modals */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-sheet {
  width: 100%;
  max-width: 520px;
  background: #060606;
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border-subtle);
  box-shadow: 0 -16px 40px rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}

.modal-header {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 14px;
  font-weight: 600;
}

.modal-body {
  padding: 10px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

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

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
}

/* Wiki modal */

.wiki-textarea {
  width: 100%;
  min-height: 140px;
  flex-shrink: 0;
  resize: vertical;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: #050505;
  color: var(--text-main);
  padding: 8px;
  font-size: 12px;
}

.wiki-preview {
  margin-top: 6px;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  font-size: 12px;
}

/* Custom character form */

.custom-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  flex: 1;
}

.field-row {
  display: flex;
  gap: 10px;
}

.field select {
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  padding: 7px 8px;
  font-size: 12px;
  background: #050505;
  color: var(--text-main);
}

.field span {
  color: var(--text-muted);
}

.field input,
.field textarea {
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  padding: 7px 8px;
  font-size: 12px;
  background: #050505;
  color: var(--text-main);
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.checkbox-field input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--pink);
}

.modal-intro {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* Prebuilt list */

.prebuilt-list {
  max-height: 60vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.prebuilt-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  font-size: 12px;
}

.prebuilt-info {
  display: flex;
  flex-direction: column;
}

.prebuilt-name {
  font-weight: 600;
}

.prebuilt-meta {
  font-size: 11px;
  color: var(--text-muted);
}

/* Special tools for Mastermind selection */
.special-tools {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  border: 1px dashed var(--border-subtle);
}

.special-tools .pill-btn {
  font-size: 10px;
  padding: 4px 8px;
}

/* Relationship Editor */
.relationships-editor-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 120px;
  overflow-y: auto;
  padding: 4px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
}

.relationship-edit-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.relationship-edit-row select {
  flex: 1;
  min-width: 0;
}

.btn-remove-rel {
  background: transparent;
  border: none;
  color: #ff4d4d;
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Saved casts list */

.saved-casts-list {
  max-height: 60vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.saved-cast-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  font-size: 12px;
}

.saved-cast-info {
  display: flex;
  flex-direction: column;
}

.saved-cast-name {
  font-weight: 600;
}

.saved-cast-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.saved-cast-actions {
  display: flex;
  gap: 6px;
}

/* Loading overlay */

.fanfiction-display {
  user-select: text;
  font-size: 15px;
}

.fanfiction-display h1, .fanfiction-display h2, .fanfiction-display h3 {
  color: var(--pink);
  font-family: system-ui;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.loading-overlay.hidden {
  display: none;
}

.loading-card {
  padding: 12px 16px;
  border-radius: 16px;
  background: #050505;
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.spinner {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--pink);
  animation: spin 0.8s linear infinite;
}

.loading-text {
  font-size: 12px;
  color: var(--text-muted);
}

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

/* Mobile tweaks */

@media (min-width: 768px) {
  .main-layout {
    max-width: 720px;
    margin: 0 auto;
  }

  .modal-backdrop {
    align-items: center;
  }

  .modal-sheet {
    border-radius: 18px;
  }
}