/* ========== CSS CUSTOM PROPERTIES ========== */
:root {
  --color-bg: #f3f4f6;
  --color-surface: #ffffff;
  --color-text: #1f2937;
  --color-text-muted: #6b7280;
  --color-accent: #2563eb;
  --color-accent-light: #dbeafe;
  --color-accent-dark: #1d4ed8;
  --color-success: #16a34a;
  --color-success-light: #dcfce7;
  --color-warning: #d97706;
  --color-warning-light: #fef3c7;
  --color-danger: #dc2626;
  --color-danger-light: #fee2e2;
  --color-border: #e5e7eb;
  --token-0: #bfdbfe; --token-1: #fde68a; --token-2: #bbf7d0; --token-3: #fecaca;
  --token-4: #e9d5ff; --token-5: #fed7aa; --token-6: #a5f3fc; --token-7: #fbcfe8;
  --space-xs: 0.25rem; --space-sm: 0.5rem; --space-md: 1rem; --space-lg: 1.5rem;
  --space-xl: 2rem; --space-2xl: 3rem; --space-3xl: 4rem;
  --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Courier New', Courier, monospace;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --duration: 300ms;
  --max-width: 960px;
  --nav-h: 48px;
}

/* ========== RESET ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font-body); font-size: 1rem; line-height: 1.6; color: var(--color-text); background: var(--color-bg); }
img, svg { display: block; max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }

/* ========== TYPOGRAPHY ========== */
h1 { font-size: 2rem; line-height: 1.2; font-weight: 700; }
h2 { font-size: 1.5rem; line-height: 1.3; font-weight: 700; margin-bottom: var(--space-md); }
h3 { font-size: 1.2rem; line-height: 1.4; font-weight: 600; margin-bottom: var(--space-sm); }
h4 { font-size: 1.05rem; line-height: 1.4; font-weight: 600; margin-bottom: var(--space-sm); }
p { margin-bottom: var(--space-md); }
small { font-size: 0.875rem; color: var(--color-text-muted); }

/* ========== LAYOUT ========== */
.container { max-width: var(--max-width); margin: 0 auto; padding: 0 var(--space-lg); }
section { padding: var(--space-3xl) 0; }
section:nth-child(odd of section) { background: var(--color-surface); }
section:nth-child(even of section) { background: var(--color-bg); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-lg); }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--space-md); }
.grid-6040 { display: grid; grid-template-columns: 3fr 2fr; gap: var(--space-lg); align-items: start; }

/* ========== STICKY NAV ========== */
nav { position: sticky; top: 0; z-index: 100; background: var(--color-surface); border-bottom: 1px solid var(--color-border); box-shadow: 0 1px 4px rgba(0,0,0,0.06); height: var(--nav-h); }
nav .container { display: flex; align-items: center; gap: var(--space-md); overflow-x: auto; height: 100%; }
nav .nav-brand { font-weight: 700; color: var(--color-accent); white-space: nowrap; font-size: 0.95rem; }
nav a { text-decoration: none; color: var(--color-text-muted); font-size: 0.85rem; white-space: nowrap; padding: var(--space-xs) var(--space-sm); border-radius: var(--radius); transition: color var(--duration) var(--ease), background var(--duration) var(--ease); }
nav a:hover, nav a.active { color: var(--color-accent); background: var(--color-accent-light); }

/* ========== COMPONENTS ========== */
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-xl); box-shadow: var(--shadow); margin-bottom: var(--space-lg); }
.card--interactive { border: 2px solid var(--color-accent-light); box-shadow: var(--shadow-lg); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-xs); min-height: 44px; min-width: 44px; padding: var(--space-sm) var(--space-lg); font-size: 0.9rem; font-weight: 600; border: 2px solid transparent; border-radius: var(--radius); cursor: pointer; transition: all var(--duration) var(--ease); text-decoration: none; }
.btn--primary { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }
.btn--primary:hover { background: var(--color-accent-dark); border-color: var(--color-accent-dark); }
.btn--outline { background: transparent; color: var(--color-accent); border-color: var(--color-accent); }
.btn--outline:hover { background: var(--color-accent-light); }
.btn--small { min-height: 36px; padding: var(--space-xs) var(--space-md); font-size: 0.8rem; }
.btn--success { background: var(--color-success); color: #fff; border-color: var(--color-success); }
.btn--danger { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-group { display: flex; flex-wrap: wrap; gap: var(--space-sm); }
.callout { padding: var(--space-lg); border-radius: var(--radius); border-left: 4px solid var(--color-accent); background: var(--color-accent-light); margin: var(--space-lg) 0; font-size: 0.95rem; }
.callout--warning { border-color: var(--color-warning); background: var(--color-warning-light); }
.callout--success { border-color: var(--color-success); background: var(--color-success-light); }
.callout--danger { border-color: var(--color-danger); background: var(--color-danger-light); }
.callout strong { display: block; margin-bottom: var(--space-xs); }

.stat-box { display: inline-flex; flex-direction: column; align-items: center; padding: var(--space-md) var(--space-lg); border-radius: var(--radius); background: var(--color-bg); border: 1px solid var(--color-border); min-width: 110px; text-align: center; }
.stat-box .stat-value { font-size: 1.3rem; font-weight: 700; color: var(--color-accent); }
.stat-box .stat-label { font-size: 0.72rem; color: var(--color-text-muted); margin-top: var(--space-xs); }
.stats-row { display: flex; flex-wrap: wrap; gap: var(--space-sm); margin: var(--space-md) 0; }

/* ========== TOKEN CHIPS ========== */
.token-chip { display: inline-block; padding: 2px 4px; margin: 1px; border-radius: 3px; font-family: var(--font-mono); font-size: 0.9rem; line-height: 1.5; border: 1px solid rgba(0,0,0,0.1); cursor: default; transition: transform 0.15s var(--ease); }
.token-chip:hover { transform: scale(1.08); z-index: 1; position: relative; }

/* ========== CHAT BUBBLES ========== */
.chat-bubble { max-width: 85%; padding: var(--space-sm) var(--space-md); border-radius: var(--radius-lg); font-size: 0.88rem; line-height: 1.5; margin-bottom: var(--space-sm); white-space: pre-line; }
.chat-bubble--user { background: var(--color-accent); color: #fff; align-self: flex-end; margin-left: auto; border-bottom-right-radius: 4px; }
.chat-bubble--ai { background: var(--color-surface); border: 1px solid var(--color-border); align-self: flex-start; border-bottom-left-radius: 4px; }
.sim-chat { display: flex; flex-direction: column; padding: var(--space-md); background: var(--color-bg); border-radius: var(--radius); min-height: 200px; overflow-y: auto; max-height: 65vh; }

/* ========== SCROLL SIMULATION ========== */
.scroll-sim { position: relative; }
.scroll-sim__track { position: relative; }
.scroll-sim__sticky { position: sticky; top: calc(var(--nav-h) + 16px); }
.scroll-hint { text-align: center; padding: var(--space-md); color: var(--color-text-muted); font-size: 0.85rem; display: flex; flex-direction: column; align-items: center; gap: var(--space-xs); animation: hintBounce 2s ease-in-out infinite; transition: opacity 0.4s var(--ease); }
.scroll-hint.faded { opacity: 0; pointer-events: none; }
.scroll-hint svg { width: 24px; height: 24px; }

@keyframes hintBounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(6px); } }

.scroll-sim__progress-bar { height: 3px; background: var(--color-border); border-radius: 2px; margin-top: var(--space-sm); overflow: hidden; }
.scroll-sim__progress-fill { height: 100%; width: 0%; background: var(--color-accent); border-radius: 2px; transition: width 0.1s linear; }

/* Bubbles collapse when not revealed, expand when revealed (bidirectional) */
.scroll-sim .chat-bubble { opacity: 0; max-height: 0; overflow: hidden; padding-top: 0; padding-bottom: 0; margin-bottom: 0; transition: opacity 0.35s var(--ease), max-height 0.45s var(--ease), padding-top 0.35s var(--ease), padding-bottom 0.35s var(--ease), margin-bottom 0.35s var(--ease); }
.scroll-sim .chat-bubble.revealed { opacity: 1; max-height: 500px; padding-top: var(--space-sm); padding-bottom: var(--space-sm); margin-bottom: var(--space-sm); overflow: visible; }

/* Sim callout at end */
.sim-callout { transition: opacity 0.6s var(--ease); }

/* ========== SIM DASHBOARD ========== */
.sim-dashboard { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-md); box-shadow: var(--shadow); }
.sim-dashboard h4 { font-size: 0.9rem; margin-bottom: var(--space-sm); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.sim-stats { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-sm); margin-bottom: var(--space-md); }
.sim-stat { text-align: center; padding: var(--space-sm); background: var(--color-bg); border-radius: var(--radius); }
.sim-stat__value { display: block; font-size: 1.1rem; font-weight: 700; color: var(--color-accent); }
.sim-stat__label { display: block; font-size: 0.7rem; color: var(--color-text-muted); margin-top: 2px; }
.sim-stat--accent { background: var(--color-accent-light); }
.sim-stat--accent .sim-stat__value { color: var(--color-accent-dark); }

.sim-table-wrap { overflow-x: auto; margin-bottom: var(--space-md); }
.sim-table { width: 100%; border-collapse: collapse; font-size: 0.75rem; }
.sim-table th { text-align: right; padding: 4px 6px; border-bottom: 2px solid var(--color-border); color: var(--color-text-muted); font-weight: 600; }
.sim-table td { text-align: right; padding: 4px 6px; border-bottom: 1px solid var(--color-border); }
.sim-table th:first-child, .sim-table td:first-child { text-align: center; }
.sim-table tr.new-row td { animation: fadeSlideIn 0.3s var(--ease); }
.sim-table tr.highlight td { background: var(--color-accent-light); }

/* ========== STACKED BAR CHART ========== */
.chart-container { width: 100%; }
.chart-container svg { width: 100%; height: auto; }

/* ========== MODEL TOGGLE ========== */
.model-toggle { display: flex; border: 2px solid var(--color-border); border-radius: var(--radius); overflow: hidden; }
.model-toggle button { flex: 1; padding: var(--space-sm) var(--space-md); border: none; background: var(--color-surface); cursor: pointer; font-weight: 600; font-size: 0.85rem; transition: all var(--duration) var(--ease); min-height: 44px; }
.model-toggle button.active { background: var(--color-accent); color: #fff; }
.model-toggle button:not(.active):hover { background: var(--color-accent-light); }

/* ========== TEXTAREA ========== */
textarea { width: 100%; min-height: 120px; padding: var(--space-md); border: 2px solid var(--color-border); border-radius: var(--radius); resize: vertical; font-size: 0.95rem; line-height: 1.6; transition: border-color var(--duration) var(--ease); }
textarea:focus { outline: none; border-color: var(--color-accent); }

/* ========== SLIDER ========== */
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; background: var(--color-border); border-radius: 3px; outline: none; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%; background: var(--color-accent); cursor: pointer; border: 2px solid #fff; box-shadow: var(--shadow); }
input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: var(--color-accent); cursor: pointer; border: 2px solid #fff; box-shadow: var(--shadow); }

/* ========== COMPARISON BAR ========== */
.comparison-bar { display: flex; align-items: center; gap: var(--space-md); padding: var(--space-md); background: var(--color-success-light); border-radius: var(--radius); border: 1px solid var(--color-success); margin-top: var(--space-md); }
.comparison-bar .savings { font-size: 1.1rem; font-weight: 700; color: var(--color-success); }

/* ========== ACCORDION ========== */
.accordion-item { border: 1px solid var(--color-border); border-radius: var(--radius); margin-bottom: var(--space-sm); overflow: hidden; }
.accordion-header { width: 100%; padding: var(--space-md); background: var(--color-surface); border: none; text-align: left; cursor: pointer; font-weight: 600; font-size: 0.95rem; display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.accordion-header::after { content: '+'; font-size: 1.2rem; color: var(--color-text-muted); transition: transform var(--duration) var(--ease); }
.accordion-item.open .accordion-header::after { content: '\2212'; }
.accordion-body { max-height: 0; overflow: hidden; transition: max-height 0.4s var(--ease); }
.accordion-item.open .accordion-body { max-height: 600px; }
.accordion-body-inner { padding: var(--space-md); border-top: 1px solid var(--color-border); font-size: 0.9rem; }

/* ========== TRIM EXERCISE ========== */
.trim-word { display: inline; cursor: pointer; padding: 1px 2px; border-radius: 2px; transition: all 0.2s var(--ease); }
.trim-word:hover { background: var(--color-danger-light); }
.trim-word.trimmed { background: var(--color-danger-light); text-decoration: line-through; opacity: 0.5; }

/* ========== SIDE LABELS ========== */
.side-label { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: var(--space-sm); }
.side-label--expensive { color: var(--color-danger); }
.side-label--savings { color: var(--color-success); }

/* ========== ANALOGY VISUAL ========== */
.analogy-row { display: flex; align-items: center; justify-content: center; gap: var(--space-xl); padding: var(--space-xl) 0; flex-wrap: wrap; }
.analogy-item { display: flex; flex-direction: column; align-items: center; gap: var(--space-sm); text-align: center; }
.analogy-icon { width: 64px; height: 64px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.8rem; background: var(--color-accent-light); color: var(--color-accent); }
.analogy-equals { font-size: 2rem; font-weight: 700; color: var(--color-text-muted); }

/* ========== TIP VISUAL BOXES ========== */
.tip-compare { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-lg); margin: var(--space-lg) 0; }
.tip-compare__side { text-align: center; padding: var(--space-lg); border-radius: var(--radius); }
.tip-compare__side--bad { background: var(--color-danger-light); }
.tip-compare__side--good { background: var(--color-success-light); }

/* ========== SCROLL-DRIVEN PROMPT VERSIONS (Tip 2) ========== */
.prompt-version { opacity: 0; max-height: 0; overflow: hidden; padding: 0; margin-bottom: 0; border: 1px solid transparent; border-radius: var(--radius-lg); background: var(--color-surface); transition: all 0.45s var(--ease); }
.prompt-version.revealed { opacity: 1; max-height: 500px; overflow: visible; padding: var(--space-lg); margin-bottom: var(--space-md); border-color: var(--color-border); }
.prompt-version__bar { height: 24px; border-radius: 4px; transition: width 0.6s var(--ease); margin-top: var(--space-sm); }

/* ========== OUTPUT COST EXPLAINER ========== */
.cost-bars { display: flex; flex-direction: column; gap: var(--space-sm); padding: var(--space-lg); }
.cost-bar-row { display: flex; align-items: center; gap: var(--space-md); }
.cost-bar-label { min-width: 140px; font-size: 0.85rem; font-weight: 600; }
.cost-bar { height: 28px; border-radius: 4px; display: flex; align-items: center; padding: 0 var(--space-sm); font-size: 0.8rem; font-weight: 600; color: #fff; }

/* ========== MODEL TIERS (Tip 6) ========== */
.model-tier { opacity: 0; max-height: 0; overflow: hidden; padding: 0; margin-bottom: 0; border: 2px solid transparent; border-radius: var(--radius-lg); background: var(--color-surface); transition: all 0.45s var(--ease); }
.model-tier.revealed { opacity: 1; max-height: 200px; overflow: visible; display: flex; gap: var(--space-lg); align-items: center; padding: var(--space-lg); margin-bottom: var(--space-md); border-color: var(--color-border); }
.model-tier__icon { width: 56px; height: 56px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.model-tier__body { flex: 1; }
.model-tier__name { font-size: 1.1rem; font-weight: 700; }
.model-tier__desc { font-size: 0.85rem; color: var(--color-text-muted); margin: 4px 0; }
.model-tier__price { font-size: 0.8rem; font-weight: 600; }

/* ========== TASK SORTER (Tip 6) ========== */
.task-sorter { margin-top: var(--space-xl); }
.task-cards { display: flex; flex-wrap: wrap; gap: var(--space-sm); margin-bottom: var(--space-lg); }
.task-card { padding: var(--space-sm) var(--space-md); background: var(--color-surface); border: 2px solid var(--color-border); border-radius: var(--radius); font-size: 0.85rem; cursor: pointer; transition: all 0.2s var(--ease); min-height: 44px; display: flex; align-items: center; }
.task-card:hover { border-color: var(--color-accent); background: var(--color-accent-light); }
.task-card.placed { opacity: 0.5; border-style: dashed; cursor: default; }
.task-buckets { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--space-md); margin-bottom: var(--space-md); }
.task-bucket { min-height: 120px; border: 2px dashed var(--color-border); border-radius: var(--radius-lg); padding: var(--space-md); text-align: center; transition: all 0.2s var(--ease); }
.task-bucket.active { border-color: var(--color-accent); background: var(--color-accent-light); }
.task-bucket__title { font-weight: 700; font-size: 0.9rem; margin-bottom: var(--space-sm); }
.task-bucket__items { display: flex; flex-direction: column; gap: var(--space-xs); }
.task-bucket__item { padding: var(--space-xs) var(--space-sm); background: var(--color-surface); border-radius: var(--radius); font-size: 0.8rem; border: 1px solid var(--color-border); }
.task-bucket__item--correct { background: var(--color-success-light); border-color: var(--color-success); }
.task-bucket__item--wrong { background: var(--color-danger-light); border-color: var(--color-danger); }

/* ========== FILE UPLOAD SCENARIOS (Tip 7) ========== */
.file-scenario { opacity: 0; max-height: 0; overflow: hidden; padding: 0; margin-bottom: 0; border: 1px solid transparent; border-radius: var(--radius-lg); background: var(--color-surface); transition: all 0.45s var(--ease); }
.file-scenario.revealed { opacity: 1; max-height: 300px; overflow: visible; display: grid; grid-template-columns: 1fr auto 1fr; gap: var(--space-md); align-items: center; padding: var(--space-lg); margin-bottom: var(--space-md); border-color: var(--color-border); }
.file-scenario__side { text-align: center; padding: var(--space-md); border-radius: var(--radius); }
.file-scenario__side--bad { background: var(--color-danger-light); }
.file-scenario__side--good { background: var(--color-success-light); }
.file-scenario__arrow { font-size: 1.5rem; color: var(--color-success); font-weight: 700; }
.file-scenario__cost { font-size: 1.3rem; font-weight: 700; margin-top: var(--space-xs); }
.file-scenario__multiplier { font-size: 0.85rem; font-weight: 700; color: var(--color-danger); }

/* ========== CHEAT SHEET ========== */
.cheat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-md); }
.cheat-item { display: flex; gap: var(--space-md); align-items: flex-start; padding: var(--space-md); border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-surface); }
.cheat-icon { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* ========== DECISION TREE ========== */
.decision-tree { display: flex; flex-direction: column; align-items: center; gap: var(--space-md); padding: var(--space-lg); }
.decision-node { display: inline-flex; flex-direction: column; align-items: center; text-align: center; padding: var(--space-md); border-radius: var(--radius); font-size: 0.85rem; min-width: 140px; }
.decision-node--question { background: var(--color-accent-light); border: 2px solid var(--color-accent); font-weight: 600; }
.decision-node--yes { background: var(--color-success-light); border: 2px solid var(--color-success); }
.decision-node--no { background: var(--color-warning-light); border: 2px solid var(--color-warning); }
.decision-branch { display: flex; gap: var(--space-xl); justify-content: center; }
.decision-arrow { font-size: 1.5rem; color: var(--color-text-muted); }

/* ========== GREEN BADGE ========== */
.badge-savings { display: inline-block; padding: var(--space-sm) var(--space-md); background: var(--color-success); color: #fff; border-radius: var(--radius); font-size: 1.1rem; font-weight: 700; }

/* ========== FOOTER ========== */
footer { padding: var(--space-xl) 0; background: var(--color-text); color: #fff; font-size: 0.85rem; text-align: center; }
footer a { color: var(--color-accent-light); text-decoration: underline; }

/* ========== ANIMATIONS ========== */
@keyframes fadeSlideIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.animate-on-scroll { opacity: 0; transform: translateY(20px); transition: opacity 0.6s var(--ease), transform 0.6s var(--ease); }
.animate-on-scroll.visible { opacity: 1; transform: translateY(0); }

/* Token split animation */
.token-split-container .token-chip { opacity: 0; transform: translateY(8px); }
.token-split-container.animated .token-chip { opacity: 1; transform: translateY(0); transition: opacity 0.3s var(--ease), transform 0.3s var(--ease); }

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }
  .grid-2, .grid-3, .grid-6040, .cheat-grid, .tip-compare, .task-buckets { grid-template-columns: 1fr; }
  .container { padding: 0 var(--space-md); }
  section { padding: var(--space-2xl) 0; }
  .card { padding: var(--space-lg); }
  nav .container { gap: var(--space-sm); }
  .analogy-row { gap: var(--space-md); }
  .chat-bubble { max-width: 92%; }
  .decision-branch { flex-direction: column; align-items: center; }
  .stats-row { justify-content: center; }
  .sim-stats { grid-template-columns: 1fr 1fr; }
  .file-scenario { grid-template-columns: 1fr; }
  .file-scenario__arrow { transform: rotate(90deg); justify-self: center; }
  .model-tier { flex-direction: column; text-align: center; }
  .scroll-sim__sticky { top: calc(var(--nav-h) + 8px); }
  .sim-chat { max-height: 50vh; }
}

/* ========== PRINT ========== */
@media print {
  body { background: #fff; font-size: 11pt; }
  nav, footer, .btn, button, textarea, input, .card--interactive, .no-print, .scroll-hint, .scroll-sim__progress-bar { display: none !important; }
  section { padding: 1rem 0; page-break-inside: avoid; }
  .card { box-shadow: none; border: 1px solid #ccc; }
  #cheat-sheet { display: block !important; }
  .cheat-grid { grid-template-columns: 1fr 1fr; }
  .scroll-sim .chat-bubble { opacity: 1; transform: none; }
  .prompt-version, .model-tier, .file-scenario { opacity: 1; transform: none; }
  .animate-on-scroll { opacity: 1; transform: none; }
}
