:root {
  color-scheme: dark;
  --font-body: "Segoe UI", "Trebuchet MS", system-ui, sans-serif;
  --font-display: "Bahnschrift SemiBold", "Segoe UI", sans-serif;
  --radius-xl: 12px;
  --radius-lg: 8px;
  --radius-md: 4px;
  --shadow: 0 16px 38px rgba(0, 0, 0, 0.34);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #070b09;
  --bg-accent: #101611;
  --surface: rgba(15, 21, 17, 0.95);
  --surface-strong: rgba(21, 30, 24, 0.98);
  --surface-soft: rgba(182, 255, 77, 0.07);
  --text: #edf7ea;
  --muted: #a8b8a7;
  --line: rgba(182, 255, 77, 0.16);
  --accent: #b6ff4d;
  --accent-2: #ff6f3c;
  --danger: #ff536d;
  --wood: linear-gradient(135deg, #8d5c34, #5e3920);
  --stone: linear-gradient(135deg, #8b837c, #5c544d);
  --metal: linear-gradient(135deg, #9d7a58, #6d5139);
  --hqm: linear-gradient(135deg, #5a4130, #35251b);
  --planner-bg: #090f0b;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #eef4ea;
  --bg-accent: #dbe9d5;
  --surface: rgba(250, 255, 247, 0.95);
  --surface-strong: rgba(255, 255, 255, 0.98);
  --surface-soft: rgba(55, 118, 74, 0.08);
  --text: #152016;
  --muted: #5f705f;
  --line: rgba(55, 118, 74, 0.18);
  --accent: #37764a;
  --accent-2: #d95f32;
  --danger: #b94358;
  --wood: linear-gradient(135deg, #b07643, #7b4b28);
  --stone: linear-gradient(135deg, #b5aca2, #83796f);
  --metal: linear-gradient(135deg, #b69069, #866043);
  --hqm: linear-gradient(135deg, #7a5a43, #553b2b);
  --planner-bg: #eef5eb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--text);
  background:
    linear-gradient(150deg, rgba(182, 255, 77, 0.08), transparent 34%),
    linear-gradient(330deg, rgba(255, 111, 60, 0.08), transparent 28%),
    linear-gradient(135deg, var(--bg), var(--bg-accent));
}

button,
select,
input {
  font: inherit;
}

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

.topbar,
.hero-panel,
.panel {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  padding: 18px 20px;
  border-radius: var(--radius-xl);
  margin-bottom: 20px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-mark {
  position: relative;
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--accent) 46%, transparent);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--accent) 24%, transparent), transparent 52%),
    var(--surface-strong);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04), 0 14px 30px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}

.brand-mark span {
  position: relative;
  z-index: 1;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--text);
}

.brand-mark i {
  position: absolute;
  width: 34px;
  height: 7px;
  border: 1px solid color-mix(in srgb, var(--accent-2) 74%, transparent);
  background: rgba(255, 255, 255, 0.06);
  transform: rotate(-28deg);
}

.brand-mark i:nth-of-type(1) {
  right: -11px;
  top: 10px;
}

.brand-mark i:nth-of-type(2) {
  right: -5px;
  top: 26px;
}

.brand-mark i:nth-of-type(3) {
  right: 1px;
  top: 42px;
}

.brand-copy {
  min-width: 0;
}

.brand-block h1,
.hero-copy h2,
.panel-header h2 {
  margin: 0;
  font-family: var(--font-display);
  letter-spacing: 0;
}

.brand-block h1 {
  font-size: clamp(1.85rem, 4vw, 3rem);
  line-height: 1;
}

.eyebrow,
.section-kicker {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  color: var(--accent);
}

.lede,
.catalog-note,
.help-copy,
.hero-copy p {
  color: var(--muted);
}

.lede {
  margin: 8px 0 0;
}

.topbar-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.stat-chip,
.icon-button {
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--surface-strong);
}

.stat-chip {
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-chip span {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.icon-button,
.ghost-button,
.segment {
  color: var(--text);
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.icon-button {
  padding: 12px 16px;
}

.icon-button:hover,
.ghost-button:hover,
.segment:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--accent) 70%, transparent);
}

.app-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(360px, 0.68fr);
  gap: 20px;
}

.hero-panel {
  grid-column: 1 / -1;
  border-radius: var(--radius-xl);
  padding: 22px 24px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
}

.hero-copy {
  max-width: 70ch;
}

.hero-copy h2 {
  font-size: clamp(1.6rem, 4vw, 2.8rem);
}

.hero-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.hero-badges span {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(182, 255, 77, 0.12), rgba(255, 111, 60, 0.12));
  border: 1px solid var(--line);
  white-space: nowrap;
}

.panel {
  border-radius: var(--radius-xl);
  padding: 20px;
}

.planner-panel {
  min-width: 0;
}

.planner-workspace {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 18px;
}

.placement-sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
}

.sidebar {
  display: grid;
  gap: 20px;
  align-self: start;
}

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

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
  margin-bottom: 16px;
}

.planner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.level-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.ghost-button,
.segment,
select,
input[type="number"] {
  border: 1px solid var(--line);
  background: var(--surface-strong);
}

.ghost-button,
.segment {
  padding: 10px 14px;
  border-radius: var(--radius-md);
}

.danger-button {
  color: var(--danger);
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 320px) minmax(280px, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.mode-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tool-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tool-group.compact {
  justify-content: center;
}

.group-label,
.field span,
.catalog-meta {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-start;
}

.segmented.vertical {
  flex-direction: column;
  flex-wrap: nowrap;
}

.segmented.vertical .segment {
  width: 100%;
  text-align: left;
}

.segment.is-active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #1a120d;
  font-weight: 700;
}

.segment:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

select,
input[type="number"] {
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius-md);
  color: var(--text);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.grid-frame {
  padding: 14px;
  border-radius: calc(var(--radius-xl) - 4px);
  background: var(--planner-bg);
  border: 1px solid var(--line);
  overflow: hidden;
  position: relative;
  cursor: grab;
  min-height: 860px;
  user-select: none;
  touch-action: none;
}

.grid-frame.is-panning {
  cursor: grabbing;
}

#planner-svg {
  width: 1120px;
  height: 1120px;
  display: block;
  transform-origin: top left;
  will-change: transform;
}

.hover-tooltip {
  position: absolute;
  z-index: 3;
  max-width: 220px;
  pointer-events: none;
  padding: 10px 12px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--surface-strong);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.22);
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.4;
}

.hover-tooltip strong {
  display: block;
  margin-bottom: 4px;
}

.planner-status {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

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

.summary-card[hidden],
.other-materials[hidden] {
  display: none;
}

.summary-card {
  border-radius: var(--radius-lg);
  padding: 16px;
  color: white;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.summary-card strong {
  font-size: 1.65rem;
}

.summary-card small {
  color: rgba(255, 255, 255, 0.84);
}

.summary-card.wood { background: var(--wood); }
.summary-card.stone { background: var(--stone); }
.summary-card.metal { background: var(--metal); }
.summary-card.hqm { background: var(--hqm); }

.other-materials {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  background: var(--surface-soft);
  border: 1px solid var(--line);
}

.other-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.other-breakdown {
  color: var(--muted);
  font-size: 0.92rem;
}

.analyst-toggle {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.raid-analyst {
  display: grid;
  gap: 10px;
}

.view3d-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 13 / 9;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--planner-bg);
  cursor: grab;
  touch-action: none;
}

.view3d-canvas.is-dragging {
  cursor: grabbing;
}

.totals {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.total-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
}

.field-stack,
.field {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field-inline {
  display: flex;
  align-items: center;
  gap: 12px;
}

.breakdown-list {
  display: grid;
  gap: 14px;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 12px;
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  border: 1px solid var(--line);
}

.share-link-input {
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--text);
}

.field-stack.tight {
  gap: 8px;
}

.share-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 20px;
  padding: 16px 4px 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

body.print-export {
  background: #f4ede2;
  color: #1f1711;
}

body.print-export .topbar-actions,
body.print-export .hero-panel,
body.print-export .mode-bar,
body.print-export .toolbar,
body.print-export #planner-status,
body.print-export .share-panel {
  display: none;
}

body.print-export .app-shell {
  max-width: 1180px;
  padding: 18px;
}

body.print-export .topbar,
body.print-export .panel {
  background: #fffaf2;
  border-color: rgba(91, 57, 34, 0.2);
  box-shadow: none;
}

body.print-export .app-grid {
  grid-template-columns: 1fr;
}

body.print-export .planner-panel {
  order: 1;
}

body.print-export .sidebar {
  order: 2;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

body.print-export.hide-upkeep .upkeep-panel,
body.print-export.hide-raid .raid-panel,
body.print-export.hide-breakdown .breakdown-panel {
  display: none;
}

@media print {
  body {
    background: #f4ede2 !important;
  }

  .topbar-actions,
  .hero-panel,
  .mode-bar,
  .toolbar,
  #planner-status,
  .share-panel {
    display: none !important;
  }

  .app-grid {
    grid-template-columns: 1fr !important;
  }

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

.insert-shell {
  overflow: hidden;
  max-height: 120px;
  opacity: 1;
  transform: translateX(0);
  transition: max-height 180ms ease, opacity 180ms ease, transform 180ms ease, margin 180ms ease;
}

.insert-shell.is-collapsed {
  max-height: 0;
  opacity: 0;
  transform: translateX(-10px);
  margin-top: -6px;
  pointer-events: none;
}

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

  .planner-workspace {
    grid-template-columns: 1fr;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }
}

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

  .topbar,
  .hero-panel {
    flex-direction: column;
    align-items: stretch;
  }

  .brand-block,
  .site-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .planner-actions,
  .hero-badges {
    justify-content: flex-start;
  }
}
