/* ============================================================
   base.css — reset, typography, CSS custom properties, themes
   ============================================================ */

/* ---------- Theme definitions ---------- */

:root,
[data-theme="sunrise"] {
  --bg:           #fffbf3;
  --surface:      #fff8ec;
  --card:         #ffffff;
  --accent:       #f59e0b;
  --accent-hover: #d97706;
  --accent-text:  #ffffff;
  --text:         #1c1917;
  --text-muted:   #78716c;
  --border:       #e7e5e4;
  --input-bg:     #fafaf9;
  --shadow:       0 1px 4px rgba(0,0,0,.08), 0 2px 12px rgba(0,0,0,.05);
  --radius:       10px;
  --font:         'Inter', system-ui, -apple-system, sans-serif;
}

[data-theme="beach"] {
  --bg:           #f0f9ff;
  --surface:      #e0f2fe;
  --card:         #ffffff;
  --accent:       #0ea5e9;
  --accent-hover: #0284c7;
  --accent-text:  #ffffff;
  --text:         #0c4a6e;
  --text-muted:   #0369a1;
  --border:       #bae6fd;
  --input-bg:     #f0f9ff;
  --shadow:       0 1px 4px rgba(14,165,233,.1), 0 2px 12px rgba(14,165,233,.06);
  --radius:       10px;
  --font:         'Inter', system-ui, -apple-system, sans-serif;
}

[data-theme="rainstorm"] {
  --bg:           #1e293b;
  --surface:      #263348;
  --card:         #334155;
  --accent:       #38bdf8;
  --accent-hover: #0ea5e9;
  --accent-text:  #0c4a6e;
  --text:         #f1f5f9;
  --text-muted:   #94a3b8;
  --border:       #475569;
  --input-bg:     #1e293b;
  --shadow:       0 1px 4px rgba(0,0,0,.3), 0 2px 12px rgba(0,0,0,.2);
  --radius:       10px;
  --font:         'Inter', system-ui, -apple-system, sans-serif;
}

[data-theme="chalet"] {
  --bg:           #fdf6ee;
  --surface:      #faecd8;
  --card:         #ffffff;
  --accent:       #c2410c;
  --accent-hover: #9a3412;
  --accent-text:  #ffffff;
  --text:         #431407;
  --text-muted:   #7c2d12;
  --border:       #fed7aa;
  --input-bg:     #fdf6ee;
  --shadow:       0 1px 4px rgba(194,65,12,.1), 0 2px 12px rgba(194,65,12,.06);
  --radius:       10px;
  --font:         'Inter', system-ui, -apple-system, sans-serif;
}

[data-theme="midnight"] {
  --bg:           #09090b;
  --surface:      #18181b;
  --card:         #27272a;
  --accent:       #a78bfa;
  --accent-hover: #8b5cf6;
  --accent-text:  #ffffff;
  --text:         #fafafa;
  --text-muted:   #a1a1aa;
  --border:       #3f3f46;
  --input-bg:     #18181b;
  --shadow:       0 1px 4px rgba(0,0,0,.5), 0 2px 12px rgba(0,0,0,.3);
  --radius:       10px;
  --font:         'Inter', system-ui, -apple-system, sans-serif;
}

[data-theme="wow"] {
  --bg:           #04011a;
  --surface:      #0c0330;
  --card:         #180950;
  --accent:       #f000b8;
  --accent-hover: #cc0099;
  --accent-text:  #ffffff;
  --text:         #f0e6ff;
  --text-muted:   #c084fc;
  --border:       #5b21b6;
  --input-bg:     #0c0330;
  --shadow:       0 1px 4px rgba(240,0,184,.3), 0 2px 16px rgba(240,0,184,.18);
  --radius:       10px;
  --font:         'Inter', system-ui, -apple-system, sans-serif;
}

/* ---------- Reset ---------- */

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

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  transition: background .25s, color .25s;
}

img, svg { display: block; max-width: 100%; }

button { cursor: pointer; font: inherit; border: none; background: none; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--input-bg);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Typography ---------- */

h1 { font-size: 1.75rem; font-weight: 700; line-height: 1.2; }
h2 { font-size: 1.35rem; font-weight: 700; line-height: 1.3; }
h3 { font-size: 1.1rem;  font-weight: 600; line-height: 1.4; }

p { line-height: 1.6; }

small, .text-sm { font-size: .875rem; }
.text-muted { color: var(--text-muted); }

/* ---------- Form elements ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
}

.field label {
  font-size: .8125rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--input-bg);
  border: 1.5px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  color: var(--text);
  font-size: .9375rem;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.field textarea {
  resize: vertical;
  min-height: 80px;
}

.field-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.field-row .field {
  min-width: 120px;
}

/* ---------- Calc button ---------- */

.calc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 22px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: .9375rem;
  font-weight: 600;
  border-radius: calc(var(--radius) - 2px);
  border: none;
  cursor: pointer;
  transition: background .15s, transform .08s;
  white-space: nowrap;
}

.calc-btn:hover  { background: var(--accent-hover); }
.calc-btn:active { transform: scale(.97); }

.calc-btn.secondary {
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--border);
}
.calc-btn.secondary:hover { background: var(--border); }

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 20px;
}

.tab {
  flex: 1;
  padding: 7px 14px;
  border-radius: calc(var(--radius) - 4px);
  font-size: .875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  cursor: pointer;
  transition: background .15s, color .15s;
  border: none;
  background: none;
}

.tab:hover { color: var(--text); background: var(--card); }

.tab.active {
  background: var(--card);
  color: var(--accent);
  box-shadow: var(--shadow);
}

/* ---------- Results ---------- */

.results {
  margin-top: 20px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  border: 1.5px solid var(--border);
  display: none;
  flex-direction: column;
  gap: 8px;
}

.results.show { display: flex; }

.result-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
}

.result-row + .result-row {
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.result-label {
  font-size: .875rem;
  color: var(--text-muted);
  flex: 1;
}

.result-value {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.result-value.accent { color: var(--accent); }
.result-value.large  { font-size: 1.4rem; }

/* ---------- Toggle (metric/imperial) ---------- */

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .875rem;
  color: var(--text-muted);
}

.toggle {
  position: relative;
  width: 44px;
  height: 24px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: background .2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ---------- Preset buttons ---------- */

.presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.preset-btn {
  padding: 4px 12px;
  font-size: .8125rem;
  font-weight: 600;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
}

.preset-btn:hover,
.preset-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

/* ---------- Viz bar ---------- */

.viz-bar {
  height: 12px;
  border-radius: 6px;
  background: var(--border);
  overflow: hidden;
  margin: 8px 0;
}

.viz-bar-fill {
  height: 100%;
  border-radius: 6px;
  background: var(--accent);
  transition: width .4s ease;
}

.viz-bar-fill.secondary {
  background: var(--text-muted);
}

/* stacked bar wrapper */
.viz-bar-stacked {
  display: flex;
  height: 100%;
}

.viz-bar-stacked .viz-bar-fill {
  border-radius: 0;
}

.viz-bar-stacked .viz-bar-fill:first-child {
  border-radius: 6px 0 0 6px;
}

.viz-bar-stacked .viz-bar-fill:last-child {
  border-radius: 0 6px 6px 0;
}

/* ---------- Utility ---------- */

.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }

.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

.applet-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.applet-desc {
  font-size: .875rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.applet-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── Help block ─────────────────────────────────────────── */
.help-block {
  margin-top: 20px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.help-toggle {
  cursor: pointer;
  padding: 10px 14px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  list-style: none;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.help-toggle::-webkit-details-marker { display: none; }
.help-toggle::after { content: '▾'; margin-left: auto; }
details[open] > .help-toggle::after { content: '▴'; }
.help-body {
  padding: 2px 14px 14px;
  font-size: .82rem;
  color: var(--text);
  line-height: 1.6;
}
.help-body h4 {
  font-size: .74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin: 12px 0 3px;
}
.help-body p { margin: 0; }
.help-what { font-style: italic; color: var(--text-muted); }
.help-body ul { margin: 3px 0 0; padding-left: 16px; }
.help-body li { margin-bottom: 3px; }
/* ============================================================
   Applet story section — publisher content for each calculator
   ============================================================ */
.applet-story {
  margin: 28px 0 8px;
  padding: 18px 20px 14px;
  border-top: 1px solid var(--border);
  border-radius: 0 0 10px 10px;
}

.applet-story-intro {
  margin: 0 0 10px;
  font-size: .875rem;
  line-height: 1.65;
  color: var(--text-muted);
}

.applet-story-examples {
  margin: 0;
  padding: 0 0 0 18px;
  list-style: disc;
}

.applet-story-examples li {
  font-size: .82rem;
  line-height: 1.6;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.applet-story-examples li:last-child {
  margin-bottom: 0;
}
