/* ==========================================================================
   12C calculator (unofficial study emulator) + HP 12C Lab page
   The calculator itself uses fixed "hardware" colors so it looks like the
   device in both themes; the surrounding page uses the app design tokens.
   All calculator dimensions are in em; ui.js sets font-size from the width.
   ========================================================================== */

.hp12c-wrap { width: 100%; max-width: 720px; margin: 0 auto; }

.hp12c {
  --body: #242120;
  --face: #1a1817;
  --trim: #b08a3e;
  --gold: #e0ad4a;
  --blue: #6cb4ee;
  --keytop: #3a3736;
  --keybot: #2a2726;
  --keyfront: #1f1d1c;
  --lcd: #c9ceb4;
  --lcd-ink: #1d2118;
  position: relative;
  width: 40em;
  margin: 0 auto;
  padding: 0.9em 1em 1.1em;
  box-sizing: border-box;
  background: linear-gradient(180deg, #2f2c2a 0%, var(--body) 30%, #1c1a19 100%);
  border-radius: 1.1em;
  box-shadow: 0 0.15em 0 #3d3935 inset, 0 -0.15em 0 #0e0d0c inset, 0 0.6em 1.6em rgba(0, 0, 0, 0.35);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  font-family: var(--font, Inter, system-ui, sans-serif);
  line-height: 1.15;
  outline: none;
}
.hp12c:focus-visible { box-shadow: 0 0 0 0.2em var(--accent, #3b82f6), 0 0.6em 1.6em rgba(0, 0, 0, 0.35); }

/* ---- top: display + brand ---- */
.hp12c-top {
  display: flex; align-items: stretch; gap: 1em;
  padding: 0.7em 0.8em;
  background: linear-gradient(180deg, #56524d, #3a3733 55%, #2e2b28);
  border-radius: 0.6em;
  border-bottom: 0.12em solid var(--trim);
}
.hp12c-lcd {
  flex: 0 0 24em;
  background: linear-gradient(180deg, #d3d8bf, var(--lcd));
  border-radius: 0.35em;
  box-shadow: 0 0.12em 0.3em rgba(0, 0, 0, 0.55) inset;
  padding: 0.35em 0.7em 0.25em;
  color: var(--lcd-ink);
  display: flex; flex-direction: column; justify-content: center;
  min-height: 4.2em;
  box-sizing: border-box;
}
.hp12c-digits {
  font-family: var(--mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: 2.35em;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-align: right;
  white-space: pre;
  overflow: hidden;
  min-height: 1.2em;
  line-height: 1.2;
}
.hp12c-digits.is-running { font-style: italic; opacity: 0.8; }
.hp12c-ann { display: flex; gap: 0.9em; justify-content: flex-end; font-size: 0.62em; font-weight: 700; letter-spacing: 0.04em; min-height: 1.1em; }
.hp12c-ann span { opacity: 0; transition: opacity 0.1s; }
.hp12c-ann span.on { opacity: 0.9; }
.hp12c-brand {
  flex: 1; display: flex; flex-direction: column; align-items: flex-end; justify-content: space-between;
  color: #e9e3d6;
}
.hp12c-brand strong { font-size: 1.9em; font-weight: 800; letter-spacing: 0.02em; color: var(--gold); line-height: 1; }
.hp12c-brand span { font-size: 0.6em; opacity: 0.7; text-transform: uppercase; letter-spacing: 0.12em; }

/* ---- keyboard ---- */
.hp12c-face { margin-top: 0.9em; padding: 0.4em 0.3em 0; background: var(--face); border-radius: 0.5em; }
.hp12c-keys {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(4, auto);
  column-gap: 0.85em;
  row-gap: 1em;
  padding: 0.3em 0.45em 0.6em;
}
.k {
  appearance: none; border: 0; margin: 0; padding: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: stretch;
  font: inherit; color: #fff; min-width: 0;
  touch-action: manipulation;
}
.k:focus { outline: none; }
.k:focus-visible .k-cap { outline: 0.15em solid var(--blue); outline-offset: 0.1em; }
.k-f {
  height: 1.25em; display: flex; align-items: flex-end; justify-content: center;
  font-size: 0.6em; font-weight: 700; color: var(--gold); letter-spacing: 0.02em; white-space: nowrap;
}
.k-cap {
  position: relative;
  display: flex; flex-direction: column; flex: 1;
  border-radius: 0.3em;
  background: linear-gradient(180deg, var(--keytop), var(--keybot));
  box-shadow: 0 0.18em 0 #0b0a0a, 0 0.08em 0 #4a4644 inset;
  transition: transform 0.06s, box-shadow 0.06s;
  overflow: hidden;
}
.k-main {
  height: 1.55em; display: flex; align-items: center; justify-content: center;
  font-size: 1em; font-weight: 600; white-space: nowrap;
}
.k-main sup, .k-g sup { font-size: 0.68em; position: relative; top: -0.45em; vertical-align: baseline; line-height: 0; }
.k-g {
  height: 1.05em; display: flex; align-items: center; justify-content: center;
  background: var(--keyfront); color: var(--blue);
  font-size: 0.62em; font-weight: 700; white-space: nowrap;
  border-top: 0.08em solid #121110;
}
.k-fkey .k-cap { background: linear-gradient(180deg, #f0c060, #c48f2a); }
.k-fkey .k-main { color: #1d1a16; font-size: 1.15em; font-weight: 800; }
.k-gkey .k-cap { background: linear-gradient(180deg, #86c3f2, #3f8fcf); }
.k-gkey .k-main { color: #0f1a24; font-size: 1.15em; font-weight: 800; }
.k-fkey .k-g, .k-gkey .k-g { background: transparent; border-top-color: transparent; }
.k-enter .k-main { flex: 1; height: auto; }
.k-vert { font-size: 0.78em; line-height: 1.05; text-align: center; letter-spacing: 0; }
.k.is-down .k-cap { transform: translateY(0.14em); box-shadow: 0 0.04em 0 #0b0a0a, 0 0.08em 0 #4a4644 inset; filter: brightness(1.15); }
.k.is-hl .k-cap { box-shadow: 0 0 0 0.16em var(--gold), 0 0 0.9em 0.2em rgba(224, 173, 74, 0.65); animation: hp12c-pulse 1.1s ease-in-out infinite; }
.k-gkey.is-hl .k-cap { box-shadow: 0 0 0 0.16em #fff, 0 0 0.9em 0.2em rgba(108, 180, 238, 0.7); }
@keyframes hp12c-pulse { 50% { filter: brightness(1.3); } }
@media (prefers-reduced-motion: reduce) { .k.is-hl .k-cap { animation: none; } .k-cap { transition: none; } }

.k-bracket {
  position: relative; z-index: 1;
  align-self: start; pointer-events: none;
  margin-top: -0.62em; margin-left: 0.3em; margin-right: 0.3em;
  height: 0.55em;
  border: 0.08em solid var(--gold); border-bottom: 0;
  display: flex; justify-content: center;
}
.k-bracket span {
  margin-top: -0.55em; padding: 0 0.4em; background: var(--face);
  color: var(--gold); font-size: 0.55em; font-weight: 800; letter-spacing: 0.08em; line-height: 1;
}

/* ---- register panel ---- */
.hp12c-panel-toggle {
  display: block; margin: 0.6rem auto 0; padding: 0.35rem 0.8rem;
  font: 500 0.85rem var(--font, system-ui); color: var(--accent, #2563eb);
  background: transparent; border: 1px solid var(--border, #d4d4d8); border-radius: 999px; cursor: pointer;
}
.hp12c-panel {
  margin-top: 0.6rem; padding: 0.6rem 0.8rem;
  background: var(--surface, #fff); color: var(--text, #111);
  border: 1px solid var(--border, #e4e4e7); border-radius: var(--radius, 12px);
  font-size: 0.85rem;
}
.hp12c-panel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.4rem 1rem; }
.hp12c-panel h5 { margin: 0.2rem 0 0.25rem; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted, #71717a); }
.hp12c-panel table { width: 100%; border-collapse: collapse; }
.hp12c-panel th { text-align: left; font-weight: 600; color: var(--muted, #71717a); padding: 0.1rem 0.4rem 0.1rem 0; width: 3.2rem; }
.hp12c-panel td { text-align: right; font-family: var(--mono, ui-monospace, monospace); padding: 0.1rem 0; font-variant-numeric: tabular-nums; }
.hp12c-mode { font-size: 0.65rem; padding: 0 0.35rem; border-radius: 999px; border: 1px solid var(--border, #ddd); margin-left: 0.3rem; }

/* ==========================================================================
   Lab page
   ========================================================================== */
.lab { max-width: 1100px; margin: 0 auto; padding: 0 16px 48px; box-sizing: border-box; color: var(--text, #111); }
.lab * { box-sizing: border-box; }
.lab h1 { font-size: 1.6rem; margin: 1rem 0 0.25rem; }
.lab h2 { font-size: 1.15rem; margin: 1.5rem 0 0.5rem; }
.lab h3 { font-size: 1rem; margin: 0 0 0.4rem; }
.lab-sub { color: var(--muted, #666); margin: 0 0 1rem; }
.lab-disclaimer { font-size: 0.8rem; color: var(--muted, #666); }
.lab-back { display: inline-block; margin-top: 1rem; color: var(--accent, #2563eb); text-decoration: none; font-size: 0.9rem; }
.lab-tools { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 0.75rem 0 0.25rem; }
.lab-search {
  flex: 1 1 220px; min-width: 0; padding: 0.55rem 0.8rem; font: inherit;
  border: 1px solid var(--border, #ddd); border-radius: 999px; background: var(--surface, #fff); color: var(--text, #111);
}
.lab-chips { display: flex; gap: 0.4rem; overflow-x: auto; padding: 0.25rem 0 0.5rem; scrollbar-width: none; }
.lab-chip {
  flex: 0 0 auto; padding: 0.3rem 0.75rem; border-radius: 999px; cursor: pointer; font: 500 0.82rem var(--font, system-ui);
  border: 1px solid var(--border, #ddd); background: var(--surface, #fff); color: var(--text, #111);
}
.lab-chip[aria-pressed="true"] { background: var(--accent, #2563eb); color: var(--accent-ink, #fff); border-color: transparent; }
.lab-progress { font-size: 0.85rem; color: var(--muted, #666); }
.lab-bar { height: 6px; background: var(--surface-2, #eee); border-radius: 999px; overflow: hidden; margin: 0.35rem 0 0.5rem; }
.lab-bar > span { display: block; height: 100%; background: var(--good, #16a34a); }
.lab-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0.75rem; }
.lab-card {
  display: block; text-decoration: none; color: inherit; padding: 0.85rem 0.95rem;
  background: var(--surface, #fff); border: 1px solid var(--border, #e5e5e5); border-radius: var(--radius, 12px);
  transition: border-color 0.15s, transform 0.15s;
}
.lab-card:hover { border-color: var(--accent, #2563eb); }
.lab-card h3 { display: flex; gap: 0.4rem; align-items: flex-start; justify-content: space-between; }
.lab-card p { margin: 0; font-size: 0.85rem; color: var(--muted, #666); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lab-card.is-free { border-style: dashed; }
.lab-badges { display: inline-flex; gap: 0.35rem; align-items: center; flex: 0 0 auto; }
.lab-pill.lab-new { flex: 0 0 auto; background: var(--accent, #0f6b62); color: var(--accent-ink, #fff); font-weight: 600; }
.lab-check { flex: 0 0 auto; width: 1.3rem; height: 1.3rem; border-radius: 50%; display: inline-grid; place-items: center; font-size: 0.8rem; background: var(--good, #16a34a); color: #fff; }
.lab-empty { color: var(--muted, #666); padding: 1rem 0; }

.lab-pill { display: inline-block; font-size: 0.75rem; padding: 0.15rem 0.6rem; border-radius: 999px; background: var(--surface-2, #f1f1f1); color: var(--muted, #555); }
.lab-concept { background: var(--surface, #fff); border: 1px solid var(--border, #e5e5e5); border-radius: var(--radius, 12px); padding: 0.4rem 1rem; }
.lab-concept code, .lab code { font-family: var(--mono, monospace); font-size: 0.9em; background: var(--surface-2, #f3f3f3); padding: 0 0.25em; border-radius: 4px; }
.lab-problem { border-left: 4px solid var(--accent, #2563eb); background: var(--surface, #fff); padding: 0.75rem 1rem; border-radius: 0 var(--radius, 12px) var(--radius, 12px) 0; margin: 1rem 0; }
.lab-problem p { margin: 0; }

.lab-work { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; margin-top: 1rem; }
@media (max-width: 900px) { .lab-work { grid-template-columns: minmax(0, 1fr); } }
.lab-calc { position: sticky; top: 0.5rem; min-width: 0; }
@media (max-width: 900px) {
  /* keep the calculator in view while stepping through the walkthrough on phones */
  .lab-calc { top: 0; z-index: 5; background: var(--bg, #f7f7f5); padding: 0.4rem 0 0.5rem; }
  .lab-calc:has(.hp12c-panel:not([hidden])) { position: static; }
}
.lab-player { background: var(--surface, #fff); border: 1px solid var(--border, #e5e5e5); border-radius: var(--radius, 12px); padding: 0.9rem; min-width: 0; }
.lab-tabs { display: flex; gap: 0.35rem; margin-bottom: 0.75rem; }
.lab-tab { flex: 1; padding: 0.45rem; font: 600 0.85rem var(--font, system-ui); border-radius: 8px; cursor: pointer; border: 1px solid var(--border, #ddd); background: transparent; color: var(--text, #111); }
.lab-tab[aria-selected="true"] { background: var(--accent, #2563eb); color: var(--accent-ink, #fff); border-color: transparent; }
.lab-controls { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0; }
.lab-btn {
  padding: 0.45rem 0.85rem; font: 600 0.85rem var(--font, system-ui); border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border, #ddd); background: var(--surface-2, #f5f5f5); color: var(--text, #111);
}
.lab-btn:disabled { opacity: 0.45; cursor: default; }
.lab-btn.primary { background: var(--accent, #2563eb); color: var(--accent-ink, #fff); border-color: transparent; }
.lab-note { min-height: 3.2em; padding: 0.6rem 0.75rem; border-radius: 8px; background: var(--surface-2, #f5f5f5); font-size: 0.92rem; }
.lab-steps { list-style: none; margin: 0.6rem 0 0; padding: 0; max-height: 380px; overflow-y: auto; }
.lab-steps li { display: flex; gap: 0.55rem; align-items: flex-start; padding: 0.4rem 0.45rem; border-radius: 8px; cursor: pointer; font-size: 0.88rem; }
.lab-steps li .step-num { flex: 0 0 1.5rem; height: 1.5rem; border-radius: 50%; display: grid; place-items: center; font-size: 0.75rem; font-weight: 700; background: var(--surface-2, #eee); color: var(--muted, #666); }
.lab-steps li.done .step-num { background: var(--good, #16a34a); color: #fff; }
.lab-steps li.current { background: color-mix(in srgb, var(--accent, #2563eb) 12%, transparent); }
.lab-steps li.current .step-num { background: var(--accent, #2563eb); color: var(--accent-ink, #fff); }
.lab-keys { display: flex; flex-wrap: wrap; gap: 0.2rem; }
.lab-key { font-family: var(--mono, monospace); font-size: 0.78rem; padding: 0.05rem 0.4rem; border-radius: 5px; background: #2a2726; color: #fff; border-bottom: 2px solid #0e0d0c; white-space: nowrap; }
.lab-key.f { background: #d9a441; color: #1d1a16; }
.lab-key.g { background: #5aa7e3; color: #0f1a24; }
.lab-key.num { background: transparent; color: var(--text, #111); border: 1px solid var(--border, #ddd); border-bottom-width: 2px; }
.lab-answer { margin-top: 0.75rem; padding: 0.7rem 0.85rem; border-radius: 8px; border: 1px solid var(--good, #16a34a); background: color-mix(in srgb, var(--good, #16a34a) 9%, transparent); }
.lab-answer .val { font-family: var(--mono, monospace); font-size: 1.15rem; font-weight: 700; }
.lab-feedback { margin-top: 0.6rem; padding: 0.6rem 0.8rem; border-radius: 8px; font-size: 0.9rem; }
.lab-feedback.good { background: color-mix(in srgb, var(--good, #16a34a) 12%, transparent); color: var(--text, #111); border: 1px solid var(--good, #16a34a); }
.lab-feedback.bad { background: color-mix(in srgb, var(--bad, #dc2626) 10%, transparent); color: var(--text, #111); border: 1px solid var(--bad, #dc2626); }
.lab-pitfalls li { margin-bottom: 0.35rem; }
.lab-practice { background: var(--surface, #fff); border: 1px solid var(--border, #e5e5e5); border-radius: var(--radius, 12px); padding: 0.9rem; margin-bottom: 0.75rem; }
.lab-practice-row { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin-top: 0.6rem; }
.lab-input { width: 11rem; max-width: 100%; padding: 0.45rem 0.6rem; font: 500 0.95rem var(--mono, monospace); border: 1px solid var(--border, #ddd); border-radius: 8px; background: var(--bg, #fff); color: var(--text, #111); }
.lab-hint { font-size: 0.85rem; color: var(--muted, #666); margin-top: 0.5rem; }
.lab-kbd-help { font-size: 0.8rem; color: var(--muted, #666); margin-top: 0.75rem; }
.lab-kbd-help summary { cursor: pointer; }
.lab-kbd-help dl { display: grid; grid-template-columns: auto 1fr; gap: 0.2rem 0.75rem; margin: 0.5rem 0 0; }
.lab-kbd-help dt { font-family: var(--mono, monospace); color: var(--text, #111); }
.lab-kbd-help dd { margin: 0; }
.lab-done-row { display: flex; align-items: center; gap: 0.6rem; margin-top: 1rem; flex-wrap: wrap; }
