:root {
  color-scheme: dark;
  --bg: #0b0e12;
  --panel: #131922;
  --panel-strong: #18222d;
  --line: #2f3c49;
  --muted: #93a4b5;
  --text: #edf3f8;
  --accent: #74c7ec;
  --accent-strong: #2e6f95;
  --story: #d7b77a;
  --story-dark: #6f5529;
}

body {
  background:
    radial-gradient(circle at top left, rgba(46, 111, 149, 0.14), transparent 34rem),
    var(--bg);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 900;
  background: rgba(11, 14, 18, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.site-header-main {
  display: flex;
  align-items: center;
  gap: 18px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 18px 10px;
}

.site-brand {
  min-width: max-content;
}

.site-brand strong {
  display: block;
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.12rem;
  letter-spacing: 0.035em;
}

.site-brand span {
  display: block;
  margin-top: 1px;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.primary-nav,
.character-nav,
.story-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.primary-nav {
  flex: 1;
}

.nav-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: #becbd6;
  padding: 8px 14px;
  font: inherit;
  cursor: pointer;
}

.nav-button:hover,
.nav-button:focus-visible {
  border-color: #435568;
  background: #17202a;
  color: #fff;
  outline: none;
}

.nav-button.active {
  border-color: #4d7692;
  background: #203445;
  color: #eef9ff;
  box-shadow: inset 0 -2px 0 var(--accent);
}

.character-nav-wrap {
  border-top: 1px solid #1e2832;
  background: #10151b;
}

.character-nav-wrap[hidden] {
  display: none;
}

.character-nav {
  max-width: 1180px;
  margin: 0 auto;
  padding: 7px 18px;
  overflow-x: auto;
}

.character-nav .nav-button {
  min-height: 36px;
  padding: 6px 11px;
  font-size: 0.88rem;
  white-space: nowrap;
}

.character-nav-spacer {
  flex: 1;
}

.cloud-card-shell {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.app-main {
  max-width: 1180px;
  margin: 0 auto;
}

.tab-content {
  padding: 24px 18px 40px;
}

.section-heading {
  margin-bottom: 18px;
}

.section-heading h1,
.section-heading h2 {
  margin: 0 0 5px;
  color: var(--text);
}

.section-heading p {
  margin: 0;
  color: var(--muted);
}

.story-nav {
  margin-bottom: 18px;
  padding: 4px;
  width: fit-content;
  border: 1px solid #4d4332;
  border-radius: 6px;
  background: #15120e;
}

.story-nav .nav-button.active {
  border-color: #8e7547;
  background: #4d3817;
  box-shadow: inset 0 -2px 0 var(--story);
}

.story-view[hidden] {
  display: none;
}

.story-so-far {
  max-width: 900px;
  margin: 0 auto;
  border: 1px solid #4e4435;
  border-radius: 7px;
  overflow: hidden;
  background: linear-gradient(180deg, #f4ecd8, #e7dbc1);
  color: #2f2417;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.34);
}

.story-so-far-hero {
  position: relative;
  min-height: 250px;
  display: flex;
  align-items: end;
  padding: 28px;
  box-sizing: border-box;
  background:
    linear-gradient(180deg, rgba(9, 12, 15, 0.14), rgba(9, 12, 15, 0.88)),
    url("img/party.png") center 34% / cover;
  color: white;
}

.story-so-far-hero h1 {
  margin: 0 0 5px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 7vw, 3.7rem);
  line-height: 0.98;
}

.story-so-far-hero p {
  margin: 0;
  color: #e5ebef;
}

.story-timeline {
  padding: 22px clamp(18px, 5vw, 46px) 32px;
}

.story-chapter {
  position: relative;
  padding: 4px 0 22px 24px;
  border-left: 2px solid #bca678;
}

.story-chapter:last-child {
  padding-bottom: 2px;
}

.story-chapter::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 10px;
  width: 12px;
  height: 12px;
  border: 2px solid #e7dbc1;
  border-radius: 50%;
  background: var(--story-dark);
}

.story-chapter h2 {
  margin: 0 0 7px;
  color: #493417;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.25rem;
}

.story-chapter p {
  margin: 0;
  line-height: 1.65;
}

.archive-note {
  max-width: 860px;
  margin: 0 auto 12px;
  padding: 11px 14px;
  border: 1px solid #5d503b;
  border-radius: 5px;
  background: #211c14;
  color: #dbc9a9;
  font-size: 0.9rem;
}

.archive-note strong {
  color: #fff1d2;
}

.character-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}

.character-management {
  margin-top: 24px;
  border-top: 1px solid #2f3c49;
  padding-top: 12px;
  color: #aebdca;
}

.character-management > summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: 0.86rem;
}

.character-management[open] > summary {
  color: #dbeaf4;
}

.character-toolbar .toolbar-copy {
  flex: 1 1 260px;
  color: var(--muted);
  font-size: 0.88rem;
}

.character-toolbar button,
.import-label {
  min-height: 38px;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #4f6c83;
  border-radius: 4px;
  background: #263747;
  color: #e7f3fb;
  padding: 7px 11px;
  cursor: pointer;
  font: inherit;
  font-size: 0.86rem;
}

.character-toolbar button:hover,
.import-label:hover {
  background: #30485d;
}

#dnd4e-file-input,
#character-backup-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.import-status {
  width: 100%;
  min-height: 1.2em;
  color: #afd6ee;
  font-size: 0.85rem;
}

.import-status.error {
  color: #ffaaaa;
}

.imported-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 7px;
  border: 1px solid #527d98;
  border-radius: 999px;
  color: #bfe7ff;
  font-size: 0.7rem;
  font-weight: 400;
  vertical-align: middle;
}

.imported-power-box {
  margin: 8px 0;
  padding: 9px 10px;
  border: 1px solid #527d98;
  border-radius: 5px;
  background: #152733;
  color: #dff3ff;
  font-size: 0.78rem;
}

.imported-power-box strong {
  color: #fff;
}

.imported-power-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.imported-power-source {
  color: #9bcbe6;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.imported-power-box select {
  width: 100%;
  margin: 3px 0 7px;
  padding: 6px 7px;
  border: 1px solid #527d98;
  border-radius: 3px;
  background: #0e1921;
  color: #edf8ff;
}

.imported-power-result {
  color: #fff;
  font-size: 0.92rem;
  font-weight: 700;
}

.imported-power-box details {
  margin-top: 7px;
  color: #b7d8ea;
}

.imported-power-box summary {
  cursor: pointer;
}

.imported-power-breakdown {
  margin: 7px 0 0;
  white-space: pre-wrap;
  color: #c6dce8;
  font: 0.74rem/1.45 Consolas, "Courier New", monospace;
}

.session-dashboard {
  margin: 0 0 24px;
}

.session-identity {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 12px;
}

.session-identity h3 {
  margin: 0;
  color: #fff;
  font-size: clamp(1.35rem, 7vw, 2rem);
}

.session-identity p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.session-feedback {
  min-height: 1.35em;
  margin: 0 0 8px;
  color: #b9d9ff;
  font-size: 0.84rem;
}

.session-vitals {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.session-card {
  min-width: 0;
  padding: 14px;
  border: 1px solid #334351;
  border-radius: 8px;
  background: linear-gradient(180deg, #18222d, #121922);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.2);
}

.session-card h4 {
  margin: 0;
  color: #bdd8e9;
  font-size: 0.76rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.hp-card {
  border-color: #45677b;
}

.hp-card.bloodied {
  border-color: #a65b5b;
  background: linear-gradient(180deg, #352026, #1c171c);
}

.hp-card.dying,
.hp-card.dead {
  border-color: #d26b6b;
  background: linear-gradient(180deg, #431b22, #180f12);
}

.vital-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.health-state {
  padding: 2px 7px;
  border: 1px solid #55778c;
  border-radius: 999px;
  color: #d8f0ff;
  font-size: 0.7rem;
}

.bloodied .health-state,
.dying .health-state,
.dead .health-state {
  border-color: #a65b5b;
  color: #ffbcbc;
}

.vital-number {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 8px 0;
}

.vital-number input {
  width: 4.2ch;
  min-height: 48px;
  padding: 2px 6px;
  border: 1px solid #50687a;
  border-radius: 5px;
  background: #0c1218;
  color: #fff;
  font: 700 2rem/1 "Trebuchet MS", sans-serif;
  text-align: center;
}

.vital-number .vital-max {
  color: #a9b8c5;
  font-size: 1.05rem;
}

.hp-meter {
  height: 8px;
  overflow: hidden;
  margin: 0 0 10px;
  border-radius: 999px;
  background: #080b0e;
}

.hp-meter > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #4a9f68, #74d493);
  transition: width 160ms ease;
}

.bloodied .hp-meter > span {
  background: linear-gradient(90deg, #9f4343, #e47878);
}

.session-adjust-row,
.session-button-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.session-adjust-row input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  border: 1px solid #50687a;
  border-radius: 5px;
  background: #0c1218;
  color: #fff;
  font-size: 1rem;
  text-align: center;
}

.session-button,
.power-use-button,
.power-name-button {
  min-height: 46px;
  border: 1px solid #4f6c83;
  border-radius: 5px;
  background: #263747;
  color: #edf8ff;
  padding: 8px 10px;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.session-button:active,
.power-use-button:active,
.power-name-button:active {
  transform: translateY(1px);
}

.session-button.damage {
  border-color: #924f58;
  background: #54242c;
}

.session-button.heal {
  border-color: #4b8060;
  background: #214832;
}

.session-button.primary {
  border-color: #5b89a5;
  background: #28516a;
}

.session-button:disabled,
.power-use-button:disabled {
  opacity: 0.46;
  cursor: not-allowed;
}

.vital-support {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin: 8px 0 10px;
  color: #b5c4cf;
  font-size: 0.82rem;
}

.compact-resource-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.compact-value {
  margin: 8px 0 10px;
  color: #fff;
  font-size: 1.5rem;
  font-weight: 700;
}

.compact-value input {
  width: 3.5ch;
  min-height: 42px;
  border: 1px solid #50687a;
  border-radius: 4px;
  background: #0c1218;
  color: #fff;
  font: inherit;
  text-align: center;
}

.rest-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin: 10px 0;
}

.condition-tracker {
  margin: 10px 0 0;
  padding: 12px;
  border: 1px solid #334351;
  border-radius: 8px;
  background: #111820;
}

.condition-tracker h3 {
  margin: 0;
  color: #fff;
  font-size: 0.9rem;
}

.condition-tracker-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.condition-tracker-heading > div > span {
  display: block;
  margin-top: 2px;
  color: #94a7b6;
  font-size: 0.72rem;
}

.condition-tracker select,
.custom-condition-form input,
.custom-condition-form textarea,
.custom-condition-form select,
.condition-dialog-add input,
.condition-dialog-add select {
  min-height: 42px;
  border: 1px solid #50687a;
  border-radius: 5px;
  background: #0c1218;
  color: #fff;
  padding: 8px 10px;
  font: inherit;
}

.condition-tracker-heading select {
  min-width: 0;
  max-width: 190px;
}

.condition-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.condition-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px 58px;
  gap: 5px;
}

.condition-row-main,
.condition-info-button,
.condition-resolve-button {
  min-height: 42px;
  border: 1px solid #70545d;
  border-radius: 5px;
  background: #2b2026;
  color: #f1dce1;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.condition-row-main {
  min-width: 0;
  padding: 6px 9px;
  text-align: left;
}

.condition-row-main strong,
.condition-row-main span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.condition-row-main strong {
  font-size: 0.84rem;
}

.condition-row-main span {
  margin-top: 1px;
  color: #d1afb8;
  font-size: 0.68rem;
}

.condition-row-main .condition-row-note {
  color: #aebbc4;
}

.condition-info-button {
  border-color: #4f6c83;
  background: #20303d;
  color: #ccecff;
  font-weight: 700;
}

.condition-resolve-button {
  background: #39242a;
  font-size: 0.74rem;
  font-weight: 700;
}

.custom-condition-form {
  margin-top: 9px;
  border-top: 1px solid #2e3c47;
  padding-top: 8px;
}

.custom-condition-form summary {
  color: #b9d9ff;
  cursor: pointer;
  font-size: 0.78rem;
}

.custom-condition-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 0.75fr);
  gap: 8px;
  margin-top: 9px;
}

.custom-condition-grid label,
.condition-dialog-add label {
  display: grid;
  gap: 4px;
  color: #aebfcb;
  font-size: 0.72rem;
}

.custom-condition-grid input,
.custom-condition-grid textarea,
.custom-condition-grid select {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.custom-condition-description {
  grid-column: 1 / -1;
}

.custom-condition-grid > .session-button {
  grid-column: 1 / -1;
}

.condition-dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: min(720px, calc(100vh - 24px));
  box-sizing: border-box;
  overflow: auto;
  border: 1px solid #526b7d;
  border-radius: 10px;
  background: #121a22;
  color: #dce8ef;
  padding: 18px;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.62);
}

.condition-dialog::backdrop {
  background: rgba(2, 6, 10, 0.78);
}

.condition-dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.condition-dialog-header h2 {
  margin: 1px 0 0;
  color: #fff;
  font-size: 1.35rem;
}

.condition-dialog-kicker {
  margin: 0;
  color: #8fb7cc;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.condition-dialog-close {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 1px solid #4f6575;
  border-radius: 50%;
  background: #202e39;
  color: #fff;
  font-size: 1.35rem;
  cursor: pointer;
}

.condition-dialog-duration {
  margin: 12px 0;
  padding: 8px 10px;
  border-left: 3px solid #6489a0;
  background: #18242e;
  color: #bcd7e7;
  font-size: 0.8rem;
  line-height: 1.4;
}

.condition-rule-list {
  margin: 0;
  padding-left: 20px;
  line-height: 1.45;
}

.condition-rule-list li + li {
  margin-top: 7px;
}

.condition-active-note {
  margin-top: 12px;
  padding: 10px;
  border: 1px solid #4a5f6e;
  border-radius: 6px;
  background: #0d141a;
  white-space: pre-wrap;
}

.condition-dialog-add {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid #344754;
}

.condition-dialog-add[hidden] {
  display: none;
}

.power-tracker {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid #334351;
  border-radius: 8px;
  background: #111820;
}

.power-tracker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.power-tracker-header h3 {
  margin: 0;
  color: #fff;
  font-size: 1rem;
}

.power-summary {
  color: #9fb3c2;
  font-size: 0.78rem;
}

.power-groups {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.power-group h4 {
  margin: 0 0 6px;
  color: #b9d9ff;
  font-size: 0.77rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.power-use-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 82px;
  gap: 7px;
  margin-bottom: 7px;
}

.power-name-button {
  overflow: hidden;
  background: #1a2631;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.power-use-button {
  background: #214832;
  border-color: #4b8060;
  font-weight: 700;
}

.power-use-row.used .power-name-button {
  color: #8f9ba5;
  text-decoration: line-through;
}

.power-use-row.used .power-use-button {
  border-color: #73515a;
  background: #39242a;
  color: #d8b8bf;
}

.sheet-details-heading {
  margin: 26px 0 10px;
  padding-top: 16px;
  border-top: 1px solid #2f3c49;
  color: #aebdca;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#glossary .glossary-layout {
  min-height: 65vh;
}

@media (max-width: 760px) {
  .site-header-main {
    display: block;
    padding-bottom: 7px;
  }

  .site-brand {
    margin-bottom: 8px;
  }

  .primary-nav {
    overflow-x: auto;
  }

  .primary-nav .nav-button {
    flex: 1 0 auto;
  }

  .character-nav-spacer {
    display: none;
  }

  .cloud-card-shell {
    padding-left: 8px;
  }

  .tab-content {
    padding: 18px 12px 30px;
  }

  #character > .section-heading {
    margin-bottom: 6px;
  }

  #character > .section-heading p,
  #character-view > .char-header-row h2 {
    display: none;
  }

  #character-view > .char-header-row {
    justify-content: flex-end;
    margin-bottom: 2px;
  }

  .story-so-far-hero {
    min-height: 210px;
    padding: 20px;
  }

  .glossary-layout {
    display: block;
  }

  .glossary-sidebar {
    width: auto;
    border-right: 0;
    border-bottom: 1px solid #555;
    padding: 0 0 12px;
  }

  #glossary-list {
    max-height: 34vh;
  }

  #glossary-detail {
    padding: 16px 0 0;
  }

  #equipment > div[style*="display:flex"] {
    height: auto !important;
    flex-direction: column;
  }

  #equipment > div[style*="display:flex"] > div {
    border-right: 0 !important;
  }

  .condition-tracker-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .condition-tracker-heading select {
    width: 100%;
    max-width: none;
  }

  .custom-condition-grid {
    grid-template-columns: 1fr;
  }

  .custom-condition-description,
  .custom-condition-grid > .session-button {
    grid-column: auto;
  }
}

@media (min-width: 640px) {
  .session-vitals {
    grid-template-columns: minmax(320px, 1.35fr) minmax(250px, 1fr);
  }

  .compact-resource-grid {
    margin-top: 0;
  }

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