/* KALC v0.1 — styles. Same token family as R3B3L / konbit.ca.
   Dark first, light via [data-theme="light"] (warm off-white #f7f2e7).
   The 16-bit stage is a colourful pixel field. Groups differ by
   outline pattern AND label AND count — never colour alone. */
:root {
  --ink: #000;
  --panel: #0a0d12;
  --soft: #10151d;
  --line: #1d2733;
  --blue: #2b86cf;
  --blue2: #80bdff;
  --accent: #2563eb;
  --white: #eef5ff;
  --muted: #9aa9bb;
  --max: 1180px;
  --stage-bg: #131a2e;
  --stage-grid: #1d2947;
  --unit-a: #ffd23f;
  --unit-b: #7dd3fc;
  --unit-c: #fda4af;
  --unit-d: #86efac;
}
[data-theme="light"] {
  --ink: #f7f2e7;
  --panel: #fffdf6;
  --soft: #f1ead9;
  --line: #d8cdb2;
  --blue: #1f6fb2;
  --blue2: #1f6fb2;
  --white: #1c2433;
  --muted: #5c6675;
  --stage-bg: #e8ecf7;
  --stage-grid: #cdd6ec;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--ink); color: var(--white);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
}
.shell { max-width: var(--max); margin: 0 auto; padding: 0 20px; }
a { color: var(--blue2); }
button { font: inherit; cursor: pointer; }

/* ---- hero (standalone only) ---- */
.kalc-hero {
  display: flex; gap: 24px; align-items: flex-end; justify-content: space-between;
  padding: 48px 0 8px; min-height: 0;
}
.hero-kicker { font-family: ui-monospace, monospace; text-transform: uppercase; letter-spacing: .12em; color: var(--blue2); font-size: 13px; }
.kalc-hero h1 { font-size: clamp(56px, 12vw, 120px); line-height: .9; letter-spacing: -.06em; margin: 8px 0; }
.hero-sub { font-size: 20px; margin: 0 0 4px; }
.hero-tag { color: var(--muted); margin: 0 0 12px; }
.hero-guarantee { font-size: 14px; color: var(--muted); margin: 0; }
.hero-art { width: 180px; height: auto; border-radius: 12px; image-rendering: pixelated; }
@media (max-width: 700px) { .hero-art { display: none; } .kalc-hero { padding-top: 28px; } }

/* ---- top bar ---- */
.kalc-topbar { display: flex; gap: 12px; align-items: center; justify-content: flex-end; padding: 12px 0; flex-wrap: wrap; }
.mode-kicker { color: var(--muted); font-size: 14px; margin-right: auto; }
.btn { background: var(--soft); color: var(--white); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; }
.btn:hover { border-color: var(--blue); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.lang-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.lang-btn { background: transparent; color: var(--white); border: 0; padding: 9px 14px; }
.lang-btn.active { background: var(--blue); color: #fff; }
.theme-toggle { background: var(--soft); color: var(--white); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }

/* ---- mode tabs ---- */
.mode-tabs { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 0; }
.mode-tab {
  background: var(--soft); color: var(--white); border: 1px solid var(--line);
  border-radius: 999px; padding: 10px 16px; font-weight: 600;
}
.mode-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.mode-tab .band {
  font-size: 11px; font-weight: 400; text-transform: uppercase; letter-spacing: .08em;
  opacity: .75; margin-left: 6px;
}

/* ---- examples ---- */
.kalc-examples { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 4px 0 12px; }
.examples-label { color: var(--muted); font-size: 14px; margin-right: 4px; }
.example-btn, .factor-btn {
  background: var(--panel); color: var(--white); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px; font-variant-numeric: tabular-nums;
}
.example-btn.active, .factor-btn.active { background: var(--blue); border-color: var(--blue); color: #fff; }

/* ---- the 16-bit stage ---- */
.stage-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; }
.kalc-stage {
  min-height: 220px; background: var(--stage-bg);
  background-image:
    linear-gradient(var(--stage-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--stage-grid) 1px, transparent 1px);
  background-size: 28px 28px;
  border-radius: 12px; padding: 20px;
  display: flex; gap: 24px; align-items: center; justify-content: center; flex-wrap: wrap;
}
.tray { background: rgba(255,255,255,.04); border-radius: 12px; padding: 12px 14px; text-align: center; animation: pop .35s ease; }
.tray.pattern-solid { border: 3px solid var(--unit-a); }
.tray.pattern-dashed { border: 3px dashed var(--unit-b); }
.tray.pattern-dotted { border: 3px dotted var(--unit-c); }
.tray.merged { border-color: var(--unit-d); }
.tray-label { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.tray-label, .units, .tenframe, .bar-label, .kalc-numeral { font-variant-numeric: tabular-nums; }
.units { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; max-width: 260px; }
.unit {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; font-size: 20px; line-height: 1;
  background: var(--unit-a); color: #201a00; border-radius: 4px;
  image-rendering: pixelated;
}
.tray.pattern-dashed .unit { background: var(--unit-b); color: #08222f; }
.tray.pattern-dotted .unit { background: var(--unit-c); color: #2f0a12; }
.tray.merged .unit { background: var(--unit-d); color: #0a2a12; }
.tray.gone { animation: slideAway .7s ease forwards; opacity: .35; }
.tray.sliding { animation: slideIn .6s ease; }
@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes slideIn { from { transform: translateX(-24px); opacity: .4; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideAway { to { transform: translateX(90px); opacity: .15; } }
.stage-arrow { display: flex; flex-direction: column; align-items: center; color: var(--blue2); }
.arrow-glyph { font-size: 34px; line-height: 1; }
.arrow-label { font-size: 13px; }
.stage-note { width: 100%; text-align: center; font-size: 18px; font-weight: 700; }
.tenframe { display: grid; grid-template-columns: repeat(5, 34px); gap: 4px; justify-content: center; }
.tf-cell {
  width: 34px; height: 34px; border: 2px solid var(--line); border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center; font-size: 20px;
}
.tf-cell.filled { background: var(--unit-d); color: #0a2a12; border-color: var(--unit-d); }
.bar-wrap { width: 100%; max-width: 520px; text-align: center; }
.bar { display: flex; border: 3px solid var(--unit-a); border-radius: 8px; overflow: hidden; }
.bar-seg { flex: 1; height: 56px; display: flex; align-items: center; justify-content: center; font-size: 24px; border-right: 1px solid var(--line); }
.bar-seg:last-child { border-right: 0; }
.bar-seg.filled { background: var(--unit-b); color: #08222f; }
.bar-label { margin-top: 10px; font-size: 20px; font-weight: 700; }
.proportions { width: 100%; max-width: 520px; display: flex; flex-direction: column; gap: 8px; }
.prop-row { display: flex; gap: 12px; align-items: center; background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; }
.prop-row.even { border-color: var(--unit-d); }
.prop-side { font-size: 18px; font-weight: 700; min-width: 28px; text-align: center; }
.prop-split { color: var(--muted); }
.prop-even { margin-left: auto; font-size: 13px; color: var(--unit-d); text-transform: uppercase; letter-spacing: .08em; }
.kalc-numeral { text-align: center; font-size: clamp(28px, 6vw, 44px); font-weight: 800; letter-spacing: -.02em; margin: 16px 0 4px; }
.kalc-caption { text-align: center; color: var(--muted); margin: 0 0 14px; min-height: 24px; }
.step-controls { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ---- skins ---- */
.skins { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 14px 0; }
.skins-label { color: var(--muted); font-size: 14px; }
.skin-btn { background: var(--panel); color: var(--white); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.skin-btn.active { background: var(--blue); border-color: var(--blue); color: #fff; }

/* ---- calculator (kiddy keyboard, always visible) ---- */
.calculator { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; margin-top: 8px; }
.calculator h2 { margin: 0 0 4px; font-size: 22px; }
.calc-hint { color: var(--muted); margin: 0 0 12px; font-size: 14px; }
.calc-expr { min-height: 22px; color: var(--muted); text-align: right; font-size: 16px; }
.calc-display {
  background: var(--ink); border: 1px solid var(--line); border-radius: 10px;
  font-size: clamp(28px, 7vw, 40px); font-weight: 700; text-align: right;
  padding: 10px 16px; margin-bottom: 12px; overflow-x: auto; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.calc-note { min-height: 22px; color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.kiddy-keys { display: flex; flex-direction: column; gap: 8px; max-width: 460px; margin: 0 auto; }
.calc-row { display: flex; gap: 8px; }
.calc-key {
  flex: 1; min-height: 56px; font-size: 24px; font-weight: 700;
  background: var(--soft); color: var(--white); border: 1px solid var(--line); border-radius: 12px;
}
.calc-key.op { background: var(--blue); border-color: var(--blue); color: #fff; }
.calc-key.equals { background: var(--accent); border-color: var(--accent); color: #fff; }
.calc-key.clear {
  width: 100%; min-height: 48px; font-size: 16px; margin-top: 8px;
  background: transparent; color: var(--muted); border: 1px solid var(--line); border-radius: 12px;
}

/* ---- record + footer ---- */
.record { padding: 20px 0; text-align: center; }
.save-hint { color: var(--muted); font-size: 14px; max-width: 560px; margin: 10px auto 0; }
.saved-note { color: var(--unit-d); min-height: 22px; }
.kalc-footer { border-top: 1px solid var(--line); padding: 18px 0 32px; color: var(--muted); font-size: 13px; }
.data-note { background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; font-size: 14px; margin: 12px 0; }
@media (prefers-reduced-motion: reduce) {
  .tray, .tray.gone, .tray.sliding { animation: none; }
}
.kalc-stage.no-motion .tray { animation: none; }
