:root {
  --bg: #0b1120;
  --panel: #111827;
  --panel-2: #1f2937;
  --panel-3: #0f172a;
  --border: #334155;
  --border-soft: #1e293b;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --muted-2: #64748b;
  --blue: #2563eb;
  --blue-hover: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --red-hover: #b91c1c;
  --yellow: #f59e0b;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.18), transparent 34%),
    radial-gradient(circle at top right, rgba(22, 163, 74, 0.12), transparent 32%),
    var(--bg);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  user-select: none;
}

.app {
  width: min(1240px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 56px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: linear-gradient(135deg, #2563eb, #16a34a);
  color: #fff;
  font-weight: 900;
  letter-spacing: 0.5px;
  box-shadow: 0 14px 40px rgba(37, 99, 235, 0.35);
}

.brand h1,
.brand p {
  margin: 0;
}

.brand h1 {
  font-size: 28px;
  line-height: 1.1;
}

.brand p {
  margin-top: 5px;
  color: var(--muted);
}

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

.current-user {
  color: #93c5fd;
  font-size: 14px;
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

.login-layout {
  min-height: calc(100vh - 150px);
  display: grid;
  place-items: center;
}

.card {
  background: rgba(17, 24, 39, 0.88);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.login-card {
  width: min(430px, 100%);
}

.card-header,
.toolbar-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.card h2,
.card h3,
.toolbar-main h2,
.modal-header h3 {
  margin: 0;
}

.card p,
.toolbar-main p {
  margin: 6px 0 0;
  color: var(--muted);
}

.form {
  display: grid;
  gap: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: #cbd5e1;
  font-size: 14px;
  font-weight: 700;
}

.field-inline {
  min-width: 190px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid #475569;
  background: #020617;
  color: #f8fafc;
  border-radius: 12px;
  padding: 11px 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: #60a5fa;
  box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.14);
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #cbd5e1;
  font-weight: 700;
}

.checkbox-field input {
  width: 18px;
  height: 18px;
}

.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 14px;
  cursor: pointer;
  color: #fff;
  font-weight: 800;
  transition:
    transform 0.12s,
    background 0.12s,
    border-color 0.12s,
    opacity 0.12s;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--blue);
}

.btn-primary:hover {
  background: var(--blue-hover);
}

.btn-secondary {
  background: #475569;
}

.btn-secondary:hover {
  background: #64748b;
}

.btn-danger {
  background: var(--red);
}

.btn-danger:hover {
  background: var(--red-hover);
}

.btn-ghost {
  background: transparent;
  border-color: #475569;
  color: #dbeafe;
}

.btn-ghost:hover {
  border-color: #60a5fa;
  background: rgba(37, 99, 235, 0.12);
}

.btn-wide {
  width: 100%;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: 1px solid #475569;
  border-radius: 12px;
  background: #020617;
  color: #fff;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.icon-btn:hover {
  background: #1e293b;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: rgba(15, 23, 42, 0.86);
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.2);
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.stat-card strong {
  font-size: 30px;
  line-height: 1;
}

.toolbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.filters {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  margin-bottom: 18px;
  align-items: end;
}

.loading {
  border: 1px solid var(--border-soft);
  background: rgba(15, 23, 42, 0.75);
  border-radius: 14px;
  padding: 18px;
  color: var(--muted);
  margin-bottom: 14px;
}

.players-grid {
  display: grid;
  gap: 14px;
}

.empty-state {
  border: 1px dashed #475569;
  background: rgba(15, 23, 42, 0.45);
  color: var(--muted);
  border-radius: 16px;
  padding: 28px;
  text-align: center;
}

.player-card {
  border: 1px solid var(--border-soft);
  background: rgba(2, 6, 23, 0.72);
  border-radius: 18px;
  padding: 16px;
}

.player-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.player-title-wrap {
  min-width: 0;
}

.player-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 20px;
  font-weight: 900;
}

.player-id {
  color: var(--muted-2);
  font-size: 13px;
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 900;
}

.badge-active {
  background: rgba(22, 163, 74, 0.14);
  color: #86efac;
  border: 1px solid rgba(22, 163, 74, 0.38);
}

.badge-inactive {
  background: rgba(220, 38, 38, 0.14);
  color: #fca5a5;
  border: 1px solid rgba(220, 38, 38, 0.38);
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.comment {
  margin-top: 10px;
  color: #cbd5e1;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 10px;
  white-space: pre-wrap;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.character-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.character-card {
  background: rgba(31, 41, 55, 0.78);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 12px;
}

.character-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.character-name {
  font-weight: 900;
  font-size: 16px;
}

.character-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
}

.stat-pill {
  border: 1px solid #334155;
  background: #020617;
  color: #cbd5e1;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
}

.export-output {
  width: 100%;
  min-height: 220px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(8px);
}

.modal-panel {
  position: relative;
  width: min(680px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: #111827;
  border: 1px solid #475569;
  border-radius: 20px;
  box-shadow: 0 30px 120px rgba(0, 0, 0, 0.6);
}

.modal-header {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(17, 24, 39, 0.96);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-soft);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.modal-body {
  padding: 18px;
}

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

.message {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  max-width: min(460px, calc(100% - 40px));
  background: #020617;
  border: 1px solid #334155;
  color: #fff;
  padding: 14px 16px;
  border-radius: 14px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.42);
}

.message.success,
.message-success {
  border-color: rgba(22, 163, 74, 0.8);
}

.message.error,
.message-error {
  border-color: rgba(220, 38, 38, 0.9);
}

.message.warning,
.message-warning {
  border-color: rgba(245, 158, 11, 0.9);
}

.link-btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.events-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  align-items: start;
}

.events-sidebar {
  position: sticky;
  top: 16px;
}

.events-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.event-list-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border-soft);
  background: rgba(2, 6, 23, 0.72);
  color: var(--text);
  border-radius: 14px;
  padding: 12px;
  cursor: pointer;
}

.event-list-item:hover,
.event-list-item.active {
  border-color: #60a5fa;
  background: rgba(37, 99, 235, 0.16);
}

.event-list-title {
  font-weight: 900;
  margin-bottom: 6px;
}

.event-list-meta {
  color: var(--muted);
  font-size: 13px;
}

.event-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 18px;
}

.event-column {
  background: rgba(2, 6, 23, 0.44);
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  padding: 12px;
  min-height: 260px;
}

.event-column h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.participant-list {
  display: grid;
  gap: 10px;
  min-height: 120px;
}

.participant-card {
  border: 1px solid #334155;
  background: #020617;
  border-radius: 14px;
  padding: 10px;
  cursor: grab;
}

.participant-card:active {
  cursor: grabbing;
}

.participant-card.dragging {
  opacity: 0.45;
}

.participant-name {
  font-weight: 900;
  margin-bottom: 6px;
}

.participant-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.participant-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.mini-btn {
  border: 1px solid #334155;
  background: #111827;
  color: #e5e7eb;
  border-radius: 999px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.mini-btn:hover {
  border-color: #60a5fa;
}

.mini-btn.green {
  color: #86efac;
}

.mini-btn.red {
  color: #fca5a5;
}

.new-mark {
  color: #fbbf24;
  font-weight: 900;
}

.section-title {
  margin: 22px 0 12px;
}

.section-title h3,
.section-title p {
  margin: 0;
}

.section-title p {
  margin-top: 5px;
  color: var(--muted);
}

.parties-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(320px, 1fr));
  gap: 14px;
}

.party-card {
  border: 1px solid var(--border-soft);
  background: rgba(2, 6, 23, 0.58);
  border-radius: 18px;
  padding: 14px;
}

.party-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.party-head h4 {
  margin: 0;
  font-size: 18px;
}

.party-slots {
  display: grid;
  gap: 8px;
}

.party-slot {
  min-height: 54px;
  border: 1px dashed #475569;
  background: rgba(15, 23, 42, 0.68);
  border-radius: 12px;
  padding: 8px;
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 8px;
  align-items: center;
}

.party-slot.drag-over {
  border-color: #60a5fa;
  background: rgba(37, 99, 235, 0.18);
}

.slot-number {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #020617;
  border: 1px solid #334155;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.slot-empty {
  color: var(--muted);
  font-size: 13px;
}

.slot-character {
  font-weight: 900;
}

.slot-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.export-textarea {
  width: 100%;
  min-height: 420px;
  resize: vertical;
  border: 1px solid #334155;
  border-radius: 14px;
  background: #020617;
  color: #e5e7eb;
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
}

/* Statistics page */
.statistics-page {
  width: min(1680px, calc(100% - 28px));
}

.statistics-layout {
  display: grid;
  gap: 20px;
}

.statistics-card {
  overflow: hidden;
}

.statistics-filters {
  grid-template-columns: minmax(260px, 1fr) minmax(220px, auto) minmax(220px, auto);
}

.statistics-help {
  border: 1px solid rgba(96, 165, 250, 0.28);
  background: rgba(37, 99, 235, 0.1);
  color: #dbeafe;
  border-radius: 14px;
  padding: 12px 14px;
  margin: -4px 0 16px;
  line-height: 1.45;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  background: rgba(2, 6, 23, 0.46);
}

.data-table {
  width: 100%;
  min-width: 900px;
  border-collapse: separate;
  border-spacing: 0;
}

.data-table th,
.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
  text-align: left;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: rgba(15, 23, 42, 0.98);
  color: #bfdbfe;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.data-table tbody tr:hover {
  background: rgba(37, 99, 235, 0.08);
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.statistics-table td {
  font-size: 14px;
}

.development-table {
  min-width: 1180px;
}

.development-table td:not(:first-child):not(:nth-child(2)),
.development-table th:not(:first-child):not(:nth-child(2)) {
  text-align: center;
}

.class-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  border: 1px solid #334155;
  background: rgba(15, 23, 42, 0.9);
  border-radius: 999px;
  padding: 4px 9px 4px 5px;
  color: #e5e7eb;
  font-weight: 800;
  white-space: nowrap;
}

.class-icon {
  width: 22px;
  height: 22px;
  object-fit: contain;
  border-radius: 6px;
  flex: 0 0 auto;
}

.stat-delta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  border-radius: 999px;
  padding: 4px 8px;
  font-weight: 900;
  border: 1px solid transparent;
}

.stat-delta-up {
  color: #86efac;
  border-color: rgba(22, 163, 74, 0.45);
  background: rgba(22, 163, 74, 0.13);
}

.stat-delta-down {
  color: #fca5a5;
  border-color: rgba(220, 38, 38, 0.5);
  background: rgba(220, 38, 38, 0.13);
}

.stat-delta-zero {
  color: #cbd5e1;
  border-color: rgba(148, 163, 184, 0.28);
  background: rgba(148, 163, 184, 0.08);
}

.stat-delta-empty {
  color: #64748b;
  border-color: rgba(100, 116, 139, 0.22);
  background: rgba(100, 116, 139, 0.06);
}

.good-cell {
  color: #86efac;
  font-weight: 900;
}

.bad-cell {
  color: #fca5a5;
  font-weight: 900;
}

.muted-small {
  margin-top: 4px;
  color: var(--muted-2);
  font-size: 11px;
  line-height: 1.25;
}

@media (max-width: 1180px) {
  .events-layout {
    grid-template-columns: 1fr;
  }

  .events-sidebar {
    position: static;
  }

  .event-board {
    grid-template-columns: 1fr;
  }

  .parties-grid {
    grid-template-columns: 1fr;
  }

  .statistics-filters {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 920px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .filters {
    grid-template-columns: 1fr;
  }

  .field-inline {
    min-width: 0;
  }
}

@media (max-width: 720px) {
  .app,
  .statistics-page {
    width: min(100% - 18px, 1240px);
    padding-top: 14px;
  }

  .topbar,
  .toolbar-main,
  .player-head,
  .character-head {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-actions,
  .toolbar-actions,
  .row-actions {
    justify-content: stretch;
  }

  .toolbar-actions .btn,
  .row-actions .btn,
  .topbar-actions .btn,
  .topbar-actions .link-btn {
    width: 100%;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .brand h1 {
    font-size: 22px;
  }
}
