:root {
  color-scheme: dark;
  --bg: #0f0d0d;
  --bg-soft: #171311;
  --panel: rgba(29, 24, 22, 0.96);
  --panel-strong: #251d19;
  --line: rgba(221, 177, 99, 0.18);
  --line-strong: rgba(221, 177, 99, 0.42);
  --gold: #d9ad62;
  --gold-bright: #f2cf87;
  --red: #9c3f3b;
  --violet: #8d63ce;
  --text: #f1e8d8;
  --muted: #b7aa9b;
  --danger: #d36b61;
  --success: #72b58e;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 8%, rgba(113, 59, 35, 0.18), transparent 30rem),
    radial-gradient(circle at 88% 20%, rgba(102, 72, 151, 0.12), transparent 34rem),
    linear-gradient(180deg, #100d0d, #0c0b0b 65%);
}

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

.app-shell {
  width: min(1220px, calc(100% - 32px));
  margin: 24px auto 64px;
}

.hero {
  position: relative;
  min-height: 292px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  padding: 42px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 22px 22px 8px 8px;
  background: #171311 url("/assets/dungeon-ledger.png") center / cover no-repeat;
  box-shadow: var(--shadow);
}

.hero::after {
  content: "";
  position: absolute;
  inset: 8px;
  pointer-events: none;
  border: 1px solid rgba(237, 200, 132, 0.22);
  border-radius: 16px 16px 4px 4px;
}

.hero__shade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(10, 8, 8, 0.96) 0%, rgba(10, 8, 8, 0.82) 35%, rgba(10, 8, 8, 0.2) 72%),
    linear-gradient(0deg, rgba(10, 8, 8, 0.92) 0%, transparent 60%);
}

.hero__content, .hero-stats { position: relative; z-index: 1; }

.hero__content {
  display: flex;
  align-items: center;
  gap: 20px;
  max-width: 650px;
}

.brand-mark {
  width: 74px;
  height: 74px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  font-family: Georgia, serif;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #17110d;
  background: linear-gradient(145deg, #f0cf8f, #9c632d);
  clip-path: polygon(50% 0%, 89% 18%, 100% 58%, 71% 100%, 29% 100%, 0 58%, 11% 18%);
  filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.45));
}

.eyebrow, .kicker {
  margin: 0 0 7px;
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1, h2, h3, p, dl, dd { margin-top: 0; }

h1, h2, h3 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(2.35rem, 6vw, 4.7rem);
  line-height: 0.96;
  letter-spacing: -0.04em;
  text-shadow: 0 3px 22px rgba(0, 0, 0, 0.7);
}

h2 { margin-bottom: 0; font-size: clamp(1.45rem, 3vw, 2rem); }
h3 { margin-bottom: 4px; font-size: 1.12rem; }

.hero__subtitle { margin-bottom: 0; color: #d9ccba; font-size: 1rem; }

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(88px, 1fr));
  gap: 8px;
  margin: 0;
}

.hero-stats div {
  min-width: 100px;
  padding: 14px 16px;
  border: 1px solid rgba(236, 204, 145, 0.26);
  background: rgba(17, 13, 13, 0.74);
  backdrop-filter: blur(10px);
}

.hero-stats dt { color: var(--muted); font-size: 0.75rem; }
.hero-stats dd { margin: 3px 0 0; color: var(--gold-bright); font: 700 1.6rem Georgia, serif; }

.main-nav {
  display: flex;
  gap: 3px;
  margin-bottom: 18px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-top: 0;
  background: #181412;
  border-radius: 0 0 10px 10px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.2);
}

.nav-button {
  min-height: 45px;
  padding: 0 18px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.nav-button span { margin-right: 7px; color: var(--gold); }
.nav-button:hover { color: var(--text); }
.nav-button.is-active { color: var(--gold-bright); border-bottom-color: var(--gold); }

.view { animation: appear 180ms ease-out; }
.view[hidden] { display: none; }

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

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

.party-layout { grid-template-columns: minmax(270px, 0.65fr) minmax(0, 1.5fr); }

.panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(160deg, rgba(37, 29, 25, 0.97), rgba(24, 20, 19, 0.98));
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.19);
}

.session-panel, .leaderboard-panel, .add-character-panel, .party-layout > .panel, [data-view-panel="history"] > .panel { padding: 26px; }

.leaderboard-panel { position: sticky; top: 18px; }

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

.panel-heading--compact { margin-bottom: 18px; }
.panel-note { max-width: 430px; margin: 0; color: var(--muted); font-size: 0.88rem; text-align: right; }

.save-state {
  padding: 7px 11px;
  border: 1px solid rgba(114, 181, 142, 0.28);
  border-radius: 999px;
  color: var(--success);
  background: rgba(114, 181, 142, 0.08);
  font-size: 0.78rem;
  font-weight: 800;
}

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

.field-grid--three { grid-template-columns: 0.7fr 1fr 1.5fr; }

label { display: grid; gap: 7px; color: var(--muted); font-size: 0.84rem; font-weight: 700; }

input, textarea {
  width: 100%;
  border: 1px solid rgba(227, 190, 124, 0.2);
  border-radius: 9px;
  outline: 0;
  background: rgba(9, 8, 8, 0.48);
  color: var(--text);
}

input { min-height: 46px; padding: 0 13px; }
textarea { padding: 12px 13px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(217, 173, 98, 0.1); }

.section-divider {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin: 28px 0 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.section-divider p { margin: 0; color: var(--muted); font-size: 0.84rem; }
.session-total { color: var(--gold-bright); white-space: nowrap; }

.kill-list { display: grid; gap: 10px; }

.kill-row {
  display: grid;
  grid-template-columns: 11px minmax(130px, 1fr) auto;
  gap: 14px;
  align-items: center;
  min-height: 70px;
  padding: 10px 13px 10px 0;
  overflow: hidden;
  border: 1px solid rgba(227, 190, 124, 0.13);
  border-radius: 10px;
  background: rgba(7, 6, 6, 0.24);
}

.character-stripe { align-self: stretch; background: var(--character-color, var(--gold)); }
.character-info strong { display: block; font-family: Georgia, serif; font-size: 1.05rem; }
.character-info small { color: var(--muted); }

.counter {
  display: grid;
  grid-template-columns: 42px 64px 42px;
  align-items: center;
}

.counter button {
  height: 42px;
  border: 1px solid rgba(227, 190, 124, 0.22);
  background: rgba(217, 173, 98, 0.08);
  cursor: pointer;
  font-size: 1.25rem;
}

.counter button:first-child { border-radius: 8px 0 0 8px; }
.counter button:last-child { border-radius: 0 8px 8px 0; }
.counter button:hover { background: rgba(217, 173, 98, 0.18); }

.counter input {
  min-height: 42px;
  padding: 0 4px;
  border-right: 0;
  border-left: 0;
  border-radius: 0;
  text-align: center;
  font-weight: 800;
  appearance: textfield;
}

.counter input::-webkit-inner-spin-button { appearance: none; }
.notes-field { margin-top: 20px; }

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

.button, .icon-button {
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 800;
}

.button { min-height: 45px; padding: 0 17px; }
.button:disabled { opacity: 0.55; cursor: wait; }
.button--primary { color: #1b130a; background: linear-gradient(135deg, var(--gold-bright), #b77a37); box-shadow: 0 8px 24px rgba(181, 117, 50, 0.15); }
.button--primary:hover { filter: brightness(1.06); }
.button--ghost { border-color: var(--line); background: transparent; color: var(--muted); }
.button--ghost:hover { color: var(--text); border-color: var(--line-strong); }
.button--danger { color: var(--danger); }
.button--small { min-height: 36px; padding: 0 12px; font-size: 0.78rem; }

.leaderboard { display: grid; gap: 8px; }

.leader-row {
  display: grid;
  grid-template-columns: 30px 9px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 55px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(227, 190, 124, 0.09);
}

.leader-rank { color: var(--muted); font: 700 0.9rem Georgia, serif; }
.leader-color { width: 9px; height: 32px; border-radius: 8px; background: var(--character-color); }
.leader-name { min-width: 0; }
.leader-name strong, .leader-name small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leader-name small { color: var(--muted); }
.leader-score { color: var(--gold-bright); font: 700 1.25rem Georgia, serif; }

.empty-state {
  padding: 28px 18px;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  color: var(--muted);
  text-align: center;
}
.empty-state strong { display: block; margin-bottom: 6px; color: var(--text); font-family: Georgia, serif; }

.history-list { display: grid; gap: 12px; }

.history-card {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 18px;
  border: 1px solid rgba(227, 190, 124, 0.13);
  border-radius: 11px;
  background: rgba(8, 7, 7, 0.24);
}

.session-seal {
  display: grid;
  place-items: center;
  width: 74px;
  height: 74px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  color: var(--gold-bright);
  background: radial-gradient(circle, rgba(141, 99, 206, 0.16), transparent 66%);
  font: 700 1.45rem Georgia, serif;
}
.session-seal small { display: block; color: var(--muted); font: 700 0.6rem Inter, sans-serif; text-transform: uppercase; }

.history-main h3 { margin-bottom: 4px; }
.history-meta { margin-bottom: 10px; color: var(--muted); font-size: 0.82rem; }
.history-notes { margin-bottom: 12px; color: #d5c8b7; line-height: 1.45; }
.kill-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.kill-chip { padding: 5px 9px; border: 1px solid color-mix(in srgb, var(--character-color) 50%, transparent); border-radius: 999px; color: #e8dece; background: color-mix(in srgb, var(--character-color) 12%, transparent); font-size: 0.76rem; }
.history-total { min-width: 86px; text-align: right; }
.history-total strong { display: block; color: var(--gold-bright); font: 700 1.9rem Georgia, serif; }
.history-total span { color: var(--muted); font-size: 0.75rem; }
.history-actions { display: flex; gap: 6px; margin-top: 12px; justify-content: flex-end; }

.stack-form { display: grid; gap: 15px; }
.color-field input { width: 100%; padding: 5px; }
.party-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }

.party-card {
  position: relative;
  min-height: 145px;
  padding: 18px;
  overflow: hidden;
  border: 1px solid rgba(227, 190, 124, 0.13);
  border-radius: 11px;
  background: rgba(8, 7, 7, 0.24);
}
.party-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--character-color); }
.party-card.is-archived { opacity: 0.62; }
.party-card__top { display: flex; justify-content: space-between; gap: 12px; }
.party-card h3 { margin-bottom: 4px; }
.party-card p { margin-bottom: 18px; color: var(--muted); }
.party-card__score { color: var(--gold-bright); text-align: right; }
.party-card__score strong { display: block; font: 700 1.55rem Georgia, serif; }
.party-card__score small { color: var(--muted); }

.edit-dialog {
  width: min(820px, calc(100% - 28px));
  max-height: calc(100vh - 40px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 15px;
  color: var(--text);
  background: #211a17;
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.7);
}
.edit-dialog::backdrop { background: rgba(5, 4, 4, 0.78); backdrop-filter: blur(4px); }
.edit-dialog form { padding: 25px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: start; margin-bottom: 22px; }
.icon-button { width: 42px; height: 42px; border-color: var(--line); background: transparent; font-size: 1.6rem; }
.kill-list--dialog { margin-top: 20px; }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(380px, calc(100% - 44px));
  padding: 13px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  color: var(--text);
  background: #29201c;
  box-shadow: var(--shadow);
  transition: 160ms ease;
}
.toast.is-visible { opacity: 1; transform: none; }
.toast.is-error { border-color: rgba(211, 107, 97, 0.55); }

@media (max-width: 900px) {
  .hero { min-height: 350px; align-items: flex-start; flex-direction: column; justify-content: flex-end; padding: 30px; }
  .hero__shade { background: linear-gradient(0deg, rgba(10, 8, 8, 0.96) 0%, rgba(10, 8, 8, 0.65) 70%, rgba(10, 8, 8, 0.22)); }
  .hero-stats { width: 100%; }
  .workspace-grid, .party-layout { grid-template-columns: 1fr; }
  .leaderboard-panel { position: static; }
}

@media (max-width: 650px) {
  .app-shell { width: min(100% - 18px, 1220px); margin-top: 9px; }
  .hero { min-height: 410px; padding: 24px 18px; border-radius: 14px 14px 6px 6px; }
  .hero__content { align-items: flex-start; }
  .brand-mark { width: 58px; height: 58px; font-size: 0.68rem; }
  h1 { font-size: clamp(2.25rem, 12vw, 3.3rem); }
  .hero-stats { grid-template-columns: repeat(3, 1fr); }
  .hero-stats div { min-width: 0; padding: 11px 9px; }
  .hero-stats dt { font-size: 0.65rem; }
  .hero-stats dd { font-size: 1.25rem; }
  .main-nav { overflow-x: auto; }
  .nav-button { flex: 1 0 auto; padding: 0 13px; }
  .session-panel, .leaderboard-panel, .add-character-panel, .party-layout > .panel, [data-view-panel="history"] > .panel { padding: 18px; }
  .panel-heading { align-items: flex-start; flex-direction: column; gap: 8px; }
  .panel-note { text-align: left; }
  .field-grid--three { grid-template-columns: 1fr; }
  .kill-row { grid-template-columns: 8px minmax(0, 1fr); padding-right: 10px; }
  .counter { grid-column: 2; width: 148px; }
  .history-card { grid-template-columns: 62px minmax(0, 1fr); gap: 12px; }
  .session-seal { width: 58px; height: 58px; font-size: 1.1rem; }
  .history-total { grid-column: 2; display: flex; align-items: baseline; gap: 5px; text-align: left; }
  .history-actions { margin-left: auto; }
  .party-list { grid-template-columns: 1fr; }
  .form-actions { flex-wrap: wrap; }
  .form-actions .button { flex: 1 1 150px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}

