@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=Space+Grotesk:wght@400;500;600;700&display=swap");

:root {
  --roll-bg: #070512;
  --roll-panel: rgba(16, 12, 35, 0.94);
  --roll-panel-solid: #100c23;
  --roll-surface: #0b081b;
  --roll-line: rgba(136, 114, 255, 0.28);
  --roll-line-strong: rgba(157, 108, 255, 0.55);
  --roll-text: #f7f4ff;
  --roll-muted: #afa8c5;
  --roll-cyan: #00d9ff;
  --roll-pink: #ff2aa1;
  --roll-orange: #ff8a45;
  --roll-yellow: #ffe45c;
  --roll-violet: #9d6cff;
}

html,
body {
  background: var(--roll-bg);
  color-scheme: dark;
  color: var(--roll-text);
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  font-size: 14px;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(255, 42, 161, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 217, 255, 0.03) 1px, transparent 1px),
    radial-gradient(circle at 64% 0, rgba(141, 55, 255, 0.22), transparent 34rem),
    linear-gradient(180deg, #10092a 0, var(--roll-bg) 44rem);
  background-size: 72px 72px, 72px 72px, auto, auto;
}

button,
input,
select {
  font: inherit;
}

.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template:
    "header header" 72px
    "inputs results" minmax(0, 1fr)
    / 440px minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: transparent;
}

.app-header {
  grid-area: header;
  min-width: 0;
  display: grid;
  grid-template-columns: 440px minmax(190px, 1fr) auto;
  align-items: center;
  gap: 24px;
  margin: 0;
  padding: 0 18px;
  border: 0;
  border-bottom: 1px solid var(--roll-line);
  border-radius: 0;
  background: rgba(7, 5, 18, 0.78);
}

.app-brand {
  display: inline-flex;
  width: max-content;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.app-brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--roll-cyan);
  background: #09071a;
  color: white;
  box-shadow: 4px 4px 0 var(--roll-pink);
  font: 700 14px/1 "IBM Plex Mono", monospace;
}

.app-brand-copy {
  display: grid;
  gap: 2px;
}

.app-brand-copy strong {
  font-size: 16px;
  line-height: 1;
}

.app-brand-copy small,
.app-title > span,
.section-kicker {
  color: var(--roll-cyan);
  font: 600 9px/1.2 "IBM Plex Mono", monospace;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.app-title {
  min-width: 0;
}

.app-title h1 {
  margin: 3px 0 0;
  font-size: 21px;
  line-height: 1;
  letter-spacing: -0.03em;
}

.app-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.app-toolbar button,
.account-link,
.inputs-heading button,
.plot-action-btn,
.cross-controls button {
  min-height: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--roll-line);
  border-radius: 0;
  background: rgba(11, 8, 27, 0.78);
  color: var(--roll-text);
  padding: 0 12px;
  font: 600 10px/1 "IBM Plex Mono", monospace;
  letter-spacing: 0.035em;
  text-decoration: none;
  text-transform: uppercase;
}

.app-toolbar button:hover,
.account-link:hover,
.inputs-heading button:hover,
.plot-action-btn:hover,
.cross-controls button:hover {
  border-color: var(--roll-cyan);
  background: rgba(0, 217, 255, 0.08);
}

.unit-control {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: var(--roll-muted);
  font: 600 9px/1 "IBM Plex Mono", monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.unit-control select {
  width: 90px;
  height: 34px;
}

.unit-control small {
  display: block;
  margin-top: 2px;
  color: #7f7794;
  font-size: 7px;
  letter-spacing: 0.04em;
}

.inputs {
  grid-area: inputs;
  width: auto;
  height: auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  gap: 10px;
  padding: 16px 14px 28px 18px;
  border-right: 1px solid var(--roll-line);
  background: rgba(7, 5, 18, 0.58);
  scrollbar-color: var(--roll-violet) transparent;
  scrollbar-width: thin;
}

.inputs-heading,
.results-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
}

.inputs-heading {
  padding: 2px 0 5px;
}

.inputs-heading h2,
.results-heading h2 {
  margin: 4px 0 0;
  color: var(--roll-text);
  font-size: 22px;
  line-height: 1;
  letter-spacing: -0.035em;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--roll-line);
  border-radius: 0;
  background:
    linear-gradient(135deg, rgba(255, 138, 69, 0.045), transparent 44%),
    var(--roll-panel);
}

legend {
  width: auto;
  margin: 0 0 7px;
  padding: 0 5px 0 0;
  color: var(--roll-text);
  font-size: 12px;
  font-weight: 700;
}

legend > span {
  margin-right: 7px;
  color: var(--roll-orange);
  font: 600 10px/1 "IBM Plex Mono", monospace;
}

label {
  grid-template-columns: minmax(0, 1fr) 152px;
  gap: 10px;
  min-height: 32px;
  margin: 0;
  padding: 4px 0;
  color: #ded9eb;
  border-bottom: 1px solid rgba(136, 114, 255, 0.11);
  font-size: 12px;
}

label:last-child {
  border-bottom: 0;
}

.unit {
  margin-top: 2px;
  color: #8e86a5;
  font: 400 9px/1.25 "IBM Plex Mono", monospace;
}

input,
select {
  width: 100%;
  height: 30px;
  border: 1px solid rgba(136, 114, 255, 0.4);
  border-radius: 0;
  background: rgba(4, 4, 13, 0.72);
  color: var(--roll-text);
  padding: 4px 8px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
}

select {
  padding-right: 28px;
  text-overflow: ellipsis;
  text-transform: none;
}

select option,
select optgroup {
  background: var(--roll-panel-solid);
  color: var(--roll-text);
}

input:hover,
select:hover {
  border-color: var(--roll-violet);
}

input:focus,
select:focus {
  border-color: var(--roll-cyan);
  background: rgba(0, 217, 255, 0.055);
  box-shadow: 0 0 0 2px rgba(0, 217, 255, 0.12);
}

.method-fieldset label {
  grid-template-columns: minmax(0, 1fr) 190px;
}

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

.paired-fieldset legend {
  grid-column: 1 / -1;
}

.paired-fieldset label {
  min-width: 0;
  display: block;
  padding: 5px 0 7px;
}

.paired-fieldset label > span:first-child {
  min-height: 31px;
  display: block;
  margin-bottom: 4px;
}

.paired-fieldset .wide-input {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 152px;
  align-items: center;
}

.paired-fieldset .wide-input > span:first-child {
  min-height: 0;
  margin: 0;
}

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

#computedRollInputs legend {
  grid-column: 1 / -1;
}

#computedRollInputs label {
  min-width: 0;
  display: block;
  padding: 5px 0 7px;
}

#computedRollInputs label > span:first-child {
  min-height: 29px;
  display: block;
  margin-bottom: 4px;
}

#computedRollInputs label small {
  margin-left: 3px;
  color: var(--roll-orange);
  font: 600 8px/1 "IBM Plex Mono", monospace;
  letter-spacing: 0.06em;
}

.messages {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.message {
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--roll-line);
  border-left: 3px solid var(--roll-cyan);
  border-radius: 0;
  background: rgba(0, 217, 255, 0.055);
  color: #dffaff;
  font-size: 11px;
}

.message + .message {
  margin-top: 5px;
}

.message.warn {
  border-left-color: var(--roll-yellow);
  color: #fff7c1;
}

.message.bad {
  border-left-color: var(--roll-pink);
  color: #ffd6eb;
}

.results {
  grid-area: results;
  width: auto;
  height: auto;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  gap: 12px;
  padding: 16px 18px 18px;
  background: transparent;
}

.results-heading {
  flex: 0 0 auto;
}

.results-heading p {
  max-width: 520px;
  margin: 0;
  color: var(--roll-muted);
  font-size: 12px;
  line-height: 1.45;
  text-align: right;
}

.result-top {
  display: grid;
  grid-template-columns: minmax(145px, 0.75fr) minmax(320px, 1.8fr) minmax(220px, 1fr);
  gap: 10px;
  flex: 0 0 auto;
}

.metric {
  min-height: 110px;
  padding: 13px 14px;
  border: 1px solid var(--roll-line);
  border-radius: 0;
  background:
    linear-gradient(135deg, rgba(157, 108, 255, 0.07), transparent 48%),
    var(--roll-panel);
  box-shadow: none;
}

.metric-primary {
  border-left: 3px solid var(--roll-orange);
}

.metric-balance {
  border-left: 3px solid var(--roll-cyan);
}

.metric-stability {
  border-left: 3px solid var(--roll-violet);
}

.metric .name {
  margin: 0 0 7px;
  color: var(--roll-muted);
  font: 600 9px/1.2 "IBM Plex Mono", monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.metric .value {
  color: var(--roll-text);
  font: 600 25px/1 "IBM Plex Mono", monospace;
}

.metric .value small {
  margin-left: 4px;
  color: var(--roll-muted);
  font-size: 10px;
}

.metric .small {
  color: #9189a8;
  font-size: 10px;
  line-height: 1.3;
}

.metric-heading,
.balance-values,
.stability-values,
.balance-legend {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.balance-comparisons {
  display: flex;
  gap: 13px;
  text-align: right;
}

.balance-comparisons span,
.balance-values span,
.stability-values span {
  display: block;
  color: #8f87a5;
  font: 500 8px/1.2 "IBM Plex Mono", monospace;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.balance-comparisons b,
.balance-values b,
.stability-values b {
  color: var(--roll-text);
  font: 600 16px/1.2 "IBM Plex Mono", monospace;
}

.balance-values {
  justify-content: flex-start;
  margin-top: 5px;
}

.balance-values > div {
  min-width: 104px;
}

.balance-scale {
  position: relative;
  height: 24px;
  margin: 10px 2px 0;
  border-top: 1px solid rgba(136, 114, 255, 0.45);
  background:
    linear-gradient(90deg, transparent 49.7%, rgba(255, 255, 255, 0.18) 50%, transparent 50.3%);
}

.scale-tick {
  position: absolute;
  top: 7px;
  color: #77708f;
  font: 400 8px/1 "IBM Plex Mono", monospace;
}

.scale-start { left: 0; }
.scale-mid { left: 50%; transform: translateX(-50%); }
.scale-end { right: 0; }

.balance-marker {
  position: absolute;
  top: -8px;
  left: 50%;
  width: 16px;
  height: 16px;
  transform: translateX(-50%) rotate(45deg);
  border: 2px solid var(--roll-surface);
  transition: left 120ms ease;
}

.weight-marker {
  background: var(--roll-pink);
}

.lltd-marker {
  background: var(--roll-cyan);
}

.balance-legend {
  justify-content: flex-start;
  gap: 14px;
  color: #8f87a5;
  font-size: 9px;
}

.balance-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.balance-legend i {
  width: 6px;
  height: 6px;
}

.weight-key { background: var(--roll-pink); }
.lltd-key { background: var(--roll-cyan); }

.stability-values {
  justify-content: flex-start;
  margin: 15px 0 8px;
}

.stability-values > div {
  min-width: 82px;
}

.stability-values span {
  text-transform: none;
  white-space: nowrap;
}

.stability-values b {
  margin-top: 2px;
  font-size: 19px;
}

.tabs {
  flex: 0 0 auto;
  gap: 0;
  border-bottom: 1px solid var(--roll-line);
}

.tab-btn {
  min-width: 160px;
  height: 36px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--roll-muted);
  font: 600 10px/1 "IBM Plex Mono", monospace;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.tab-btn:hover {
  background: rgba(157, 108, 255, 0.06);
}

.tab-btn.active {
  border-color: var(--roll-cyan);
  background: rgba(0, 217, 255, 0.055);
  color: var(--roll-text);
}

#summaryTab {
  overflow: auto;
  scrollbar-color: var(--roll-violet) transparent;
  scrollbar-width: thin;
}

.panels {
  flex: 0 0 auto;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: auto auto;
  align-content: start;
  overflow: visible;
}

.panel {
  min-height: 0;
  border-color: var(--roll-line);
  border-radius: 0;
  background: var(--roll-panel);
}

.panel h2 {
  padding: 10px 11px;
  border-bottom-color: var(--roll-line);
  background: rgba(157, 108, 255, 0.07);
  color: var(--roll-text);
  font-size: 12px;
}

.transfer-visual {
  display: grid;
  gap: 7px;
  padding: 10px 11px 9px;
  border-bottom: 1px solid rgba(136, 114, 255, 0.16);
  background: rgba(4, 4, 13, 0.24);
}

.transfer-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  color: var(--roll-muted);
  font: 500 8px/1 "IBM Plex Mono", monospace;
  text-transform: uppercase;
}

.transfer-bar {
  height: 8px;
  display: flex;
  overflow: hidden;
  background: rgba(136, 114, 255, 0.1);
}

.transfer-bar > i {
  width: 0;
  height: 100%;
  transition: width 120ms ease;
}

.transfer-elastic { background: var(--roll-cyan); }
.transfer-geometric { background: var(--roll-orange); }
.transfer-unsprung { background: var(--roll-violet); }

.transfer-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-left: 44px;
  color: #8f87a5;
  font-size: 8px;
}

.transfer-legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.transfer-legend i {
  width: 5px;
  height: 5px;
}

table {
  font-size: 11px;
}

th,
td {
  padding: 6px 8px;
  border-bottom-color: rgba(136, 114, 255, 0.14);
  line-height: 1.25;
}

th {
  background: rgba(4, 4, 13, 0.32);
  color: var(--roll-muted);
}

.audit-panel {
  grid-column: 1 / -1;
  display: block;
}

.audit-panel > summary {
  position: relative;
  padding: 11px 36px 11px 12px;
  background: rgba(157, 108, 255, 0.07);
  color: var(--roll-text);
  font-size: 12px;
  list-style: none;
}

.audit-panel > summary::-webkit-details-marker {
  display: none;
}

.audit-panel > summary::after {
  content: "+";
  position: absolute;
  top: 9px;
  right: 12px;
  color: var(--roll-cyan);
  font: 500 17px/1 "IBM Plex Mono", monospace;
}

.audit-panel[open] > summary::after {
  content: "−";
}

.audit-panel > summary span {
  margin-left: 8px;
  color: var(--roll-muted);
  font-size: 10px;
  font-weight: 400;
}

.audit-content {
  max-height: 280px;
  overflow: auto;
}

.audit-content table {
  table-layout: auto;
}

.cross-grid {
  grid-template-columns: 440px minmax(0, 1fr);
  gap: 10px;
}

.cross-controls {
  overflow-y: auto;
  scrollbar-color: var(--roll-violet) transparent;
  scrollbar-width: thin;
}

.cross-controls label {
  grid-template-columns: minmax(0, 1fr) 220px;
}

.cross-plot-area {
  border-color: var(--roll-line);
  border-radius: 0;
  background: var(--roll-panel);
}

.plot-header,
.plot-toolbar,
.plot-note {
  border-color: var(--roll-line);
  background: rgba(16, 12, 35, 0.96);
}

.plot-title b {
  color: var(--roll-text);
  font-size: 14px;
}

.plot-title span,
.plot-note {
  color: var(--roll-muted);
}

.plot-stat {
  border-color: rgba(136, 114, 255, 0.18);
  color: var(--roll-muted);
  font-family: "IBM Plex Mono", monospace;
}

.plot-stat b {
  color: var(--roll-text);
}

.plot-stat:nth-child(n + 5) {
  display: none;
}

.plot-legend {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 10px 20px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--roll-line);
  background: rgba(11, 8, 27, 0.9);
}

.plot-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--roll-muted);
  font: 500 8px/1.25 "IBM Plex Mono", monospace;
  text-transform: uppercase;
}

.plot-legend-item > i {
  width: 34px;
  height: 6px;
  flex: 0 0 auto;
}

.plot-legend-item b {
  display: block;
  margin-top: 2px;
  color: var(--roll-text);
  font-size: 9px;
  text-transform: none;
}

.surface-legend-swatch {
  background: linear-gradient(90deg, #512b85, var(--roll-cyan), var(--roll-orange));
}

.solid-legend-swatch {
  height: 2px !important;
  background: var(--roll-text);
}

.dashed-legend-swatch {
  height: 2px !important;
  background: repeating-linear-gradient(90deg, var(--roll-pink) 0 4px, transparent 4px 9px);
}

.canvas-wrap,
#crossCanvas {
  background: #080615;
}

.canvas-wrap {
  width: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  align-self: center;
  flex: 1 1 0;
}

body.plot-maximized-open {
  overflow: hidden;
}

#crossPlotTab.plot-maximized {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex !important;
  min-width: 0;
  min-height: 0;
  padding: 14px;
  background:
    radial-gradient(circle at 70% 0, rgba(141, 55, 255, 0.2), transparent 32rem),
    var(--roll-bg);
}

#crossPlotTab.plot-maximized .cross-grid {
  width: 100%;
  height: 100%;
}

@media (max-width: 1360px) {
  .app {
    grid-template-columns: 400px minmax(0, 1fr);
  }

  .app-header {
    grid-template-columns: 400px minmax(160px, 1fr) auto;
  }

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

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

  .audit-panel {
    grid-column: 1 / -1;
  }

}

@media (max-width: 1000px) {
  html,
  body {
    height: auto;
    overflow: auto;
  }

  .app {
    display: grid;
    grid-template:
      "header" auto
      "inputs" auto
      "results" auto
      / minmax(0, 1fr);
    width: 100%;
    height: auto;
    overflow: visible;
  }

  .app-header {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 14px;
    padding: 12px 16px;
  }

  .app-title {
    display: none;
  }

  .app-toolbar {
    flex-wrap: wrap;
  }

  .inputs,
  .results {
    width: 100%;
    height: auto;
    overflow: visible;
    padding: 16px;
    border-right: 0;
  }

  .inputs {
    border-bottom: 1px solid var(--roll-line);
  }

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

  .tab-panel.active {
    display: block;
  }

  .cross-grid,
  .cross-grid.controls-collapsed {
    grid-template-columns: 1fr;
  }

  .cross-controls {
    max-height: none;
  }

  .cross-grid.controls-collapsed .cross-controls {
    display: none;
  }

  .cross-plot-area {
    min-height: 620px;
  }
}

@media (max-width: 680px) {
  .app-header {
    grid-template-columns: 1fr;
  }

  .app-toolbar {
    justify-content: flex-start;
  }

  .app-toolbar #copyInputsBtn,
  .account-link {
    display: none;
  }

  .results-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .results-heading p {
    text-align: left;
  }

  .result-top,
  .panels,
  #computedRollInputs {
    grid-template-columns: 1fr;
  }

  .audit-panel {
    grid-column: auto;
  }

  label,
  .cross-controls label {
    grid-template-columns: minmax(0, 1fr) 118px;
  }

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