:root {
  --bg-page-top: #081109;
  --bg-page-bottom: #030804;
  --bg-body-glow: rgba(70, 255, 130, 0.09);
  --bg-panel: rgba(8, 26, 12, 0.92);
  --bg-panel-strong: rgba(4, 18, 8, 0.96);
  --bg-input: rgba(5, 17, 8, 0.92);
  --bg-card: rgba(8, 20, 10, 0.96);
  --bg-card-dark: rgba(4, 10, 5, 0.99);
  --line: rgba(94, 255, 144, 0.22);
  --line-strong: rgba(94, 255, 144, 0.48);
  --text-primary: #9dffb6;
  --text-dim: #6ab982;
  --text-heading: #d7ffe1;
  --accent: #66ff99;
  --accent-soft: rgba(102, 255, 153, 0.16);
  --danger: #ff8b74;
  --shadow: 0 0 30px rgba(58, 255, 131, 0.08);
  --font-ui: "Share Tech Mono", monospace;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-ui);
  background:
    radial-gradient(circle at top, var(--bg-body-glow), transparent 32%),
    linear-gradient(180deg, var(--bg-page-top) 0%, var(--bg-page-bottom) 100%);
  color: var(--text-primary);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    repeating-linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.02) 0,
      rgba(255, 255, 255, 0.02) 1px,
      transparent 1px,
      transparent 4px
    );
  pointer-events: none;
  opacity: 0.3;
  animation: crtFlicker 0.18s steps(2, end) infinite;
}

body::after {
  content: "";
  position: fixed;
  inset: -25% 0 auto 0;
  height: 22%;
  background:
    linear-gradient(
      180deg,
      transparent 0%,
      rgba(255, 255, 255, 0.02) 18%,
      var(--accent-soft) 48%,
      rgba(255, 255, 255, 0.03) 78%,
      transparent 100%
    );
  mix-blend-mode: screen;
  opacity: 0.34;
  pointer-events: none;
  animation: scanBeam 8s linear infinite;
}

.screen-glow {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at center, transparent 40%, rgba(0, 0, 0, 0.42) 100%);
  pointer-events: none;
  animation: screenPulse 5.5s ease-in-out infinite;
}

.app-shell {
  position: relative;
  max-width: 1480px;
  margin: 0 auto;
  padding: 24px;
}

.panel {
  background: linear-gradient(180deg, var(--bg-panel), var(--bg-panel));
  border: 1px solid var(--line);
  box-shadow: inset 0 0 0 1px rgba(130, 255, 173, 0.05), var(--shadow);
  border-radius: 16px;
  padding: 20px;
  position: relative;
  overflow: hidden;
  animation: panelBoot 420ms ease both;
}

.panel::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 16px;
  border: 1px solid rgba(148, 255, 183, 0.05);
  pointer-events: none;
}

.panel::before {
  content: "";
  position: absolute;
  inset: -30% auto -30% -15%;
  width: 42%;
  background: linear-gradient(90deg, transparent, var(--accent-soft), transparent);
  opacity: 0;
  pointer-events: none;
  transform: skewX(-22deg);
  animation: panelSweep 9s linear infinite;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 20px;
}

.title-block {
  flex: 0 0 320px;
  min-width: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.8rem;
}

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

h1,
h2,
h3 {
  color: var(--text-heading);
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 2.5vw, 1.8rem);
  line-height: 1.02;
}

.title-line {
  display: block;
  white-space: nowrap;
}

h2 {
  margin-bottom: 18px;
  font-size: 1.15rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h3 {
  margin-bottom: 0;
}

.grid-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.full-width {
  grid-column: 1 / -1;
}

.form-grid {
  display: grid;
  gap: 16px;
}

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

.weapon-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

.full-span {
  grid-column: 1 / -1;
}

label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text-dim);
  font-size: 0.92rem;
}

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

input,
select,
textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--line);
  color: var(--text-primary);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

button,
.file-button {
  border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, var(--accent-soft), transparent);
  color: var(--text-heading);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  text-align: center;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

button:hover,
.file-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px var(--accent-soft);
}

button:active,
.file-button:active {
  transform: translateY(0);
}

.danger {
  border-color: rgba(255, 139, 116, 0.35);
  background: linear-gradient(180deg, rgba(255, 139, 116, 0.16), rgba(255, 139, 116, 0.04));
  color: var(--danger);
}

.save-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: nowrap;
  justify-content: flex-end;
  flex: 1 1 auto;
  min-width: 0;
}

body.editor-hidden .editor-panel {
  display: none;
}

body.account-hidden .auth-panel {
  display: none;
}

body.chooser-hidden .compendium-full {
  display: none;
}

body:not(.chooser-hidden) .selected-perks-strip {
  display: none;
}

body.trait-chooser-hidden .trait-compendium-full {
  display: none;
}

body:not(.trait-chooser-hidden) .selected-traits-strip {
  display: none;
}

.theme-control {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 126px;
  color: var(--text-dim);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.theme-control select,
.theme-control input[type="color"] {
  min-height: 42px;
  padding: 8px;
}

.auth-panel {
  margin-bottom: 20px;
}

.auth-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: end;
}

.form-actions {
  display: flex;
  align-items: end;
}

.cloud-panel {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.compact-list {
  gap: 10px;
}

.compact-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-card);
}

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

.shared-inventory-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.shared-transfer-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  background: var(--bg-card);
}

.party-transfer-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 12px;
}

.shared-party-inventory {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.shared-inventory-column {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: var(--bg-card);
  min-height: 120px;
}

.shared-inventory-column h3 {
  margin-bottom: 10px;
}

.shared-inventory-entry {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.shared-inventory-entry:first-of-type {
  border-top: 0;
}

.theme-control input[type="color"] {
  width: 100%;
  border-radius: 10px;
  background: var(--bg-input);
  border: 1px solid var(--line);
  padding: 4px;
}

.theme-control input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.theme-control input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 6px;
}

#load-character {
  display: none;
}

#load-party {
  display: none;
}

.inline-input {
  display: flex;
  gap: 10px;
}

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

.special-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

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

.stat-card,
.display-card,
.skill-card,
.armor-card,
.list-card {
  background: linear-gradient(180deg, var(--bg-card), var(--bg-card-dark));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.stat-card {
  text-align: center;
}

.stat-card .stat-letter {
  font-size: 1.5rem;
  color: var(--text-heading);
}

.stat-card .stat-name {
  margin: 6px 0 12px;
  color: var(--text-dim);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.skills-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.skill-card {
  display: grid;
  gap: 12px;
}

.skill-card.tagged {
  border-color: var(--line-strong);
  box-shadow: inset 0 0 0 1px rgba(102, 255, 153, 0.18), 0 0 24px rgba(102, 255, 153, 0.08);
  background: linear-gradient(180deg, var(--bg-card), var(--bg-card-dark));
}

.skill-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.skill-header h3 {
  font-size: 1rem;
}

.tag-toggle {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text-heading);
}

.tag-toggle input {
  width: auto;
}

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

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

.section-note {
  color: var(--text-dim);
  margin-bottom: 0;
}

.armor-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.dynamic-list {
  display: grid;
  gap: 16px;
}

.inventory-caps-grid {
  max-width: 260px;
  margin-bottom: 16px;
}

.compendium-list {
  max-height: 560px;
  overflow: auto;
  padding-right: 4px;
}

.compendium-toolbar {
  display: flex;
  gap: 12px;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 14px;
}

.compendium-full,
.trait-compendium-full {
  display: grid;
  gap: 14px;
}

.selected-perks-strip,
.selected-traits-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
  margin-bottom: 14px;
}

.selected-perks-strip.empty,
.selected-traits-strip.empty {
  color: var(--text-dim);
}

.selected-perk-chip,
.selected-trait-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.18);
  color: var(--text-heading);
  font-size: 0.82rem;
}

.selected-perk-chip span,
.selected-trait-chip span {
  color: var(--text-dim);
}

.compendium-search {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text-dim);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.compendium-search input {
  width: 100%;
}

.compendium-card {
  gap: 10px;
}

.compendium-card.selected {
  border-color: var(--line-strong);
  box-shadow: inset 0 0 0 1px rgba(102, 255, 153, 0.16), 0 0 20px rgba(102, 255, 153, 0.08);
}

.compendium-card h3 {
  font-size: 0.98rem;
}

.compendium-select {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-heading);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.compendium-rank-input {
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text-dim);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.compendium-rank {
  color: var(--text-dim);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.compendium-meta {
  display: grid;
  gap: 8px;
}

.compendium-meta p {
  margin: 0;
  color: var(--text-dim);
}

.display-card {
  display: grid;
  gap: 12px;
  position: relative;
  background: linear-gradient(180deg, var(--bg-card), var(--bg-card-dark));
  box-shadow: inset 0 0 0 1px var(--line), 0 0 24px var(--accent-soft);
  animation-delay: 90ms;
}

.display-card::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  pointer-events: none;
}

.display-card p {
  margin: 0;
  color: var(--text-dim);
}

.display-card strong {
  color: var(--text-heading);
}

.display-list {
  display: grid;
  gap: 0;
}

.display-heading {
  display: block;
  position: relative;
  padding-right: 42%;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.display-heading h3 {
  margin-bottom: 0;
  font-size: 1rem;
  line-height: 1.2;
  letter-spacing: 0;
  text-transform: none;
}

.display-heading span {
  position: absolute;
  top: 2px;
  right: 0;
  max-width: 40%;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.76rem;
  line-height: 1.2;
  text-align: right;
}

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

.display-statline {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--bg-card-dark);
}

.display-statline strong,
.display-statline span {
  display: block;
}

.display-statline strong {
  color: var(--text-dim);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.display-statline span {
  color: var(--text-heading);
  font-size: 1.08rem;
  margin-top: 4px;
}

.display-statline .display-adjust-line {
  display: flex;
}

.caps-statline {
  margin-bottom: 2px;
}

.display-inventory-category {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.shared-inventory-category-columns {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.shared-inventory-category-column {
  min-width: 0;
}

.shared-inventory-category-column .display-inventory-category:first-child {
  padding-top: 0;
}

.display-inventory-category:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.display-inventory-category h4 {
  margin: 0 0 6px;
  color: var(--text-dim);
  font-size: 0.78rem;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.display-inventory-category .display-row:first-of-type {
  padding-top: 0;
}

.display-block {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.display-block:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.display-block:first-child {
  padding-top: 0;
}

.display-block p {
  margin: 2px 0 0;
}

.display-party-pool-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.display-adjust-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.display-party-ap-controls {
  display: inline-flex;
  gap: 6px;
  flex: 0 0 auto;
}

.display-inline-controls {
  display: inline-flex;
  gap: 6px;
  flex: 0 0 auto;
}

.display-party-ap-controls button,
.display-inline-controls button {
  width: 32px;
  height: 32px;
  padding: 0;
  min-height: 0;
  border-radius: 8px;
  font-size: 1rem;
  line-height: 1;
}

.multiline-text {
  white-space: pre-wrap;
}

.display-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.display-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.display-row:first-child {
  padding-top: 0;
}

.display-row span:last-child {
  text-align: right;
  color: var(--text-heading);
}

.display-sheet-header {
  grid-column: span 4;
}

.display-special {
  grid-column: span 4;
}

.display-skills {
  grid-column: span 4;
}

.display-armor {
  grid-column: span 4;
}

.display-power-armor {
  grid-column: span 4;
}

.display-weapons {
  grid-column: span 4;
}

.display-ammo {
  grid-column: span 4;
}

.display-party {
  grid-column: span 4;
}

.display-shared-inventory {
  grid-column: 1 / -1;
}

.display-perks {
  grid-column: span 4;
}

.display-companion-perks {
  grid-column: span 4;
}

.display-traits {
  grid-column: span 4;
}

.display-inventory {
  grid-column: span 4;
}

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

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 20px;
  color: var(--text-dim);
  text-align: center;
}

.party-pools-list {
  margin-top: 16px;
}

.party-pool-card {
  display: grid;
  gap: 14px;
}

.party-pool-controls {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, auto));
  gap: 10px;
  align-items: end;
}

.party-pool-controls label {
  min-width: 120px;
}

.party-log-panel {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.party-log-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

.party-log-entry {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.16);
}

.party-log-entry strong {
  color: var(--text-heading);
}

.party-log-entry span {
  color: var(--text-dim);
  font-size: 0.82rem;
}

@keyframes scanBeam {
  0% {
    transform: translateY(-130%);
  }
  100% {
    transform: translateY(760%);
  }
}

@keyframes crtFlicker {
  0%,
  100% {
    opacity: 0.26;
  }
  50% {
    opacity: 0.34;
  }
}

@keyframes screenPulse {
  0%,
  100% {
    opacity: 0.95;
  }
  50% {
    opacity: 1;
  }
}

@keyframes panelBoot {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.995);
    filter: brightness(1.2);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: brightness(1);
  }
}

@keyframes panelSweep {
  0%,
  82% {
    opacity: 0;
    transform: translateX(-30%) skewX(-22deg);
  }
  88% {
    opacity: 0.18;
  }
  100% {
    opacity: 0;
    transform: translateX(340%) skewX(-22deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  body::before,
  body::after,
  .screen-glow,
  .panel,
  .panel::before {
    animation: none;
  }
}

@media (max-width: 1080px) {
  .grid-layout,
  .weapon-grid,
  .armor-grid,
  .skills-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .display-sheet-header,
  .display-special,
  .display-skills,
  .display-perks,
  .display-companion-perks,
  .display-traits,
  .display-party,
  .display-shared-inventory,
  .display-armor,
  .display-power-armor,
  .display-weapons,
  .display-ammo,
  .display-inventory {
    grid-column: span 1;
  }

  .display-shared-inventory {
    grid-column: 1 / -1;
  }

  .special-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 16px;
  }

  .topbar,
  .section-title-row,
  .section-actions,
  .inline-input {
    flex-direction: column;
    align-items: stretch;
  }

  .save-controls {
    flex-wrap: wrap;
  }

  .title-block {
    flex-basis: auto;
  }

  .grid-layout,
  .two-col,
  .weapon-grid,
  .party-pool-controls,
  .display-grid,
  .perk-grid,
  .armor-grid,
  .skills-grid,
  .special-grid {
    grid-template-columns: 1fr;
  }

  .display-meta {
    grid-template-columns: 1fr;
  }

  .shared-inventory-category-columns {
    grid-template-columns: 1fr;
  }

  .display-heading {
    padding-right: 0;
  }

  .display-heading span {
    position: static;
    display: block;
    max-width: none;
    margin-top: 4px;
    text-align: left;
  }

  .compendium-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
}
