/* 5ehp.app Design System — Minimalist Light/Dark App Theme */
:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --text: #0f172a;
  --text-muted: #475569;
  --text-soft: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --primary-text: #3730a3;
  --amber-bg: #fffbeb;
  --amber-bg-alt: #fef3c7;
  --amber-border: #f59e0b;
  --amber-text: #92400e;
  --amber-heading: #78350f;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.07);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-alt: #1e293b;
  --text: #f8fafc;
  --text-muted: #cbd5e1;
  --text-soft: #94a3b8;
  --border: #1e293b;
  --border-strong: #334155;
  --primary: #818cf8;
  --primary-hover: #6366f1;
  --primary-soft: rgba(99, 102, 241, 0.16);
  --primary-text: #c7d2fe;
  --amber-bg: #1f1910;
  --amber-bg-alt: #2d2210;
  --amber-border: #d97706;
  --amber-text: #fcd34d;
  --amber-heading: #fde68a;
  --success: #34d399;
  --success-soft: rgba(16, 185, 129, 0.14);
  --warn: #fbbf24;
  --warn-soft: rgba(245, 158, 11, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(239, 68, 68, 0.14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.45);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

/* Top Compact App Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  font-size: 1.08rem;
  color: var(--text);
  letter-spacing: -0.025em;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.brand-link:hover {
  text-decoration: none;
  transform: translateY(-1px);
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  flex-shrink: 0;
  display: block;
  box-shadow: 0 2px 8px rgba(225, 29, 72, 0.28);
}

.brand-wordmark {
  display: inline-flex;
  align-items: baseline;
  gap: 1px;
  line-height: 1;
}

.brand-five {
  color: var(--text);
  font-weight: 900;
}

.brand-hp {
  background: linear-gradient(135deg, #e11d48 0%, #f59e0b 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-weight: 900;
}

.brand-tld {
  margin-left: 3px;
  padding: 2px 5px;
  border-radius: 5px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: var(--primary-soft);
  color: var(--primary-text);
  border: 1px solid var(--border-strong);
  transform: translateY(-1px);
}

.tool-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 2px 0;
}

.tool-nav::-webkit-scrollbar {
  display: none;
}

.tool-pill {
  display: inline-flex;
  align-items: center;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.tool-pill:hover {
  background: var(--surface-alt);
  color: var(--text);
  text-decoration: none;
}

.tool-pill.active {
  background: var(--primary-soft);
  color: var(--primary-text);
}

.theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  flex-shrink: 0;
}

.theme-btn:hover {
  border-color: var(--border-strong);
}

/* Main Container */
.main-wrap {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px 48px;
  flex: 1;
}

/* Above-the-Fold Tool Stage */
.tool-stage {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 20px 22px 22px;
  margin-bottom: 28px;
}

.stage-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.page-title {
  margin: 0;
  font-size: clamp(1.35rem, 2.5vw, 1.75rem);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.stage-sub {
  margin: 4px 0 0;
  font-size: 0.92rem;
  color: var(--text-muted);
}

/* Segmented Toggle Pills */
.seg-control {
  display: inline-flex;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}

.seg-btn.active {
  background: var(--surface);
  color: var(--primary-text);
  box-shadow: var(--shadow-sm);
}

/* Mad-Libs Sentence UI */
.sentence-card {
  text-align: center;
  padding: 10px 6px 14px;
}

.sentence-line {
  font-size: clamp(1.08rem, 2.2vw, 1.28rem);
  font-weight: 500;
  line-height: 2.1;
  color: var(--text);
  margin: 6px 0;
}

.inline-select,
.inline-num {
  font-family: inherit;
  font-size: 1em;
  font-weight: 700;
  color: var(--primary-text);
  background: var(--primary-soft);
  border: 0;
  border-bottom: 2px solid var(--primary);
  border-radius: 6px 6px 2px 2px;
  padding: 2px 8px;
  margin: 0 3px;
  cursor: pointer;
  vertical-align: baseline;
  transition: background-color 0.15s ease;
}

.inline-select:focus,
.inline-num:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.inline-num {
  width: 3.4em;
  text-align: center;
  -moz-appearance: textfield;
}

.inline-num::-webkit-outer-spin-button,
.inline-num::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.stepper-wrap {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  margin: 0 4px;
}

.stepper-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface-alt);
  color: var(--text);
  font-weight: 800;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.stepper-btn:hover {
  background: var(--border);
}

.multiclass-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px auto;
  max-width: 720px;
}

.multiclass-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1.05rem;
}

.remove-row-btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--danger);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.remove-row-btn:hover {
  background: var(--danger-soft);
}

.modifier-checks {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 18px;
  margin: 12px 0 6px;
}

.check-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.check-chip:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-text);
}

.check-chip input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  margin: 0;
  cursor: pointer;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.btn:hover {
  background: var(--surface-alt);
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
  color: #ffffff;
}

.btn-ghost {
  background: var(--surface-alt);
  border-color: var(--border);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.82rem;
  border-radius: 7px;
}

/* Warm Amber Result Card (Core Flagship Output) */
.result-banner {
  margin-top: 16px;
  background: var(--amber-bg);
  border-top: 3px solid var(--amber-border);
  border-bottom: 3px solid var(--amber-border);
  border-radius: 10px;
  padding: 18px 18px 16px;
  text-align: center;
}

.mode-radios {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 24px;
  margin-bottom: 10px;
}

.mode-radio {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--amber-heading);
  cursor: pointer;
}

.mode-radio input {
  width: 17px;
  height: 17px;
  accent-color: var(--amber-border);
  cursor: pointer;
}

.big-result {
  font-size: clamp(2.6rem, 6vw, 3.6rem);
  font-weight: 900;
  line-height: 1.05;
  color: var(--amber-heading);
  margin: 4px 0 8px;
  letter-spacing: -0.03em;
}

.result-unit {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--amber-text);
  margin-left: 6px;
}

.breakdown-lines {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--amber-text);
}

.breakdown-lines strong {
  color: var(--amber-heading);
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
}

.result-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  margin-top: 10px;
}

.status-ok {
  background: var(--success-soft);
  color: var(--success);
}

.status-warn {
  background: var(--danger-soft);
  color: var(--danger);
}

/* Interactive Per-Level Roll Grid */
.roll-panel {
  margin-top: 14px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-align: left;
}

.roll-panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.roll-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 8px;
}

.roll-cell {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.roll-cell-label {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-muted);
}

.roll-cell-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.roll-input {
  width: 48px;
  padding: 3px 4px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  text-align: center;
  font-size: 0.92rem;
}

/* Next-Step Bar */
.next-step-bar {
  margin-top: 14px;
  padding: 10px 14px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.9rem;
}

.next-step-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Companion Tool Grids (Point Buy / AC / Hit Dice / Temp HP) */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 10px;
}

.field-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

.field-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 6px;
}

.field-select,
.field-input {
  width: 100%;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
}

.ability-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.ability-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 10px;
  text-align: center;
}

.ability-card.highlight-con {
  border-color: var(--amber-border);
  background: var(--amber-bg);
}

.ability-name {
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.ability-total {
  font-size: 1.9rem;
  font-weight: 900;
  line-height: 1.1;
  margin: 4px 0;
}

.ability-mod {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-text);
  font-weight: 800;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.budget-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin: 10px 0;
  font-weight: 700;
}

/* Below-the-Fold Publisher Content */
.content-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 24px;
  margin-bottom: 22px;
  box-shadow: var(--shadow-sm);
}

.content-section h2 {
  margin: 0 0 12px;
  font-size: 1.38rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.content-section h3 {
  margin: 20px 0 8px;
  font-size: 1.08rem;
  font-weight: 700;
}

.content-section p {
  margin: 0 0 12px;
  color: var(--text-muted);
}

.content-section ul,
.content-section ol {
  margin: 0 0 14px;
  padding-left: 22px;
  color: var(--text-muted);
}

.content-section li {
  margin-bottom: 6px;
}

.formula-box {
  background: var(--surface-alt);
  border-left: 4px solid var(--primary);
  padding: 12px 16px;
  border-radius: 0 8px 8px 0;
  font-family: var(--font-mono);
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  margin: 12px 0;
  overflow-x: auto;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 14px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  text-align: left;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  background: var(--surface-alt);
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:hover {
  background: var(--surface-alt);
}

.edition-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin: 14px 0;
}

.edition-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

.edition-card h3 {
  margin-top: 0;
}

.faq-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.faq-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  padding: 0;
}

.faq-item summary {
  padding: 12px 16px;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.faq-item summary::after {
  content: "+";
  font-size: 1.2rem;
  color: var(--primary);
  flex-shrink: 0;
}

.faq-item[open] summary::after {
  content: "−";
}

.faq-body {
  padding: 0 16px 14px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.faq-body p:last-child {
  margin-bottom: 0;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 60;
  background: #0f172a;
  color: #f8fafc;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Footer */
.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 26px 16px 32px;
  margin-top: auto;
}

.footer-inner {
  max-width: 960px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 20px;
}

.footer-col h3 {
  margin: 0 0 8px;
  font-size: 0.9rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text);
}

.footer-links {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.9rem;
}

.footer-legal {
  max-width: 960px;
  margin: 18px auto 0;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-soft);
  line-height: 1.5;
}

@media (max-width: 640px) {
  .tool-stage {
    padding: 16px 14px 18px;
  }
  .content-section {
    padding: 18px 16px;
  }
  .header-inner {
    padding: 0 10px;
    gap: 8px;
  }
}

@media print {
  .app-header, .site-footer, .next-step-bar, .result-actions, .row-actions, .theme-btn {
    display: none !important;
  }
  body {
    background: #ffffff;
    color: #000000;
  }
  .tool-stage, .content-section {
    box-shadow: none;
    border: 1px solid #cbd5e1;
  }
}
