/* ============================================================
   DigitalKiddo™ Maths — Calculator (Kalkulator)
   ------------------------------------------------------------
   A floating educational calculator panel, styled and laid out
   to match the Working Space scratch pad (working-space.css).

   Layout strategy (same as Working Space):
   • ≥ 768px  → side panel docked to the RIGHT edge.
   • < 768px  → bottom sheet that slides UP.
   • 1024×600 tablet-landscape → slimmer panel, compact keys.

   z-index: modal overlay is 2000 (style.css), WS panel is 2050.
   Calculator FAB 2040 / panel 2052 — usable mid-quiz, non-modal
   (no backdrop, the question stays visible).
   ============================================================ */

/* ── FLOATING "🧮 Calculator" BUTTON ────────────────────────── */
/* Stacked above the Working Space FAB (bottom: 84px) which in
   turn sits above the Kiddo Coach FAB (bottom: 24px). */
.calc-fab {
  position: fixed;
  bottom: 144px;
  right: 24px;
  z-index: 2040;
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--green, #26de81), #4be89a);
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: 12px 20px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(38, 222, 129, 0.4);
  transition: transform 0.2s, box-shadow 0.2s;
}
.calc-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(38, 222, 129, 0.5);
}
.calc-fab:active { transform: scale(0.96); }
/* Gentle bounce on the abacus so kids spot it (like the ✏️ wiggle). */
.calc-fab .calc-fab-icon { display: inline-block; animation: calc-bounce 3.6s ease-in-out infinite; }
@keyframes calc-bounce {
  0%, 86%, 100% { transform: translateY(0); }
  90% { transform: translateY(-4px); }
  94% { transform: translateY(1px); }
  97% { transform: translateY(-2px); }
}
/* While the panel is open the FAB hides — the panel has its own ❌. */
.calc-fab.calc-fab-hidden { opacity: 0; pointer-events: none; transform: scale(0.6); }

/* ── PANEL ──────────────────────────────────────────────────── */
.calc-panel {
  position: fixed;
  z-index: 2052;
  display: flex;
  flex-direction: column;
  background: var(--white, #fff);
  box-shadow: -12px 0 40px rgba(45, 52, 54, 0.25);
  /* Side-panel default (desktop / tablet ≥768px) */
  top: 0;
  right: 0;
  bottom: 0;
  width: min(340px, 40vw);
  border-radius: var(--radius, 20px) 0 0 var(--radius, 20px);
  transform: translateX(105%);
  visibility: hidden;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.35s;
}
.calc-panel.open { transform: translateX(0); visibility: visible; }

/* ── HEADER (matches .ws-head) ──────────────────────────────── */
.calc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.85rem 1rem 0.75rem;
  background: linear-gradient(135deg, var(--primary, #6c63ff), #8b85ff);
  border-radius: var(--radius, 20px) 0 0 0;
  color: #fff;
  flex-shrink: 0;
}
.calc-title {
  font-family: 'Fredoka One', cursive;
  font-size: 1.05rem;
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.calc-close {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}
.calc-close:hover { background: rgba(255, 255, 255, 0.32); transform: rotate(90deg); }

/* ── DISPLAY ────────────────────────────────────────────────── */
.calc-display {
  flex-shrink: 0;
  position: relative;
  margin: 0.75rem 0.75rem 0.5rem;
  padding: 0.7rem 0.9rem 0.8rem;
  border-radius: var(--radius-sm, 12px);
  border: 3px dashed var(--gray-200, #dfe6e9);
  background: #fffef9;      /* same exercise-book paper as the WS canvas */
  text-align: right;
  overflow: hidden;
}
.calc-expr {
  min-height: 1.4em;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--gray-600, #636e72);
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;      /* clean edge-to-edge number strip */
}
.calc-expr::-webkit-scrollbar { display: none; }
.calc-result {
  font-family: 'Fredoka One', cursive;
  font-size: 1.7rem;
  line-height: 1.25;
  min-height: 1.25em;
  color: var(--primary, #6c63ff);
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.calc-result::-webkit-scrollbar { display: none; }
/* Friendly hint shown while the display is empty (like .ws-hint) */
.calc-hint {
  position: absolute;
  top: 0.55rem;
  left: 0.9rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--gray-400, #b2bec3);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.calc-panel.calc-empty .calc-hint { opacity: 1; }

/* Error state — red result + a little head-shake */
.calc-panel.calc-error .calc-result {
  color: var(--secondary, #ff6b6b);
  font-size: 1.15rem;
  animation: calc-shake 0.4s ease;
}
@keyframes calc-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

/* ── KEYPAD ─────────────────────────────────────────────────── */
.calc-keys {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 1fr;
  gap: 0.5rem;
  padding: 0.25rem 0.75rem 0.85rem;
}
.calc-key {
  border: none;
  border-radius: var(--radius-sm, 12px);
  background: var(--white, #fff);
  box-shadow: 0 2px 6px rgba(45, 52, 54, 0.14);
  font-family: 'Fredoka One', cursive;
  font-size: 1.25rem;
  color: var(--dark, #2d3436);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;                     /* touch-friendly */
  transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
}
.calc-key:hover { transform: translateY(-2px); box-shadow: 0 5px 12px rgba(45, 52, 54, 0.2); }
.calc-key:active, .calc-key.pressed { transform: scale(0.93); box-shadow: 0 1px 4px rgba(45, 52, 54, 0.18); }

/* Key colour roles — same palette as the rest of the app */
.calc-key--util  { background: var(--gray-100, #f1f2f6); color: var(--gray-600, #636e72); font-size: 1.05rem; }
.calc-key--op    { background: color-mix(in srgb, var(--primary, #6c63ff) 14%, #fff); color: var(--primary, #6c63ff); }
.calc-key--clear { background: color-mix(in srgb, var(--secondary, #ff6b6b) 16%, #fff); color: var(--secondary, #ff6b6b); }
.calc-key--eq {
  grid-row: span 2;
  background: linear-gradient(135deg, var(--green, #26de81), #4be89a);
  color: #fff;
  font-size: 1.6rem;
  box-shadow: 0 4px 14px rgba(38, 222, 129, 0.45);
}
.calc-key--eq:hover { filter: brightness(1.06); }
.calc-key--zero { grid-column: span 2; }

/* ── MOBILE: bottom sheet (< 768px) — mirrors .ws-panel ─────── */
@media (max-width: 767px) {
  .calc-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: auto;
    max-height: 78vh;
    max-height: 78dvh;
    border-radius: var(--radius, 20px) var(--radius, 20px) 0 0;
    box-shadow: 0 -12px 40px rgba(45, 52, 54, 0.3);
    transform: translateY(105%);
  }
  .calc-panel.open { transform: translateY(0); }
  .calc-head {
    position: relative;
    padding-top: 1rem;
    border-radius: var(--radius, 20px) var(--radius, 20px) 0 0;
  }
  /* Little grab-handle look for the sheet */
  .calc-head::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 44px;
    height: 4px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.45);
  }
  .calc-keys { grid-auto-rows: minmax(52px, 1fr); flex: 0 1 auto; }
  .calc-fab { bottom: 156px; right: 20px; }
}
/* Match the round FABs on small phones (chat.css / ws ≤480px). */
@media (max-width: 480px) {
  .calc-fab {
    gap: 0;
    width: 56px;
    height: 56px;
    padding: 0;
    justify-content: center;
    font-size: 1.5rem;
    bottom: 160px;
    right: 24px;
  }
  .calc-fab .calc-fab-label { display: none; }
}

/* ── TABLET LANDSCAPE 1024×600-class screens ────────────────── */
/* Short + wide: keep the side panel, slim it down and compress
   the display + keys so all 6 rows fit without scrolling. */
@media (min-width: 768px) and (max-height: 640px) {
  .calc-panel { width: min(300px, 36vw); }
  .calc-head { padding: 0.55rem 0.85rem; }
  .calc-title { font-size: 0.95rem; }
  .calc-display { margin: 0.5rem 0.5rem 0.4rem; padding: 0.5rem 0.7rem 0.6rem; }
  .calc-expr { font-size: 0.9rem; }
  .calc-result { font-size: 1.35rem; }
  .calc-keys { gap: 0.35rem; padding: 0.15rem 0.5rem 0.55rem; }
  .calc-key { font-size: 1.05rem; min-height: 36px; border-radius: 10px; }
  .calc-key--eq { font-size: 1.3rem; }
  .calc-fab { bottom: 134px; }
}

@media (prefers-reduced-motion: reduce) {
  .calc-fab .calc-fab-icon { animation: none; }
  .calc-panel { transition: none; }
  .calc-fab, .calc-close, .calc-key { transition: none; }
  .calc-panel.calc-error .calc-result { animation: none; }
}
