:root {
  --bg: #0d0b10;
  --bg-2: #17131b;
  --panel: rgba(25, 19, 28, 0.94);
  --panel-alt: #1d1a22;
  --accent: #9d7c4d;
  --accent-strong: #d6b073;
  --accent-soft: rgba(214, 176, 115, 0.14);
  --purple: #8257d5;
  --red: #b4555c;
  --text: #f1ebf4;
  --muted: #bcaeb7;
  --danger: #d66d67;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
  background:
    radial-gradient(circle at top, rgba(130, 87, 213, 0.16), transparent 20%),
    radial-gradient(circle at bottom, rgba(180, 85, 92, 0.12), transparent 25%),
    linear-gradient(135deg, var(--bg), var(--bg-2));
  color: var(--text);
  font-family: "Inter", sans-serif;
}

body {
  min-height: 100vh;
}

button, input, textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: rgba(14, 11, 17, 0.96);
  border-right: 1px solid var(--border);
  padding: 24px 18px;
  position: relative;
}

.sidebar::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(157, 124, 77, 0.06), transparent 25%);
  pointer-events: none;
}

.brand-box {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
  position: relative;
  z-index: 1;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent-strong), #7c5d35);
  color: #180d0c;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(24, 13, 12, 0.3);
  border-radius: 50%;
  pointer-events: none;
}

.brand-mark svg {
  width: 86%;
  height: 86%;
}

.sigil-ring, .sigil-rays, .sigil-orbit {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sigil-ring.outer {
  stroke-width: 1.8;
}

.sigil-ring.inner, .sigil-orbit {
  stroke-width: 1.2;
}

.sigil-rays {
  stroke-width: 1.5;
}

.sigil-core {
  fill: currentColor;
}

.sigil-node {
  fill: #d6b073;
  stroke: currentColor;
  stroke-width: 1;
}

h1, h2, h3 {
  font-family: "Cinzel", serif;
  margin: 0;
}

h1 {
  font-size: 1.1rem;
}

h2 {
  font-size: clamp(1.4rem, 2vw, 2rem);
}

h3 {
  font-size: 1.08rem;
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.primary-btn, .danger-btn, .small-btn, .ghost-btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}

.primary-btn:hover, .danger-btn:hover, .small-btn:hover, .ghost-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.2);
}

.primary-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--accent-strong), #8c6a39);
  color: #1a120d;
  font-weight: 700;
}

.danger-btn {
  background: rgba(214, 109, 103, 0.12);
  color: #ffd9d6;
  border: 1px solid rgba(214, 109, 103, 0.4);
}

.small-btn, .ghost-btn {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border: 1px solid var(--border);
}

.list-header {
  margin: 22px 0 12px;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.list-header.compact {
  margin-top: 18px;
}

.investigator-list, .party-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  z-index: 1;
}

.investigator-item, .party-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  padding: 12px 12px;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
  text-align: left;
}

.investigator-item.active {
  background: rgba(214, 176, 115, 0.12);
  border-color: rgba(214, 176, 115, 0.7);
}

.investigator-item strong, .party-item strong {
  display: block;
  margin-bottom: 4px;
}

.investigator-meta, .party-item span {
  color: var(--muted);
  font-size: 0.76rem;
}

.sidebar-section {
  position: relative;
  z-index: 1;
}

.main-panel {
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.sheet-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.panel-card {
  background: linear-gradient(180deg, rgba(27, 21, 30, 0.96), rgba(18, 15, 21, 0.94));
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
}

.basic-card, .notes-card, .skills-card, .combat-card, .inventory-card, .party-card, .enemies-card, .log-card {
  grid-column: span 2;
}

.dice-card, .conditions-card, .campaign-card {
  grid-column: span 2;
}

.two-cols {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field-grid {
  display: grid;
  gap: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

input, textarea {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
}

input:focus, textarea:focus {
  outline: 1px solid rgba(214, 176, 115, 0.8);
  border-color: rgba(214, 176, 115, 0.8);
}

.stats-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.derived-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.metric-box {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 10px;
  text-align: center;
}

.metric-box span {
  display: block;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.68rem;
  margin-bottom: 8px;
}

.metric-box strong {
  font-size: 1.2rem;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.skills-list, .inventory-list, .combat-list, .party-detail-list, .enemy-list, .session-log {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.skill-row {
  display: grid;
  grid-template-columns: minmax(160px, 1.8fr) 110px 90px auto;
  gap: 10px;
  align-items: center;
}

.skill-row input {
  min-width: 0;
}

.skill-row .ghost-btn {
  justify-self: end;
}

.inventory-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.4fr) 90px minmax(130px, 1fr) minmax(120px, 1.4fr) auto;
  gap: 10px;
  align-items: center;
}

.attack-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.2fr) 100px minmax(120px, 1fr) minmax(120px, 1.2fr) auto;
  gap: 10px;
  align-items: center;
}

.party-row, .enemy-row, .log-row {
  display: grid;
  gap: 10px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.party-row {
  grid-template-columns: minmax(150px, 1.2fr) minmax(120px, 1fr) 90px minmax(120px, 1.4fr) auto;
}

.enemy-row {
  grid-template-columns: minmax(150px, 1.2fr) minmax(120px, 1fr) 90px 90px minmax(110px, 1fr) minmax(140px, 1.5fr) auto;
}

.log-row {
  grid-template-columns: 90px minmax(0, 1fr) auto;
  align-items: start;
}

.log-time {
  color: var(--accent-strong);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.inventory-row input,
.inventory-row textarea,
.attack-row input,
.attack-row textarea,
.party-row input,
.enemy-row input,
.log-row textarea {
  min-width: 0;
}

.row-field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 5px;
  color: var(--muted);
  font-size: 0.67rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.row-field span {
  overflow-wrap: anywhere;
}

.row-field input {
  width: 100%;
}

.row-remove {
  align-self: end;
  white-space: nowrap;
}

textarea {
  resize: vertical;
  min-height: 120px;
}

.empty-state {
  border: 1px dashed var(--border);
  color: var(--muted);
  border-radius: 12px;
  padding: 22px;
  text-align: center;
}

select {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
}

.die-select {
  border-width: 2px;
  font-weight: 700;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.die-select option {
  background: var(--panel-alt);
  color: var(--text);
}

.die-select option[data-die-color="d100"] { color: #e4bb73; }
.die-select option[data-die-color="d3"] { color: #76d5b8; }
.die-select option[data-die-color="d4"] { color: #84bdf0; }
.die-select option[data-die-color="d6"] { color: #bba5ed; }
.die-select option[data-die-color="d8"] { color: #ee9db4; }
.die-select option[data-die-color="d10"] { color: #f2ab73; }
.die-select option[data-die-color="d12"] { color: #acd47d; }
.die-select option[data-die-color="d20"] { color: #ed8b85; }

.dice-controls select.die-d100 { border-color: #c99b54; background: rgba(201, 155, 84, 0.16); }
.dice-controls select.die-d3 { border-color: #5fc4a5; background: rgba(95, 196, 165, 0.16); }
.dice-controls select.die-d4 { border-color: #66a8e8; background: rgba(102, 168, 232, 0.16); }
.dice-controls select.die-d6 { border-color: #a78be7; background: rgba(167, 139, 231, 0.16); }
.dice-controls select.die-d8 { border-color: #e77d9b; background: rgba(231, 125, 155, 0.16); }
.dice-controls select.die-d10 { border-color: #e89558; background: rgba(232, 149, 88, 0.16); }
.dice-controls select.die-d12 { border-color: #8dbb63; background: rgba(141, 187, 99, 0.16); }
.dice-controls select.die-d20 { border-color: #d66d67; background: rgba(214, 109, 103, 0.16); }

.dice-controls select.roll-skill-select,
.dice-controls select.roll-difficulty-select {
  border-width: 2px;
  font-weight: 700;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.dice-controls select.roll-skill-select {
  border-color: #66a8e8;
  background: rgba(102, 168, 232, 0.16);
  color: #c7e3ff;
}

.dice-controls select.roll-skill-select option {
  background: #172535;
  color: #c7e3ff;
}

.dice-controls select.roll-difficulty-select {
  border-color: #a78be7;
  background: rgba(167, 139, 231, 0.16);
  color: #ded2ff;
}

.dice-controls select.roll-difficulty-select option {
  background: #251d38;
  color: #ded2ff;
}

.dice-controls select.roll-difficulty-select.difficulty-1 { border-color: #5fc4a5; background: rgba(95, 196, 165, 0.16); color: #b9f0dd; }
.dice-controls select.roll-difficulty-select.difficulty-0-5 { border-color: #e4bb73; background: rgba(228, 187, 115, 0.16); color: #f6ddb0; }
.dice-controls select.roll-difficulty-select.difficulty-0-2 { border-color: #e89558; background: rgba(232, 149, 88, 0.16); color: #ffd0a8; }
.dice-controls select.roll-difficulty-select.difficulty--1 { border-color: #e77d9b; background: rgba(231, 125, 155, 0.16); color: #ffc2d2; }

.dice-controls {
  display: grid;
  grid-template-columns: minmax(180px, 1.5fr) minmax(150px, 1fr) 120px;
  gap: 14px;
}

.roll-result {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid rgba(214, 176, 115, 0.35);
  border-radius: 10px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-weight: 700;
}

.roll-history {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
}

.roll-history-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding: 8px 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.roll-history-row strong {
  color: var(--text);
}

.section-actions {
  display: flex;
  gap: 8px;
}

.condition-list, .scenario-list, .npc-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.condition-list + .condition-list {
  margin-top: 10px;
}

.condition-row, .scenario-row, .npc-row {
  display: grid;
  gap: 10px;
  align-items: center;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
}

.condition-row {
  grid-template-columns: minmax(150px, 1.3fr) minmax(120px, 0.8fr) minmax(160px, 1.5fr) auto;
}

.scenario-row {
  grid-template-columns: minmax(160px, 1.2fr) minmax(120px, 0.8fr) minmax(180px, 2fr) auto;
}

.npc-row {
  grid-template-columns: minmax(140px, 1.2fr) minmax(120px, 1fr) minmax(120px, 1fr) minmax(160px, 1.5fr) auto;
}

.campaign-subhead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 18px 0 10px;
}

.campaign-subhead h4 {
  margin: 0;
  color: var(--accent-strong);
  font-family: "Cinzel", serif;
}

@media print {
  html, body {
    background: #fff;
    color: #111;
  }

  .sidebar, .topbar-actions, .section-head button, .ghost-btn, .primary-btn, .danger-btn,
  .roll-history, .roll-result, .dice-card, .campaign-card {
    display: none !important;
  }

  .app-shell, .sheet-layout {
    display: block;
  }

  .main-panel {
    padding: 0;
  }

  .panel-card {
    color: #111;
    background: #fff;
    border: 1px solid #999;
    box-shadow: none;
    border-radius: 0;
    margin-bottom: 12px;
    break-inside: avoid;
  }

  input, textarea, select {
    color: #111;
    background: #fff;
    border-color: #aaa;
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sheet-layout, .two-cols, .stats-grid, .derived-grid {
    grid-template-columns: 1fr;
  }

  .basic-card, .notes-card, .skills-card, .combat-card, .inventory-card, .party-card, .enemies-card, .log-card {
    grid-column: auto;
  }

  .dice-card, .conditions-card, .campaign-card {
    grid-column: auto;
  }

  .dice-controls, .condition-row, .scenario-row, .npc-row {
    grid-template-columns: 1fr;
  }

  .skill-row, .inventory-row, .attack-row, .party-row, .enemy-row, .log-row {
    grid-template-columns: 1fr;
  }

  .inventory-row, .attack-row, .enemy-row, .scenario-row, .npc-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
  }

  .inventory-row .row-field:first-child,
  .attack-row .row-field:first-child,
  .enemy-row .row-field:first-child,
  .scenario-row .row-field:first-child,
  .npc-row .row-field:first-child,
  .row-field-wide {
    grid-column: 1 / -1;
  }

  .inventory-row .row-remove,
  .attack-row .row-remove,
  .enemy-row .row-remove,
  .scenario-row .row-remove,
  .npc-row .row-remove {
    grid-column: 1 / -1;
    width: 100%;
  }

  .row-field input {
    min-height: 42px;
  }

  .skill-row .ghost-btn {
    justify-self: stretch;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 600px) {
  .sidebar, .main-panel {
    padding: 16px;
  }

  .sidebar {
    padding-bottom: 12px;
  }

  .investigator-list, .party-list {
    flex-direction: row;
    overflow-x: auto;
    margin-right: -16px;
    padding: 2px 16px 8px 0;
    scrollbar-width: thin;
  }

  .investigator-item, .party-item {
    flex: 0 0 190px;
  }

  .list-header {
    margin-top: 16px;
  }

  .brand-box {
    margin-bottom: 18px;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
    font-size: 1.7rem;
  }

  .main-panel {
    padding-top: 20px;
  }

  .topbar {
    gap: 12px;
    margin-bottom: 16px;
  }

  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .topbar-actions button {
    width: 100%;
  }

  .section-head, .campaign-subhead {
    align-items: center;
    flex-direction: row;
    gap: 10px;
  }

  .section-head h3, .campaign-subhead h4 {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .section-head button, .campaign-subhead button {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .section-actions {
    flex: 0 0 auto;
    flex-direction: row;
    gap: 6px;
  }

  .section-actions button {
    padding-inline: 9px;
  }

  .panel-card {
    border-radius: 12px;
    padding: 14px 12px;
  }

  .two-cols, .field-grid {
    gap: 10px;
  }

  .basic-card .two-cols,
  .stats-grid,
  .derived-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats-grid label {
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 9px;
  }

  .derived-grid {
    gap: 8px;
  }

  .metric-box {
    padding: 11px 8px;
  }

  input, textarea, select {
    font-size: 16px;
  }

  .roll-history-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }
}
