/*
 * CG50 Academy — simulator body, screen bezel and keypad (original artwork, no CASIO logo).
 * Scales with its container (container query units, px fallbacks). The calculator body keeps
 * its own dark look in light and dark site themes; only focus / highlight colours and the
 * drop shadow come from site tokens when they exist.
 */
.cg50 {
  --cg50-max-width: 460px;
  --cg50-focus: var(--focus-ring, var(--accent, #4c8dff));
  --cg50-hl: var(--cg50-highlight, #38a3ff);
  --cg50-shift: #f6c443;
  --cg50-alpha: #ff6b5f;
  --cg50-body-1: #30343c;
  --cg50-body-2: #1c1e23;
  --cg50-key-dark: #3a3f48;
  --cg50-key-dark-2: #2b2f36;
  --cg50-key-light: #f1f2f4;
  --cg50-key-light-2: #d5d8de;
  --cg50-key-blue: #3f7fd6;
  --cg50-key-blue-2: #2c5fa6;
  --cg50-fkey: #dfe2e8;
  --cg50-fkey-2: #b9bec8;
  container-type: inline-size;
  position: relative;
  width: 100%;
  max-width: var(--cg50-max-width);
  margin: 0 auto;
  outline: none;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
.cg50 *, .cg50 *::before, .cg50 *::after { box-sizing: border-box; }

/* ---------- body ---------- */
.cg50-body {
  position: relative;
  padding: 14px 16px 22px;
  padding: 3.6cqw 4.4cqw 6cqw;
  border-radius: 26px 26px 44px 44px / 22px 22px 38px 38px;
  border-radius: 6.5cqw 6.5cqw 11cqw 11cqw / 5.5cqw 5.5cqw 9.5cqw 9.5cqw;
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(255,255,255,0.10), rgba(255,255,255,0) 60%),
    linear-gradient(180deg, var(--cg50-body-1), var(--cg50-body-2));
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.18),
    inset 0 -3px 6px rgba(0,0,0,0.45),
    0 18px 40px -16px var(--cg50-shadow, rgba(10, 14, 25, 0.55)),
    0 3px 8px rgba(0,0,0,0.25);
  transition: box-shadow .15s;
}
.cg50:focus-visible .cg50-body,
.cg50.is-focus .cg50-body {
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.18),
    inset 0 -3px 6px rgba(0,0,0,0.45),
    0 0 0 3px var(--cg50-focus),
    0 18px 40px -16px var(--cg50-shadow, rgba(10, 14, 25, 0.55));
}
.cg50-top {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 0 4px 6px;
  padding: 0 1.2cqw 1.6cqw;
  color: #a3a9b4;
  font-size: 10px; font-size: 2.4cqw;
  letter-spacing: 0.06em;
}
.cg50-mark { font-weight: 700; color: #d7dbe2; letter-spacing: 0.02em; }
.cg50-mark::before {
  content: ""; display: inline-block; vertical-align: -0.12em;
  width: 0.95em; height: 0.95em; margin-right: 0.4em; border-radius: 0.22em;
  background: conic-gradient(from 210deg, #f6c443, #ff6b5f, #4f8ff7, #3fc48c, #f6c443);
}
.cg50-model { text-transform: uppercase; font-size: 0.9em; }

/* ---------- screen ---------- */
.cg50-bezel {
  padding: 11px 12px;
  padding: 2.8cqw 3cqw 3.2cqw;
  border-radius: 12px; border-radius: 3cqw;
  background: linear-gradient(180deg, #0c0d10, #16181d 70%, #0e0f12);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06), inset 0 2px 8px rgba(0,0,0,0.8), 0 1px 0 rgba(255,255,255,0.08);
}
.cg50-lcd {
  position: relative;
  overflow: hidden;
  border-radius: 3px; border-radius: 0.7cqw;
  background: #fff;
  aspect-ratio: 384 / 216;
  box-shadow: 0 0 0 1px #000, inset 0 0 6px rgba(0,0,0,0.25);
}
.cg50-lcd::after {   /* faint glass reflection */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(160deg, rgba(255,255,255,0.10) 0%, rgba(255,255,255,0) 38%);
}
.cg50-canvas { display: block; width: 100%; height: 100%; }
.cg50--screen-only .cg50-body { padding-bottom: 14px; padding-bottom: 3.6cqw; border-radius: 6.5cqw; }

/* ---------- keypad layout ---------- */
.cg50-keypad { margin-top: 14px; margin-top: 3.6cqw; }
.kp-cell { display: flex; flex-direction: column; align-items: stretch; min-width: 0; }
.kp-leg {
  display: flex; justify-content: space-between; align-items: flex-end;
  height: 12px; height: 3.1cqw;
  margin-bottom: 2px; margin-bottom: 0.5cqw;
  padding: 0 1px;
  font-size: 9.5px; font-size: 2.35cqw;
  line-height: 1; white-space: nowrap; font-weight: 600; letter-spacing: -0.01em;
}
.kp-leg--solo { justify-content: flex-start; }
.kp-leg--f { justify-content: center; font-size: 8.5px; font-size: 2.1cqw; }
.kp-leg-s { color: var(--cg50-shift); }
.kp-leg-a { color: var(--cg50-alpha); margin-left: auto; padding-left: 0.3em; }
.kp-leg sup { font-size: 0.7em; vertical-align: 0.45em; line-height: 0; }
.kp-leg sub { font-size: 0.7em; vertical-align: -0.1em; line-height: 0; }
.kp-cell-SD .kp-leg-s { font-size: 0.88em; letter-spacing: -0.04em; }
.kp-cell-7 .kp-leg, .kp-cell-4 .kp-leg, .kp-cell-8 .kp-leg, .kp-cell-9 .kp-leg { font-size: 9px; font-size: 2.15cqw; }

.kp-frow { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0 9px; gap: 0 2.3cqw; }
.kp-ctrl { display: grid; grid-template-columns: 1fr 31%; gap: 0 10px; gap: 0 2.6cqw; margin-top: 6px; margin-top: 1.4cqw; align-items: center; }
.kp-ctrlgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px 9px; gap: 0.8cqw 2.3cqw; }
.kp-funcgrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px 9px; gap: 0.9cqw 2.3cqw; margin-top: 6px; margin-top: 1.4cqw; }
.kp-numgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px 11px; gap: 1.4cqw 2.9cqw; margin-top: 10px; margin-top: 2.6cqw; }

/* ---------- keys ---------- */
.kp-key {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 100%;
  margin: 0; padding: 0;
  border: 0;
  border-radius: 6px / 7px; border-radius: 1.5cqw / 1.8cqw;
  font: inherit; font-weight: 600;
  font-size: 12px; font-size: 2.9cqw;
  line-height: 1;
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform .06s ease, box-shadow .06s ease, filter .1s;
  outline: none;
}
.kp-key:focus-visible { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--cg50-focus) !important; z-index: 2; }
.kp-face { pointer-events: none; display: inline-block; white-space: nowrap; line-height: 1; }
.kp-face sup { font-size: 0.62em; vertical-align: 0.6em; line-height: 0; margin-left: 0.04em; position: relative; }

.kp-fkey {
  height: 22px; height: 5.4cqw;
  border-radius: 5px; border-radius: 1.3cqw;
  color: #2a2e36; font-size: 10.5px; font-size: 2.6cqw;
  background: linear-gradient(180deg, var(--cg50-fkey), var(--cg50-fkey-2));
  box-shadow: 0 2px 0 #7f8592, 0 3px 4px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.7);
}
.kp-ctrl .kp-key, .kp-funcgrid .kp-key {
  height: 25px; height: 6.1cqw;
  background: linear-gradient(180deg, var(--cg50-key-dark), var(--cg50-key-dark-2));
  box-shadow: 0 2px 0 #121418, 0 3px 5px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.14);
}
.kp-funcgrid .kp-key { font-size: 12.5px; font-size: 3.05cqw; font-weight: 500; }
.kp-k-SQUARE, .kp-k-POWER { font-size: 13px !important; font-size: 3.2cqw !important; }
.kp-shiftkey { color: #2b2100 !important; background: linear-gradient(180deg, #f7cd56, #d9a822) !important; box-shadow: 0 2px 0 #7a5d08, 0 3px 5px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.45) !important; font-size: 10.5px !important; font-size: 2.55cqw !important; }
.kp-alphakey { color: #fff !important; background: linear-gradient(180deg, #ee5a4f, #c83b31) !important; box-shadow: 0 2px 0 #6e1712, 0 3px 5px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.3) !important; font-size: 10.5px !important; font-size: 2.55cqw !important; }
.kp-ctrl .kp-ctrl { font-size: 10.5px; font-size: 2.55cqw; }
.kp-k-OPTN, .kp-k-VARS, .kp-k-MENU, .kp-k-EXIT { font-size: 10.5px !important; font-size: 2.55cqw !important; letter-spacing: 0.02em; }

.kp-numgrid .kp-key {
  height: 31px; height: 7.6cqw;
  border-radius: 7px / 8px; border-radius: 1.8cqw / 2cqw;
  color: #16181c;
  font-size: 17px; font-size: 4.3cqw; font-weight: 500;
  background: linear-gradient(180deg, var(--cg50-key-light), var(--cg50-key-light-2));
  box-shadow: 0 2.5px 0 #80858f, 0 4px 6px rgba(0,0,0,0.5), inset 0 1px 0 #fff;
}
.kp-numgrid .kp-op { font-size: 19px; font-size: 4.8cqw; }
.kp-k-EXP, .kp-k-NEG { font-size: 13px !important; font-size: 3.3cqw !important; }
.kp-k-EXE { font-size: 13px !important; font-size: 3.3cqw !important; font-weight: 700 !important; letter-spacing: 0.04em; }
.kp-numgrid .kp-del, .kp-numgrid .kp-ac {
  color: #fff;
  font-size: 13px; font-size: 3.2cqw; font-weight: 700; letter-spacing: 0.03em;
  background: linear-gradient(180deg, #4e8fe6, var(--cg50-key-blue-2));
  box-shadow: 0 2.5px 0 #183c6d, 0 4px 6px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.35);
}
.kp-sub { font-size: 0.68em; font-weight: 600; margin-left: 0.05em; opacity: 0.9; }

/* fraction glyph on the key face: ▪ over ▫ */
.kp-fracicon { display: inline-flex; vertical-align: middle; flex-direction: column; align-items: center; gap: 0.12em; }
.kp-fracicon i { display: block; width: 0.52em; height: 0.44em; border: 1.5px solid currentColor; border-radius: 1px; }
.kp-fracicon i:first-child { background: currentColor; }
.kp-fracicon b { display: block; width: 0.9em; height: 1.5px; background: currentColor; }
.kp-fracicon--s { vertical-align: middle; font-size: 0.75em; margin-left: 0.1em; gap: 0.06em; }
.kp-fracicon--s i { border-width: 1px; }
.kp-fracicon--s b { height: 1px; }
.kp-mixicon { display: inline-flex; align-items: center; }

/* press / state feedback */
.kp-key.is-down, .kp-key.is-flash, .kp-key:active { transform: translateY(1.5px); filter: brightness(0.92); }
.kp-numgrid .kp-key.is-down, .kp-numgrid .kp-key.is-flash, .kp-numgrid .kp-key:active { box-shadow: 0 1px 0 #80858f, 0 1px 2px rgba(0,0,0,0.5), inset 0 1px 0 #fff; }
.kp-ctrl .kp-key.is-down, .kp-funcgrid .kp-key.is-down, .kp-ctrl .kp-key.is-flash, .kp-funcgrid .kp-key.is-flash { box-shadow: 0 1px 0 #121418, 0 1px 2px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.1); }
.kp-shiftkey.is-latched { box-shadow: 0 0 0 2px #fff3c4, 0 0 10px 2px rgba(246,196,67,0.85) !important; }
.kp-alphakey.is-latched { box-shadow: 0 0 0 2px #ffd6d2, 0 0 10px 2px rgba(255,107,95,0.8) !important; }
.kp-alphakey.is-locked::after { content: ""; position: absolute; left: 22%; right: 22%; bottom: 14%; height: 2px; border-radius: 1px; background: #fff; }
.mod-shift .kp-leg-s { text-shadow: 0 0 6px rgba(246,196,67,0.75); }
.mod-alpha .kp-leg-a { text-shadow: 0 0 6px rgba(255,107,95,0.75); }

.kp-key.is-hl { z-index: 3; animation: kp-pulse 1.1s ease-in-out infinite; }
@keyframes kp-pulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--cg50-hl), 0 0 0 5px rgba(56,163,255,0.25); }
  50% { box-shadow: 0 0 0 3px var(--cg50-hl), 0 0 0 9px rgba(56,163,255,0.0); }
}
.is-shake { animation: kp-shake .4s ease; }
@keyframes kp-shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-4px); } 40% { transform: translateX(4px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }

/* ---------- cursor pad ---------- */
.kp-pad { display: flex; align-items: center; justify-content: center; align-self: stretch; }
.kp-padring {
  position: relative;
  width: 100%; aspect-ratio: 1 / 1;
  max-height: 128px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #4a4f59, #262a30 70%);
  box-shadow: 0 3px 0 #0e1013, 0 5px 8px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.18), inset 0 0 0 1px rgba(0,0,0,0.4);
}
.kp-dir {
  position: absolute !important;
  background: transparent !important; box-shadow: none !important;
  border-radius: 40% !important;
  height: auto !important;
}
.kp-dir-up { top: 3%; left: 30%; width: 40% !important; height: 30% !important; }
.kp-dir-down { bottom: 3%; left: 30%; width: 40% !important; height: 30% !important; }
.kp-dir-left { left: 3%; top: 30%; width: 30% !important; height: 40% !important; }
.kp-dir-right { right: 3%; top: 30%; width: 30% !important; height: 40% !important; }
.kp-dir:hover { background: rgba(255,255,255,0.06) !important; }
.kp-dir.is-down, .kp-dir.is-flash, .kp-dir:active { background: rgba(255,255,255,0.12) !important; transform: none; }
.kp-dir.is-hl { animation: kp-pulse 1.1s ease-in-out infinite; }
.kp-arrow { width: 0; height: 0; border: 6px solid transparent; border: 1.5cqw solid transparent; }
.kp-dir-up .kp-arrow { border-bottom-color: #e8ebf0; border-top-width: 0; }
.kp-dir-down .kp-arrow { border-top-color: #e8ebf0; border-bottom-width: 0; }
.kp-dir-left .kp-arrow { border-right-color: #e8ebf0; border-left-width: 0; }
.kp-dir-right .kp-arrow { border-left-color: #e8ebf0; border-right-width: 0; }
.kp-padhub {
  position: absolute; left: 36%; top: 36%; width: 28%; height: 28%; border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #353a43, #1c1f24);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.7), 0 1px 0 rgba(255,255,255,0.1);
  pointer-events: none;
}

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

@media (prefers-reduced-motion: reduce) {
  .kp-key, .cg50-body { transition: none; }
  .kp-key.is-hl, .kp-dir.is-hl { animation: none; box-shadow: 0 0 0 3px var(--cg50-hl) !important; }
  .is-shake { animation: none; }
}
@media (forced-colors: active) {
  .kp-key { border: 1px solid ButtonText; }
}

/* P3-QA: on touch screens the small keys (F1–F6, SHIFT…EXIT, function rows) get an invisible
   hit area reaching into the legend gap, so the touch target is ~30 px tall at 360 px width. */
@media (pointer: coarse) {
  .kp-fkey::before, .kp-ctrl .kp-key::before, .kp-funcgrid .kp-key::before {
    content: ""; position: absolute; left: -3px; right: -3px; top: -7px; bottom: -5px;
  }
}
