:root {
  --bg: #070603;
  --bg-2: #100c06;
  --panel: #151006;
  --panel-soft: #1e1709;
  --gold: #d6ad3d;
  --gold-soft: #8a6a1f;
  --gold-dim: #4d3a12;
  --text: #efe2bf;
  --muted: #a88d54;
  --danger: #a13b2a;
  --line: rgba(214, 173, 61, 0.28);
  --line-soft: rgba(214, 173, 61, 0.13);
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.42);
  --role-caller: #70d6ff;
  --role-tank: #4c8fe8;
  --role-healer: #5ccf78;
  --role-support: #d9bd3f;
  --role-dps: #dc6252;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: Cambria, Georgia, 'Times New Roman', serif;
  background:
    radial-gradient(circle at 72% 0%, rgba(126, 72, 20, 0.2), transparent 34rem),
    radial-gradient(circle at 20% 20%, rgba(214, 173, 61, 0.11), transparent 22rem),
    linear-gradient(145deg, #050402 0%, #0d0904 42%, #130d06 100%);
}

body.light-mode {
  --bg: #f6f0df;
  --bg-2: #efe3c5;
  --panel: #fff7df;
  --panel-soft: #f4e6bf;
  --gold: #9b7212;
  --gold-soft: #83631b;
  --gold-dim: #c7a34e;
  --text: #231b0d;
  --muted: #765d24;
  --line: rgba(155, 114, 18, 0.36);
  --line-soft: rgba(155, 114, 18, 0.2);
  --shadow: 0 18px 48px rgba(74, 52, 10, 0.16);
  --role-caller: #1e9acc;
  --role-tank: #2266c0;
  --role-healer: #218744;
  --role-support: #96770c;
  --role-dps: #b73629;
  background:
    radial-gradient(circle at 72% 0%, rgba(214, 173, 61, 0.28), transparent 34rem),
    radial-gradient(circle at 20% 20%, rgba(92, 207, 120, 0.1), transparent 22rem),
    linear-gradient(145deg, #faf4e5 0%, #f0e4c7 48%, #e7d5ad 100%);
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(214, 173, 61, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(214, 173, 61, 0.025) 1px, transparent 1px);
  background-size: 38px 38px;
  opacity: 0.65;
}

body.light-mode::before {
  background-image:
    linear-gradient(rgba(155, 114, 18, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(155, 114, 18, 0.06) 1px, transparent 1px);
  opacity: 0.48;
}

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

button, a { transition: border-color 160ms ease, background 160ms ease, transform 160ms ease; }
button:hover, a:hover { transform: translateY(-1px); }

.app-frame {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  grid-template-rows: 102px 1fr;
  min-height: 100vh;
}

.single-view, .commander-view {
  grid-template-columns: 1fr;
}

.landing-board, .player-board {
  grid-column: 1 / -1;
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
  padding: 34px 0;
}

.landing-hero {
  padding: 30px;
}

.landing-grid, .player-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(240px, 1fr));
  gap: 20px;
  margin-top: 22px;
}

.player-grid {
  grid-template-columns: minmax(300px, 0.8fr) minmax(360px, 1.2fr);
  align-items: start;
}

.read-only-roster-grid {
  grid-template-columns: 1fr;
}

.signed-roster-card {
  max-width: 760px;
}

.roster-mini {
  padding: 18px;
}

.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(300px, 1fr) auto minmax(280px, 1fr);
  align-items: center;
  gap: 24px;
  padding: 20px 28px 20px 138px;
  border-top: 3px solid rgba(214, 173, 61, 0.2);
  border-bottom: 1px solid var(--line-soft);
  background: rgba(13, 9, 4, 0.94);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}

.theme-toggle {
  position: fixed;
  top: 20px;
  left: 24px;
  z-index: 30;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  color: var(--gold);
  background: rgba(19, 13, 5, 0.88);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.66rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.light-mode .theme-toggle {
  background: rgba(255, 248, 226, 0.92);
}

.light-mode .topbar {
  background: rgba(255, 248, 226, 0.94);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  color: var(--gold);
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  font-size: clamp(1.3rem, 2vw, 2rem);
  font-weight: 800;
  text-shadow: 0 0 22px rgba(214, 173, 61, 0.24);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  color: var(--text);
  background: #211708;
  box-shadow: inset 0 0 18px rgba(214, 173, 61, 0.12);
}

.room-pill {
  display: inline-flex;
  align-items: center;
  gap: 16px;
  justify-content: center;
  min-height: 52px;
  padding: 0 18px;
  border: 1px solid var(--gold);
  border-radius: 5px;
  background: rgba(39, 29, 10, 0.82);
}

.room-pill span, .section-kicker, label span, .event-picker label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.28em;
  font-size: 0.72rem;
}

.room-pill strong {
  color: var(--gold);
  letter-spacing: 0.18em;
  font-size: 1.15rem;
}

.top-actions {
  justify-self: end;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.ghost-button, .outline-button, .gold-button {
  border: 1px solid var(--line);
  color: var(--gold);
  background: rgba(19, 13, 5, 0.78);
  min-height: 40px;
  padding: 0 16px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.76rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.light-mode .ghost-button,
.light-mode .outline-button,
.light-mode .icon-button {
  background: rgba(255, 248, 226, 0.78);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  color: var(--gold);
  background: rgba(19, 13, 5, 0.78);
  cursor: pointer;
}

.gold-button {
  background: linear-gradient(180deg, #4a3712, #2a200c);
  border-color: var(--gold);
  color: #f7df8f;
  min-height: 44px;
}

.ghost-button {
  min-height: 32px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.025);
}

.side-rail {
  border-right: 1px solid var(--line-soft);
  background: rgba(12, 10, 5, 0.72);
}

.rail-section {
  padding: 26px 22px;
  border-bottom: 1px solid var(--line-soft);
}

.signup-form, .compact-form, .event-form {
  display: grid;
  gap: 14px;
}

.turnstile-widget {
  min-height: 65px;
  max-width: 100%;
  overflow: hidden;
}

.read-me {
  margin: 0 0 14px;
  border: 1px solid var(--line-soft);
  padding: 10px 12px;
  color: #d7c492;
  background: rgba(214, 173, 61, 0.045);
  line-height: 1.35;
}

label {
  display: grid;
  gap: 7px;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--gold-dim);
  color: var(--text);
  background: rgba(3, 3, 2, 0.72);
  min-height: 42px;
  padding: 10px 12px;
  outline: none;
}

.light-mode input,
.light-mode select,
.light-mode textarea {
  background: rgba(255, 252, 240, 0.86);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(214, 173, 61, 0.09);
}

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

summary {
  cursor: pointer;
  color: var(--gold);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 0.78rem;
  margin-bottom: 12px;
}

.gear-details {
  border: 1px dashed var(--gold-dim);
  padding: 12px;
  background: rgba(214, 173, 61, 0.025);
}

.gear-details input { margin-top: 8px; }

.command-board {
  grid-column: 1 / -1;
  min-width: 0;
  padding: 30px;
}

.panel-line, .party-card, .commander-card {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(27, 20, 8, 0.92), rgba(12, 9, 4, 0.92));
  box-shadow: var(--shadow);
}

.light-mode .panel-line,
.light-mode .party-card,
.light-mode .commander-card {
  background: linear-gradient(180deg, rgba(255, 248, 226, 0.94), rgba(244, 230, 191, 0.94));
}

.event-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  align-items: end;
  gap: 24px;
  padding: 22px 24px;
}

.editable-label-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.editable-label-row .section-kicker {
  margin: 0;
}

h1 {
  margin: 0;
  color: var(--gold);
  font-size: clamp(2.1rem, 4vw, 4rem);
  line-height: 0.95;
  letter-spacing: -0.04em;
  text-transform: uppercase;
}

.muted, .hint {
  color: var(--muted);
}

.event-note {
  margin-top: 14px;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  color: #cdb47a;
}

.light-mode .event-note,
.light-mode .read-me {
  color: #5f4717;
}

.event-note span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 28px 0 24px;
  border-bottom: 1px solid var(--line-soft);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 18px;
  margin: 30px 0 24px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  border: 1px solid var(--line);
  padding: 10px 14px;
  background: rgba(18, 12, 4, 0.88);
}

.light-mode .stat-card {
  background: rgba(255, 248, 226, 0.86);
}

.stat-card span {
  color: var(--muted);
  font-size: 1rem;
  letter-spacing: 0.12em;
}

.stat-card strong { color: var(--gold); font-size: 1.2rem; }
.stat-card small { color: var(--muted); }

.party-stack {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.commander-party-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.roster-source-panel {
  position: sticky;
  top: 120px;
}

.manual-kicker {
  margin-top: 22px;
}

.panel-kicker-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-kicker-row .section-kicker {
  margin: 0;
}

.compact-action {
  min-height: 28px;
  padding: 0 10px;
  font-size: 0.64rem;
}

.party-card { overflow: hidden; }

.party-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 62px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.18em;
}

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

.party-name-input {
  width: min(260px, 50vw);
  min-height: 34px;
  border: 0;
  color: var(--gold);
  background: transparent;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-weight: 700;
}

.party-edit-icon {
  width: 28px;
  height: 28px;
  margin-left: 8px;
  font-size: 0.72rem;
}

.danger-action {
  border-color: rgba(161, 59, 42, 0.65);
  color: #d98676;
}

.drag-dots {
  color: var(--muted);
  margin-right: 14px;
  cursor: grab;
  user-select: none;
}

.drag-dots:active { cursor: grabbing; }

.roster-table-wrap { overflow-x: auto; padding: 12px; }

.roster-table {
  width: 100%;
  min-width: 1380px;
  border-collapse: collapse;
}

.roster-table th {
  color: var(--gold-soft);
  background: rgba(51, 37, 12, 0.62);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.68rem;
  text-align: left;
  padding: 12px 10px;
}

.light-mode .roster-table th {
  background: rgba(202, 164, 69, 0.22);
}

.roster-table td {
  border-top: 1px dashed var(--line-soft);
  color: #d7c492;
  padding: 8px;
  min-height: 38px;
}

.roster-table tr.role-caller td:first-child,
.roster-table tr.role-tank td:first-child,
.roster-table tr.role-healer td:first-child,
.roster-table tr.role-support td:first-child,
.roster-table tr.role-dps td:first-child {
  border-left: 4px solid currentColor;
}

.role-caller { color: var(--role-caller) !important; }
.role-tank { color: var(--role-tank) !important; }
.role-healer { color: var(--role-healer) !important; }
.role-support { color: var(--role-support) !important; }
.role-dps { color: var(--role-dps) !important; }

.role-caller input, .role-caller .build-head span, .role-caller strong { color: var(--role-caller); }
.role-tank input, .role-tank .build-head span, .role-tank strong { color: var(--role-tank); }
.role-healer input, .role-healer .build-head span, .role-healer strong { color: var(--role-healer); }
.role-support input, .role-support .build-head span, .role-support strong { color: var(--role-support); }
.role-dps input, .role-dps .build-head span, .role-dps strong { color: var(--role-dps); }

.role-caller input, .role-caller.build-row, .mini-list .role-caller { border-color: color-mix(in srgb, var(--role-caller), transparent 55%); }
.role-tank input, .role-tank.build-row, .mini-list .role-tank { border-color: color-mix(in srgb, var(--role-tank), transparent 55%); }
.role-healer input, .role-healer.build-row, .mini-list .role-healer { border-color: color-mix(in srgb, var(--role-healer), transparent 55%); }
.role-support input, .role-support.build-row, .mini-list .role-support { border-color: color-mix(in srgb, var(--role-support), transparent 55%); }
.role-dps input, .role-dps.build-row, .mini-list .role-dps { border-color: color-mix(in srgb, var(--role-dps), transparent 55%); }

.empty-row td {
  color: rgba(215, 196, 146, 0.42);
}

.editable-roster input {
  min-height: 28px;
  padding: 4px 6px;
  font-size: 0.72rem;
  color: #efe2bf;
  background: rgba(2, 2, 1, 0.84);
  user-select: text;
}

.light-mode .editable-roster input {
  color: var(--text);
  background: rgba(255, 252, 240, 0.9);
}

.editable-roster input:disabled {
  opacity: 0.46;
  cursor: not-allowed;
}

.editable-roster td:first-child input {
  min-width: 150px;
}

.editable-roster td:last-child input {
  min-width: 130px;
}

.consumable-cell {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) 54px;
  gap: 6px;
  align-items: center;
}

.enchant-select {
  min-height: 28px;
  padding: 4px;
  font-size: 0.72rem;
}

.role-pill {
  display: inline-flex;
  padding: 4px 8px;
  border: 1px solid var(--line-soft);
  color: var(--text);
  background: rgba(214, 173, 61, 0.06);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.7rem;
}

.role-pill.healer { color: #9fd48c; }
.role-pill.tank { color: #8fb9df; }
.role-pill.support { color: #d7bf72; }
.role-pill.mdps, .role-pill.rdps { color: #e69a75; }

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

.mini-list div {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  color: #d7c492;
  border-bottom: 1px dashed var(--line-soft);
  padding-bottom: 8px;
  min-width: 0;
}

.mini-list .source-row {
  display: grid;
  grid-template-columns: 24px minmax(72px, 0.8fr) minmax(0, 1.2fr);
  align-items: start;
}

.mini-list strong,
.mini-list span {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.draggable-source {
  cursor: grab;
}

.draggable-source:active {
  cursor: grabbing;
}

.ready-check {
  display: inline-grid;
  place-items: center;
  gap: 0;
}

.ready-check input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.ready-check span {
  width: 18px;
  height: 18px;
  border: 1px solid var(--gold-dim);
  background: rgba(0, 0, 0, 0.34);
}

.ready-check input:checked + span {
  border-color: #5fbe63;
  background: rgba(38, 118, 44, 0.26);
}

.ready-check input:checked + span::after {
  content: '✓';
  display: block;
  color: #7ee083;
  font-size: 16px;
  line-height: 16px;
  text-align: center;
  font-weight: 800;
}

.mini-list span {
  color: var(--muted);
  font-size: 0.86rem;
  text-align: right;
}

.mini-list .source-row span {
  text-align: right;
}

.commander-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(360px, 1.2fr) minmax(280px, 0.8fr);
  gap: 20px;
  margin-top: 28px;
}

.commander-card { padding: 22px; }

.approval-list {
  margin-top: 18px;
}

.approval-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-top: 1px dashed var(--line-soft);
  padding: 12px 0;
}

.approval-row span {
  display: grid;
  gap: 4px;
}

.approval-row small {
  color: var(--muted);
}

.planned-comp-card {
  margin-top: 22px;
}

.player-comp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr));
  gap: 16px;
  padding: 18px;
}

.player-comp-grid section {
  border: 1px solid var(--line-soft);
  padding: 14px;
  background: rgba(5, 4, 2, 0.54);
}

.light-mode .player-comp-grid section {
  background: rgba(255, 252, 240, 0.52);
}

.player-comp-grid h3 {
  margin: 0 0 12px;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.9rem;
}

.build-row {
  border-top: 1px dashed var(--line-soft);
  padding: 10px 0;
}

.build-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.build-head span {
  color: var(--gold);
  text-align: right;
  overflow-wrap: anywhere;
}

.build-details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 8px 12px;
  margin: 10px 0 0;
}

.build-details div {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 0;
  border: 1px solid var(--line-soft);
  padding: 7px 8px;
  background: rgba(0, 0, 0, 0.18);
}

.item-icon {
  width: 42px;
  height: 42px;
  object-fit: contain;
  border: 1px solid var(--line-soft);
  background: rgba(214, 173, 61, 0.06);
}

.build-details dt {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.64rem;
}

.build-details dd {
  margin: 4px 0 0;
  color: var(--text);
  overflow-wrap: anywhere;
  word-break: normal;
}

.build-empty {
  margin: 8px 0 0;
}

.details-form { margin-top: 14px; }

.event-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.event-form textarea, .event-form button { grid-column: 1 / -1; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(440px, calc(100% - 36px));
  border: 1px solid var(--gold);
  color: var(--text);
  background: #120d05;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  z-index: 20;
}

.light-mode .toast,
.light-mode .action-dialog {
  background: #fff8e2;
}

.action-dialog {
  border: 1px solid var(--gold);
  color: var(--text);
  background: #120d05;
  padding: 20px;
  box-shadow: var(--shadow);
}

.action-dialog::backdrop {
  background: rgba(0, 0, 0, 0.56);
}

.dialog-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.export-textarea {
  width: min(520px, 78vw);
  min-height: 220px;
  margin-top: 12px;
  white-space: pre;
}

@media (max-width: 1100px) {
  .app-frame { grid-template-columns: 1fr; grid-template-rows: auto; }
  .topbar { position: static; grid-template-columns: 1fr; padding-left: 28px; padding-top: 70px; }
  .theme-toggle { top: 16px; left: 28px; }
  .top-actions { justify-self: start; }
  .side-rail { border-right: 0; border-bottom: 1px solid var(--line-soft); }
  .event-hero, .commander-grid, .landing-grid, .player-grid, .commander-party-layout { grid-template-columns: 1fr; }
  .roster-source-panel { position: static; }
  .stats-grid { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
}

@media (max-width: 640px) {
  .command-board, .rail-section, .topbar { padding: 18px; }
  .landing-board, .player-board { width: calc(100% - 28px); padding: 20px 0; }
  .room-pill, .toolbar, .top-actions { align-items: stretch; flex-direction: column; }
  .event-form, .stats-grid { grid-template-columns: 1fr; }
  h1 { font-size: 2.2rem; }
}
