/* Theme variables used throughout the app. */
:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #141820;
  --panel-soft: #1b202a;
  --line: #2d3542;
  --text: #eef2f7;
  --muted: #a4afbf;
  --gold: #f2be4b;
  --cyan: #68d8ef;
  --green: #87d37c;
  --red: #ff7a7a;
  --violet: #b69cff;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.36);
}

/* Keep padding and borders inside declared element sizes. */
* {
  box-sizing: border-box;
}

/* Page-level dark theme and subtle background lighting. */
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background:
    radial-gradient(circle at 18% 16%, rgba(242, 190, 75, 0.18), transparent 28rem),
    linear-gradient(135deg, rgba(104, 216, 239, 0.08), transparent 34rem),
    var(--bg);
}

/* Form controls inherit the app font instead of browser defaults. */
button,
input,
select,
textarea {
  font: inherit;
}

/* Buttons are all clickable controls, so show the pointer cursor globally. */
button {
  cursor: pointer;
}

/* Outer page padding and max readable app width. */
.app-shell {
  width: min(1680px, 100%);
  margin: 0 auto;
  padding: 24px;
}

/* Main framed app surface. */
.calculator-panel {
  overflow: hidden;
  min-height: calc(100vh - 48px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(20, 24, 32, 0.94);
  box-shadow: var(--shadow);
}

/* Header row containing the title and import/export/reset controls. */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(242, 190, 75, 0.15), transparent),
    rgba(255, 255, 255, 0.02);
}

/* Small label above the main title. */
.eyebrow {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 0.77rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

/* Reset heading and paragraph top margins for tighter layout control. */
h1,
h2,
p {
  margin-top: 0;
}

/* Responsive app title sizing. */
h1 {
  margin-bottom: 0;
  font-size: clamp(1.5rem, 2.5vw, 2.4rem);
  letter-spacing: 0;
}

/* Compact section headings used inside panels. */
h2 {
  margin-bottom: 0;
  font-size: 0.98rem;
  letter-spacing: 0;
}

/* Shared horizontal alignment for toolbar-like rows. */
.topbar-actions,
.filters,
.form-title,
.section-heading {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Hover/focus explanation bubbles for compact icon controls. */
.tooltip-control {
  position: relative;
}

.tooltip-control::after {
  position: absolute;
  z-index: 10;
  top: calc(100% + 10px);
  right: 0;
  width: max-content;
  max-width: 230px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--text);
  background: #0f1218;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  content: attr(data-tooltip);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition:
    opacity 140ms ease,
    transform 140ms ease;
}

.tooltip-control:hover::after,
.tooltip-control:focus-visible::after,
.tooltip-control:focus-within::after {
  opacity: 1;
  transform: translateY(0);
}

/* Section headers with optional actions on the right side. */
.section-heading {
  justify-content: space-between;
  margin: 20px 0 12px;
}

/* Main three-column desktop layout. */
.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr) minmax(280px, 360px);
  min-height: calc(100vh - 140px);
}

/* Shared column padding. */
.loadout-column,
.results-column,
.editor-column {
  padding: 20px;
}

/* Side columns get a subtle contrast from the center results area. */
.loadout-column,
.editor-column {
  background: rgba(255, 255, 255, 0.025);
}

/* Divider between the setup column and the results column. */
.loadout-column {
  border-right: 1px solid var(--line);
}

/* Divider between the results column and the editor column. */
.editor-column {
  border-left: 1px solid var(--line);
}

/* Shared card surface styling. */
.base-card,
.formula-card,
.modifier-form,
.result-tile,
.active-item,
.modifier-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

/* Base damage input card spacing. */
.base-card {
  padding: 16px;
}

/* Label layout for every form field. */
label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

/* Inputs, selects, and textareas share the same control styling. */
input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  color: var(--text);
  background: #0f1218;
  outline: none;
}

/* Notes fields can grow vertically when needed. */
textarea {
  resize: vertical;
}

/* Visible keyboard/mouse focus state for form controls. */
input:focus,
select:focus,
textarea:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(104, 216, 239, 0.13);
}

/* Shared button/control shell. */
.icon-button,
.filter-chip,
.ghost,
.section-heading button,
.primary-button,
.small-button,
.text-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #10141b;
}

/* Square icon-style buttons in the header and modifier cards. */
.icon-button {
  display: inline-grid;
  min-width: 40px;
  padding: 0 8px;
  place-items: center;
  font-size: 0.82rem;
  font-weight: 900;
}

/* Hide the native file input while keeping the styled label clickable. */
.file-button input {
  display: none;
}

/* Red action color for destructive controls. */
.danger {
  color: var(--red);
}

/* Primary submit button in the editor form. */
.primary-button {
  width: 100%;
  border-color: rgba(242, 190, 75, 0.65);
  color: #17120a;
  font-weight: 900;
  background: var(--gold);
}

/* Category filter buttons. */
.filter-chip {
  padding: 0 12px;
  color: var(--muted);
}

/* Active category filter state. */
.filter-chip.active {
  border-color: var(--cyan);
  color: var(--text);
  background: rgba(104, 216, 239, 0.14);
}

/* Three result tiles across the top of the results column. */
.result-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

/* Individual result tile dimensions. */
.result-tile {
  min-height: 116px;
  padding: 16px;
}

/* Result tile label text. */
.result-tile span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

/* Large numeric result text. */
.result-tile strong {
  display: block;
  margin-top: 16px;
  font-size: clamp(1.45rem, 3vw, 2.35rem);
  line-height: 1;
}

/* Card that explains how the final multiplier was built. */
.formula-card {
  margin-top: 12px;
  padding: 16px;
}

/* Container for non-stacking warnings generated by the active modifier selection. */
.stack-warnings {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

/* Warning cards explain which modifier is ignored and why. */
.stack-warning {
  display: grid;
  gap: 4px;
  border: 1px solid rgba(255, 122, 122, 0.45);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--text);
  background: rgba(255, 122, 122, 0.1);
}

.stack-warning span {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

/* Small spacing tweak for the dedicated weapon perk card grid. */
.weapon-perk-library {
  padding-bottom: 8px;
}

/* Stack trace body copy. */
.formula-card p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

/* Grid containers for selected modifiers and available modifiers. */
.active-list,
.modifier-library {
  display: grid;
  gap: 10px;
}

/* Empty states for lists with no visible records. */
.active-empty,
.library-empty {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

/* Shared inner spacing for modifier cards and active rows. */
.active-item,
.modifier-card {
  padding: 14px;
}

/* Active modifiers show text on the left and a remove button on the right. */
.active-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

/* Responsive card grid for modifier libraries. */
.modifier-library {
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
}

/* Modifier card internals stack vertically. */
.modifier-card {
  display: grid;
  gap: 12px;
}

/* Highlight a card when it is part of the active calculation. */
.modifier-card.active {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 1px rgba(242, 190, 75, 0.35);
}

/* Card headers align the name and percentage value. */
.modifier-card header,
.active-item header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

/* Modifier names inside cards and active rows. */
.modifier-card h3,
.active-item h3 {
  margin: 0;
  font-size: 0.98rem;
}

/* Tag rows wrap so long card metadata does not overflow. */
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Default tag pill style. */
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  color: #12161c;
  font-size: 0.72rem;
  font-weight: 900;
  background: var(--cyan);
}

/* Category-specific tag colors. */
.tag.buff {
  background: var(--green);
}

.tag.debuff {
  background: var(--red);
}

.tag.surge {
  background: var(--gold);
}

.tag.ability {
  background: var(--violet);
}

/* Modifier notes and source text. */
.modifier-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

/* Add/edit/delete button layout on each card. */
.card-actions {
  display: grid;
  grid-template-columns: 1fr 40px minmax(72px, auto);
  gap: 8px;
}

/* Compact text buttons such as Add/Active. */
.small-button {
  padding: 0 10px;
}

/* Clear text action used where a single X could be confused with clearing active modifiers. */
.text-button {
  padding: 0 11px;
  font-size: 0.78rem;
  font-weight: 800;
}

/* Sticky editor form on wide screens. */
.modifier-form {
  display: grid;
  gap: 14px;
  padding: 16px;
  position: sticky;
  top: 20px;
}

/* Header row inside the add/edit form. */
.form-title {
  justify-content: space-between;
}

/* Two-column form row for compact field pairs. */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Utility class for controls that should not currently be visible. */
.hidden {
  display: none;
}

/* Tablet layout: editor drops below the main two-column workspace. */
@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .editor-column {
    grid-column: 1 / -1;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .modifier-form {
    position: static;
  }
}

/* Mobile layout: everything becomes a single column. */
@media (max-width: 780px) {
  .app-shell {
    padding: 12px;
  }

  .calculator-panel {
    min-height: calc(100vh - 24px);
  }

  .topbar,
  .workspace,
  .result-grid,
  .two-col {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .loadout-column,
  .editor-column {
    border: 0;
  }

  .loadout-column,
  .results-column,
  .editor-column {
    padding: 16px;
  }

  .filters {
    flex-wrap: wrap;
  }
}
