/* calc.css — the Knox Calculator (calc.js), in the same Knox sticker style
   as Flashcards: badge + big title, chunky keys with colored ledges. Uses
   the theme variables, so Light, Dark and Fall all just work. */
/* Sized to fit one screen: the keys grow and shrink with the window height. */
#calcModal { align-items: center; padding: clamp(12px, 2.4vh, 28px) clamp(14px, 3vw, 36px); --kc-key: clamp(40px, calc(6.2vh / var(--kz, 1)), 56px); }
#calcModal .kc-wrap { position: relative; z-index: 1; width: 100%; max-width: 960px; margin: auto; }
#calcModal button { font-family: inherit; cursor: pointer; }

/* Header — same recipe as Flashcards / the welcome screen */
.kc-head { text-align: center; margin: 0 auto clamp(10px, 2vh, 18px); }
/* The calculator's blue (like its sidebar icon); the same pill as the other sections */
.kc-badge { display: inline-flex; align-items: center; gap: 6px; background: var(--blue-light); border: 2px solid var(--blue); border-radius: 999px; padding: 7px 18px; font-size: 14px; font-weight: 800; color: var(--blue-dark); margin-bottom: 10px; }
html[data-theme="dark"]:not(.knox-seasonal) .kc-badge { color: var(--blue); }
.kc-title { font-size: clamp(24px, 3.4vw, 34px); font-weight: 900; line-height: 1.05; letter-spacing: -.02em; margin: 0; color: var(--text); outline: none; }
.kc-title .accent { color: var(--blue); }
.kc-sub { font-size: 16px; font-weight: 700; color: var(--text-light); line-height: 1.55; margin: 0 auto; }

/* Back + Basic/Scientific, inside the top of the card */
.kc-cardbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.kc-back { border: 0; font-size: 13.5px; font-weight: 900; padding: 7px 12px; border-radius: 10px;
  color: var(--orange); background: var(--orange-light); } /* the color of the mode you came from: Ask Knox… */
.kc-back:hover { filter: brightness(.97); box-shadow: inset 0 0 0 2px var(--orange); }
body.knox-learn-mode .kc-back { color: var(--purple-on-tint); background: var(--purple-light); } /* …or Learn */
body.knox-learn-mode .kc-back:hover { box-shadow: inset 0 0 0 2px var(--purple); }
html.knox-seasonal body:not(.knox-learn-mode) .kc-back { color: #873D28; background: #FBE4C6; } /* Fall's Ask Knox colors */
.kc-modes { display: inline-flex; gap: 3px; padding: 3px; border-radius: 13px; background: var(--cream-warm); border: 2px solid var(--border); }
.kc-mode { border: 0; border-radius: 10px; padding: 6px 14px; background: transparent; color: var(--text-light); font-size: 13px; font-weight: 900; }
.kc-mode.on { background: var(--orange); color: #fff; box-shadow: 0 3px 0 var(--orange-dark); }

/* Card + history side by side, the same height and lined up */
.kc-layout { display: grid; grid-template-columns: auto 240px; gap: 18px; justify-content: center; align-items: stretch; }
.kc-card { width: 400px; max-width: 100%; background: var(--surface); border: 3px solid var(--orange); border-radius: 26px; box-shadow: 0 6px 0 var(--orange-dark); padding: 12px 14px 14px; }
/* Scientific: the function keys sit beside the number pad (wider, not taller) */
.kc-card.kc-is-sci { width: 680px; }
.kc-pads { display: grid; grid-template-columns: 1fr; gap: 12px; }
.kc-is-sci .kc-pads { grid-template-columns: 5fr 4fr; }

/* Screen */
.kc-screen { border-radius: 18px; background: var(--cream-warm); border: 2px solid var(--border); padding: 10px 16px 8px; margin-bottom: 12px; text-align: right; height: clamp(96px, calc(13vh / var(--kz, 1)), 116px); display: flex; flex-direction: column; justify-content: flex-end; overflow: hidden; }
.kc-expr { font-size: 13.5px; font-weight: 800; color: var(--text-light); min-height: 19px; overflow-wrap: anywhere; }
.kc-result { font-size: clamp(30px, 6vw, 40px); font-weight: 900; color: var(--text); line-height: 1.15; overflow-wrap: anywhere; letter-spacing: -.01em; }
.kc-result:not(.kc-big) { font-size: clamp(24px, 4.6vw, 32px); }
.kc-big { color: var(--orange); }
.kc-pop { animation: kcPop .28s ease-out; }
@keyframes kcPop { 0% { transform: scale(.94); opacity: .4; } 100% { transform: none; opacity: 1; } }
.kc-caret { display: inline-block; width: 2px; height: .9em; margin-left: 2px; vertical-align: -.08em; background: var(--orange); animation: kcBlink 1s steps(1) infinite; }
@keyframes kcBlink { 50% { opacity: 0; } }
.kc-preview { font-size: 17px; font-weight: 800; color: var(--text-light); min-height: 24px; }
.kc-preview.kc-err { color: var(--red); font-size: 14.5px; }
.kc-frac { font-size: 15px; font-weight: 800; color: var(--green-dark); min-height: 22px; }
html[data-theme="dark"] .kc-frac { color: var(--green); }

/* Keys */
.kc-sci { display: grid; grid-template-columns: repeat(5, 1fr); grid-auto-rows: 1fr; gap: 8px; }
.kc-sci[hidden] { display: none; }
.kc-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
.kc-key { min-height: var(--kc-key); border-radius: 16px; border: 2px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 22px; font-weight: 900; box-shadow: 0 4px 0 var(--border); transition: transform .08s, box-shadow .08s, background .12s; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.kc-key:hover { transform: translateY(-1px); box-shadow: 0 5px 0 var(--border); }
.kc-key:active, .kc-key.kc-pressed { transform: translateY(3px); box-shadow: 0 1px 0 var(--border); }
.kc-op { background: var(--orange-cream); border-color: var(--orange-light); color: var(--orange); box-shadow: 0 4px 0 var(--orange-light); }
.kc-op:hover { box-shadow: 0 5px 0 var(--orange-light); }
.kc-op:active, .kc-op.kc-pressed { box-shadow: 0 1px 0 var(--orange-light); }
.kc-eq { background: var(--orange); border-color: var(--orange-dark); color: #fff; font-size: 26px; box-shadow: 0 4px 0 var(--orange-dark); }
.kc-eq:hover { box-shadow: 0 5px 0 var(--orange-dark); }
.kc-eq:active, .kc-eq.kc-pressed { box-shadow: 0 1px 0 var(--orange-dark); }
.kc-clear { background: color-mix(in srgb, var(--red) 12%, var(--surface)); border-color: color-mix(in srgb, var(--red) 35%, transparent); color: var(--red); font-size: 18px; box-shadow: 0 4px 0 color-mix(in srgb, var(--red) 35%, transparent); }
.kc-del { color: var(--text-light); font-size: 20px; }
.kc-sci .kc-key { min-height: 0; font-size: 15px; border-radius: 13px; box-shadow: 0 3px 0 var(--border); }
.kc-fn { background: var(--blue-light); border-color: color-mix(in srgb, var(--blue) 35%, transparent); color: var(--blue-dark); box-shadow: 0 3px 0 color-mix(in srgb, var(--blue) 35%, transparent) !important; }
html[data-theme="dark"] .kc-fn { color: var(--blue); }
.kc-fn.kc-on { background: var(--blue); color: #fff; border-color: var(--blue-dark); }
.kc-modekey { font-size: 13px !important; }
.kc-const { background: var(--green-light); border-color: color-mix(in srgb, var(--green) 40%, transparent); color: var(--green-dark); box-shadow: 0 3px 0 color-mix(in srgb, var(--green) 40%, transparent) !important; }
html[data-theme="dark"] .kc-const { color: var(--green); }
.kc-sci .kc-op { font-size: 17px; }

/* Answer actions */
.kc-actions { display: grid; grid-template-columns: 1fr 1fr 1.2fr; gap: 8px; margin-top: 12px; }
.kc-act { min-height: 42px; border-radius: 13px; border: 2px solid var(--border); background: var(--surface); color: var(--text); font-size: 13px; font-weight: 900; box-shadow: 0 3px 0 var(--border); }
.kc-act-main { background: var(--blue); border-color: var(--blue-dark); color: #fff; box-shadow: 0 3px 0 var(--blue-dark); }
.kc-act:disabled { opacity: .4; cursor: default; box-shadow: none; }
.kc-act:not(:disabled):active { transform: translateY(2px); box-shadow: none; }

/* History */
.kc-history { background: var(--surface); border: 2px solid var(--border); border-radius: 22px; box-shadow: 0 4px 0 var(--border); padding: 14px; display: flex; flex-direction: column;
  height: 0; min-height: 100%; } /* exactly the card's height; the list scrolls inside */
.kc-history-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.kc-history-top b { font-size: 12px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; color: var(--text-light); }
.kc-link { border: 0; background: transparent; color: var(--orange); font-size: 12.5px; font-weight: 900; padding: 4px 6px; border-radius: 8px; }
.kc-link[hidden] { display: none; }
.kc-history-body { overflow-y: auto; flex: 1; min-height: 0; }
.kc-tip { margin-top: 12px; padding-top: 10px; border-top: 2px dashed var(--border); }
.kc-empty { font-size: 13px; font-weight: 700; color: var(--text-light); line-height: 1.5; margin: 6px 0; }
.kc-hist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.kc-hist-item { width: 100%; text-align: right; border: 2px solid transparent; background: var(--cream-warm); border-radius: 12px; padding: 8px 10px; color: var(--text); display: flex; flex-direction: column; gap: 1px; }
.kc-hist-item:hover { border-color: var(--orange); }
.kc-hist-expr { font-size: 12px; font-weight: 700; color: var(--text-light); overflow-wrap: anywhere; }
.kc-hist-item b { font-size: 17px; font-weight: 900; overflow-wrap: anywhere; }

.kc-toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 12px); padding: 10px 18px; border-radius: 14px; background: var(--text); color: var(--surface); font-size: 14px; font-weight: 900; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 20; }
.kc-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Not enough room for the wide Scientific card + history: history goes below. */
@media (max-width: 1180px) {
  .kc-layout:has(.kc-is-sci) { grid-template-columns: auto; }
  .kc-layout:has(.kc-is-sci) .kc-history { height: auto; min-height: 0; max-height: 220px; }
}
@media (max-width: 760px) {
  #calcModal { align-items: flex-start; }
  .kc-layout { grid-template-columns: minmax(0, 1fr); }
  .kc-card, .kc-card.kc-is-sci { width: 100%; }
  .kc-is-sci .kc-pads { grid-template-columns: 1fr; }
  .kc-history { height: auto; min-height: 0; max-height: 240px; }
}
/* Phones: the whole calculator (keys + Copy / Send / Explain) fits one
   screen — keys follow the screen height; history sits below it. */
@media (max-width: 760px) {
  #calcModal { padding: 10px 12px 24px; }
  .kc-head { margin-bottom: 8px; }
  .kc-badge { display: none; }
  .kc-title { font-size: 22px; }
  .kc-screen { height: clamp(62px, 9vh, 92px); padding: 8px 14px 6px; margin-bottom: 10px; }
  .kc-result { font-size: clamp(26px, 8vw, 34px); }
  .kc-cardbar { margin-bottom: 8px; }
  .kc-key { min-height: clamp(40px, 6.3vh, 54px); }
  .kc-is-sci .kc-key { min-height: clamp(36px, 5.2vh, 48px); }
  .kc-is-sci .kc-sci .kc-key { min-height: clamp(28px, 4.1vh, 38px); }
  .kc-actions { grid-template-columns: 1fr 1fr 1fr; margin-top: 10px; }
  .kc-act { min-height: 38px; font-size: 12px; }
}
@media (max-width: 420px) {
  .kc-card { padding: 10px; border-radius: 22px; }
  .kc-keys { gap: 7px; }
  .kc-key { font-size: 20px; }
  .kc-sci { gap: 5px; }
  .kc-sci .kc-key { font-size: 13.5px; }
  .kc-pads { gap: 8px; }
}
@media (prefers-reduced-motion: reduce) { .kc-caret, .kc-pop { animation: none; } }

/* Shared Flashcards card language: blue calculator, light-blue history,
   comfortable keys, and layout based on available panel width. */
#calcModal { container-type:inline-size; align-items:flex-start; padding:20px 24px; overscroll-behavior:none; overflow-anchor:none; }
#calcModal .kc-wrap { max-width:1040px; margin:0 auto; min-width:0; }
.kc-head { margin-bottom:24px; }
.kc-badge { background:var(--blue-light); color:var(--blue-dark); border-color:var(--blue); box-shadow:0 3px 0 var(--blue-dark); }
.kc-title { font-size:clamp(28px,3.4vw,40px); line-height:1.2; margin:8px 0; }
.kc-title .accent { color:var(--blue); }
.kc-sub { font-size:14px; }
.kc-layout { grid-template-columns:minmax(0,1fr) 240px; align-items:start; gap:20px; max-width:860px; margin:auto; }
.kc-card,.kc-card.kc-is-sci { width:100%; min-width:0; padding:20px; border:2px solid var(--blue); border-radius:20px; box-shadow:0 4px 0 var(--blue-dark); }
.kc-cardbar { flex-wrap:wrap; gap:12px; margin-bottom:18px; }
.kc-modes { padding:4px; border-radius:14px; }
.kc-mode { min-height:38px; }
.kc-mode.on { background:var(--blue); box-shadow:0 3px 0 var(--blue-dark); }
.kc-screen { height:auto; min-height:116px; max-height:220px; overflow:auto; padding:16px 18px; border-radius:16px; background:var(--cream-warm); border-color:var(--border); margin-bottom:18px; }
.kc-result { font-variant-numeric:tabular-nums; }
.kc-big { color:var(--text); }
.kc-keys { gap:10px; }
.kc-key { min-height:50px; border-radius:13px; font-size:22px; box-shadow:0 3px 0 var(--border); }
.kc-sci .kc-key { min-height:44px; }
.kc-actions { margin-top:18px; gap:10px; }
.kc-act { min-height:46px; padding:8px 6px; }
/* History: a secondary card in the calculator's light blue (purple is Learn's color). */
.kc-history { height:auto; min-height:0; max-height:550px; padding:18px; border:2px solid color-mix(in srgb,var(--blue) 40%,var(--border)); border-radius:20px; box-shadow:0 4px 0 color-mix(in srgb,var(--blue) 40%,var(--border)); }
.kc-history-top { padding-bottom:12px; border-bottom:2px solid var(--border); gap:8px; }
.kc-history-top b { color:var(--text); font-size:14px; }
.kc-history-body { max-height:440px; }
#calcModal button:focus-visible { outline:3px solid var(--blue); outline-offset:4px; }
html[data-theme="dark"]:not(.knox-seasonal) .kc-badge { color:var(--blue); }
html.knox-seasonal .kc-fn,html.knox-seasonal .kc-badge { color:var(--blue-dark); }
html.knox-seasonal .kc-const { color:var(--green-dark); }
.kc-layout:has(.kc-is-sci) { grid-template-columns:minmax(0,1fr) 220px; max-width:1040px; }
@container (max-width:900px) {
 .kc-layout,.kc-layout:has(.kc-is-sci) { grid-template-columns:minmax(0,1fr); max-width:680px; margin:auto; }
 .kc-history { max-height:260px; }
 .kc-history-body { max-height:190px; }
}
@container (max-width:560px) {
 .kc-is-sci .kc-pads { grid-template-columns:1fr; }
 .kc-card,.kc-card.kc-is-sci { padding:14px; }
 .kc-cardbar { justify-content:center; }
 .kc-back { margin-right:auto; }
 .kc-sci { gap:7px; }
 .kc-sci .kc-key { min-height:44px; font-size:14px; }
 .kc-actions { gap:6px; }
 .kc-act { font-size:12px; }
}
@media(max-width:760px) {
 #calcModal { padding:18px 12px 28px; }
 .kc-badge { display:inline-flex; }
 .kc-head { margin-bottom:18px; }
 .kc-is-sci .kc-key { min-height:48px; }
}
/* Phone scientific mode keeps the number pad near the function keys. */
@container (max-width:560px) {
 .kc-wrap:has(.kc-is-sci) .kc-head { margin-bottom:12px; }
 .kc-wrap:has(.kc-is-sci) .kc-title { font-size:26px; margin:4px 0; }
 .kc-wrap:has(.kc-is-sci) .kc-badge { margin-bottom:4px; padding:4px 12px; }
 .kc-is-sci .kc-screen { min-height:68px; padding:8px 12px; margin-bottom:12px; }
 .kc-is-sci .kc-cardbar { gap:6px; margin-bottom:12px; }
 .kc-is-sci .kc-sci .kc-key { min-height:32px; font-size:13px; }
 .kc-is-sci .kc-keys { gap:7px; }
 .kc-is-sci .kc-keys .kc-key { min-height:40px; font-size:20px; }
 .kc-is-sci .kc-pads { gap:10px; }
 .kc-is-sci .kc-actions { margin-top:12px; }
}
/* The calculator's keys follow the same rule as every section: everyday keys
   white (operators only get a blue symbol), the main key (=) solid blue. AC stays red; "Back" keeps the color of
   where you came from. */
.kc-op { background:var(--surface); border-color:var(--border); color:var(--blue-dark); box-shadow:0 4px 0 var(--border); }
.kc-op:hover { box-shadow:0 5px 0 var(--border); }
.kc-op:active, .kc-op.kc-pressed { box-shadow:0 1px 0 var(--border); }
html[data-theme="dark"]:not(.knox-seasonal) .kc-op { color:var(--blue); }
.kc-eq { background:var(--blue); border-color:var(--blue-dark); box-shadow:0 4px 0 var(--blue-dark); }
.kc-eq:hover { box-shadow:0 5px 0 var(--blue-dark); }
.kc-eq:active, .kc-eq.kc-pressed { box-shadow:0 1px 0 var(--blue-dark); }
.kc-caret { background:var(--blue); }
.kc-link { color:var(--blue-dark); }
html[data-theme="dark"]:not(.knox-seasonal) .kc-link { color:var(--blue); }
.kc-hist-item:hover { border-color:var(--blue); }
/* Explain it opens Learn (solid purple, the main action); Send to Knox goes to
   Ask Knox (white with orange, a secondary action); Copy stays plain. */
.kc-act-learn { background:var(--purple); border-color:var(--purple-dark); color:#fff; box-shadow:0 3px 0 var(--purple-dark); }
.kc-act-ask { color:var(--orange-dark); border-color:color-mix(in srgb,var(--orange) 55%,var(--border)); box-shadow:0 3px 0 color-mix(in srgb,var(--orange) 55%,var(--border)); }
html[data-theme="dark"]:not(.knox-seasonal) .kc-act-ask { color:var(--orange); }
