/* ============================================================
   DigitalKiddo™ Maths — Working Space (Scratch Pad)
   ------------------------------------------------------------
   A floating canvas panel students can scribble workings on
   while reading a lesson / answering a quiz question.

   Layout strategy:
   • ≥ 768px  → side panel docked to the RIGHT edge, so the
     lesson modal (centred) stays readable next to it.
   • < 768px  → bottom sheet that slides UP, leaving the top of
     the screen free for the question.
   • 1024×600 tablet-landscape gets a narrower panel + compact
     toolbar so the canvas keeps a useful height.

   z-index: the lesson modal overlay is 2000 (style.css), so the
   FAB (2040) and panel (2050) sit ABOVE it — the scratch pad is
   usable mid-quiz without closing anything. The panel is
   non-modal on purpose: no backdrop, the question stays visible.
   ============================================================ */

/* ── FLOATING "✏️ Working Space" BUTTON ─────────────────────── */
/* Stacked above the Kiddo Coach FAB (bottom: 24px in chat.css). */
.ws-fab {
  position: fixed;
  bottom: 84px;
  right: 24px;
  z-index: 2040;
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--orange, #ff9f43), #ffb95e);
  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(255, 159, 67, 0.4);
  transition: transform 0.2s, box-shadow 0.2s;
}
.ws-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(255, 159, 67, 0.5);
}
.ws-fab:active { transform: scale(0.96); }
/* Gentle wiggle on the pencil so kids spot it — respects reduced motion. */
.ws-fab .ws-fab-icon { display: inline-block; animation: ws-wiggle 3.2s ease-in-out infinite; }
@keyframes ws-wiggle {
  0%, 88%, 100% { transform: rotate(0deg); }
  91% { transform: rotate(-14deg); }
  94% { transform: rotate(12deg); }
  97% { transform: rotate(-8deg); }
}
@media (prefers-reduced-motion: reduce) {
  .ws-fab .ws-fab-icon { animation: none; }
}
/* While the panel is open the FAB hides — the panel has its own ❌. */
.ws-fab.ws-hidden { opacity: 0; pointer-events: none; transform: scale(0.6); }

/* ── PANEL ──────────────────────────────────────────────────── */
.ws-panel {
  position: fixed;
  z-index: 2050;
  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(420px, 44vw);
  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;
  touch-action: none; /* the panel itself never scrolls the page */
}
.ws-panel.open { transform: translateX(0); visibility: visible; }

/* ── HEADER ─────────────────────────────────────────────────── */
.ws-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;
}
.ws-title {
  font-family: 'Fredoka One', cursive;
  font-size: 1.05rem;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ws-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;
}
.ws-close:hover { background: rgba(255, 255, 255, 0.32); transform: rotate(90deg); }

/* ── CANVAS ─────────────────────────────────────────────────── */
.ws-canvas-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  margin: 0.75rem;
  border-radius: var(--radius-sm, 12px);
  border: 3px dashed var(--gray-200, #dfe6e9);
  /* Faint squared-paper grid so it feels like a maths exercise book. */
  background:
    linear-gradient(rgba(108, 99, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(108, 99, 255, 0.06) 1px, transparent 1px),
    #fffef9;
  background-size: 24px 24px, 24px 24px, auto;
  overflow: hidden;
}
.ws-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;      /* stylus / finger draws instead of scrolling */
  cursor: crosshair;
  display: block;
}
/* Friendly hint shown until the first stroke */
.ws-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--gray-400, #b2bec3);
  font-weight: 700;
  font-size: 0.9rem;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.3s;
  padding: 1rem;
}
.ws-hint .ws-hint-emoji { font-size: 2rem; }
.ws-panel.has-drawing .ws-hint { opacity: 0; }

/* ── TOOLBAR ────────────────────────────────────────────────── */
.ws-toolbar {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.75rem 0.85rem;
}
.ws-tool-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--gray-100, #f1f2f6);
  border-radius: 50px;
  padding: 5px 8px;
}
.ws-tool-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--white, #fff);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(45, 52, 54, 0.12);
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ws-tool-btn:hover { transform: translateY(-2px); box-shadow: 0 4px 10px rgba(45, 52, 54, 0.18); }
.ws-tool-btn:active { transform: scale(0.92); }
.ws-tool-btn:disabled {
  opacity: 0.35;
  cursor: default;
  transform: none;
  box-shadow: 0 2px 6px rgba(45, 52, 54, 0.08);
}
.ws-tool-btn.active {
  background: var(--primary, #6c63ff);
  box-shadow: 0 3px 10px rgba(108, 99, 255, 0.45);
}
/* Colour swatches */
.ws-color {
  width: 30px;
  height: 30px;
  border: 3px solid transparent;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  transition: transform 0.15s, border-color 0.15s;
}
.ws-color:hover { transform: scale(1.15); }
.ws-color.active {
  border-color: var(--white, #fff);
  box-shadow: 0 0 0 3px var(--primary, #6c63ff);
  transform: scale(1.12);
}
/* Pen sizes — dot grows with the stroke width it selects */
.ws-size {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: var(--white, #fff);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(45, 52, 54, 0.12);
  transition: transform 0.15s;
  padding: 0;
}
.ws-size:hover { transform: scale(1.1); }
.ws-size::after {
  content: '';
  border-radius: 50%;
  background: var(--dark, #2d3436);
  width: var(--ws-dot, 6px);
  height: var(--ws-dot, 6px);
}
.ws-size.active { background: var(--accent, #ffd93d); box-shadow: 0 3px 10px rgba(255, 217, 61, 0.55); }

/* ── MOBILE: bottom sheet (< 768px) ─────────────────────────── */
@media (max-width: 767px) {
  .ws-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 62vh;
    height: 62dvh;
    border-radius: var(--radius, 20px) var(--radius, 20px) 0 0;
    box-shadow: 0 -12px 40px rgba(45, 52, 54, 0.3);
    transform: translateY(105%);
  }
  .ws-panel.open { transform: translateY(0); }
  .ws-head { border-radius: var(--radius, 20px) var(--radius, 20px) 0 0; }
  /* Little grab-handle look for the sheet */
  .ws-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);
  }
  .ws-head { position: relative; padding-top: 1rem; }
  .ws-fab { bottom: 96px; right: 20px; }
}
/* Match the round Kiddo Coach FAB on small phones (chat.css ≤480px). */
@media (max-width: 480px) {
  .ws-fab {
    gap: 0;
    width: 56px;
    height: 56px;
    padding: 0;
    justify-content: center;
    font-size: 1.5rem;
    bottom: 96px;
    right: 24px;
  }
  .ws-fab .ws-fab-label { display: none; }
}

/* ── TABLET LANDSCAPE 1024×600-class screens ────────────────── */
/* Short + wide: keep the side panel but slim it down and compress
   header/toolbar so the canvas keeps a workable height. */
@media (min-width: 768px) and (max-height: 640px) {
  .ws-panel { width: min(360px, 40vw); }
  .ws-head { padding: 0.55rem 0.85rem; }
  .ws-title { font-size: 0.95rem; }
  .ws-canvas-wrap { margin: 0.5rem; }
  .ws-toolbar { padding: 0 0.5rem 0.55rem; gap: 0.35rem; }
  .ws-tool-btn { width: 35px; height: 35px; font-size: 1rem; }
  .ws-color { width: 26px; height: 26px; }
  .ws-size { width: 30px; height: 30px; }
  .ws-fab { bottom: 80px; }
}

@media (prefers-reduced-motion: reduce) {
  .ws-panel { transition: none; }
  .ws-fab, .ws-close, .ws-tool-btn, .ws-color, .ws-size { transition: none; }
}
