/* Fonts come from the host page (the portal loads Chewy + Fredoka + Nunito). Nothing here
   @imports a font: an extra blocking request for a widget is not worth it, and the stack
   falls back to system-ui cleanly if the host ever drops one. */
/* Repainted 2026-09-04 for the boardwalk-arcade lab: the chat was the last thing still
   wearing the retired dark-purple palette. Same markup and behaviour — colour only. */
/* Floating family chat widget — Maya's Game Lab (iPad / iPhone friendly) */
#family-chat-widget{
  position:fixed;
  bottom:max(16px,env(safe-area-inset-bottom));
  right:max(12px,env(safe-area-inset-right));
  top:auto;
  left:auto;
  z-index:450;
  font-family:'Nunito',system-ui,sans-serif;
  -webkit-touch-callout:none;
}
#family-chat-widget *{box-sizing:border-box}

#family-chat-fab{
  position:relative;
  display:flex;align-items:center;justify-content:center;
  width:56px;height:56px;min-width:56px;min-height:56px;
  border:none;border-radius:50%;
  background:linear-gradient(135deg,var(--pink,#ff2d87),var(--purple,#c2452b));
  color:#fff;
  font-size:26px;line-height:1;
  cursor:pointer;
  box-shadow:0 6px 24px rgba(0,0,0,.45),0 0 0 2px rgba(255,255,255,.12);
  /* NOT `manipulation` — that still lets the browser claim a touch as a page pan,
     so a finger drifting a few px while tapping fired pointercancel and the chat
     never opened. `none` means no gesture on this button is ever a scroll, so a
     tap is always a tap. You don't scroll the page from a 56px button anyway. */
  touch-action:none;
  -webkit-user-select:none;user-select:none;
  transition:transform .15s,box-shadow .15s;
  /* iOS Safari promotes the game <iframe> to its own compositing layer; without
     our own layer, taps on this FAB fall through to the iframe and the chat
     won't open while a game is on screen. translateZ forces a sibling layer. */
  transform:translateZ(0);
}
#family-chat-fab:active{transform:translateZ(0) scale(.94)}
#family-chat-widget.fcw-panel-open #family-chat-fab{
  opacity:.85;
}
#family-chat-fab.pulse{animation:fcw-pulse 1.2s ease-in-out infinite}
@keyframes fcw-pulse{0%,100%{box-shadow:0 6px 24px rgba(0,0,0,.45),0 0 0 0 rgba(255,110,180,.5)}50%{box-shadow:0 6px 28px var(--ink,#3b2a2a),0 0 0 8px rgba(255,110,180,0)}}

#family-chat-badge{
  position:absolute;top:-2px;right:-2px;
  min-width:20px;height:20px;padding:0 5px;
  background:var(--yellow,#ffc61a);color:#3b2a2a;
  font-size:13px;font-weight:700;
  border-radius:99px;display:flex;align-items:center;justify-content:center;
  border:3px solid #3b2a2a;
}
#family-chat-badge[hidden]{display:none}

/* While a game is open, hide the floating chat so it never covers game controls
   or pops a note mid-play. Dad's notes still arrive in the game's own mailbox. */
body.maya-game-open #family-chat-widget{display:none!important}

/* Dad note peek — same corner as chat; tap to open full chat */
.dad-peek{
  position:absolute;
  right:0;
  bottom:68px;
  width:min(280px,calc(100vw - 32px));
  background:linear-gradient(135deg,#fff7e6,#ffeccf);
  border:3px solid var(--ink,#3b2a2a);
  border-radius:18px 18px 4px 18px;
  padding:12px 14px 10px;
  box-shadow:0 10px 36px rgba(0,0,0,.5);
  animation:dad-peek-in .4s cubic-bezier(.34,1.56,.64,1);
  touch-action:manipulation;
  /* Own layer so its reply button is tappable over a running game iframe. */
  transform:translateZ(0);
}
.dad-peek[hidden]{display:none!important}
@keyframes dad-peek-in{
  0%{transform:scale(.9) translateY(12px);opacity:0}
  100%{transform:scale(1) translateY(0);opacity:1}
}
.dad-peek-from{
  font-size:13px;font-weight:700;color:#c2452b;
  letter-spacing:.1em;text-transform:uppercase;margin-bottom:6px;
}
.dad-peek-text{
  font-size:14px;line-height:1.5;color:#3b2a2a;
  margin:0 0 10px;padding-right:20px;
}
.dad-peek-close{
  position:absolute;top:6px;right:8px;
  background:none;border:none;color:#3b2a2a;
  font-size:18px;width:40px;height:40px;
  cursor:pointer;line-height:1;touch-action:manipulation;
}
.dad-peek-reply{
  width:100%;padding:10px;
  background:#ffd9e8;
  border:3px solid var(--ink,#3b2a2a);
  border-radius:10px;
  font-family:'Nunito',system-ui,sans-serif;font-weight:700;font-size:15px;color:#3b2a2a;
  cursor:pointer;min-height:44px;touch-action:manipulation;
}

#family-chat-backdrop{
  position:fixed;inset:0;
  background:rgba(0,0,0,.45);
  z-index:449;
  opacity:0;visibility:hidden;
  transition:opacity .2s,visibility .2s;
  touch-action:manipulation;
  -webkit-tap-highlight-color:transparent;
  /* Own layer so tap-to-close lands here, not on the game iframe underneath. */
  transform:translateZ(0);
}
#family-chat-backdrop.open{
  opacity:1;visibility:visible;
}

#family-chat-panel{
  position:absolute;bottom:68px;right:0;top:auto;
  width:min(340px,calc(100vw - max(24px,env(safe-area-inset-left) + env(safe-area-inset-right))));
  max-height:min(62dvh,62vh,440px);
  display:flex;flex-direction:column;
  background:linear-gradient(180deg,#fff7e6,#ffeccf);
  border:3px solid var(--ink,#3b2a2a);
  border-radius:22px;
  box-shadow:6px 6px 0 var(--ink,#3b2a2a);
  overflow:hidden;
  opacity:0;visibility:hidden;transform:translateY(12px) scale(.96);
  transform-origin:bottom right;
  transition:opacity .2s,transform .2s,visibility .2s;
  touch-action:manipulation;
}
#family-chat-panel.open{
  opacity:1;visibility:visible;transform:translateY(0) scale(1);
}
#family-chat-widget.fcw-panel-open .dad-peek{
  display:none!important;
}

.fcw-panel-head{
  display:flex;align-items:center;gap:8px;
  padding:12px 14px;
  border-bottom:3px solid var(--ink,#3b2a2a);
  flex-shrink:0;
}
.fcw-panel-title{
  flex:1;
  font-family:'Fredoka','Nunito',ui-rounded,sans-serif;font-weight:700;
  font-size:17px;
  color:#3b2a2a;
}
.fcw-panel-close{
  display:flex;align-items:center;justify-content:center;
  background:#ffd9e8;
  border:3px solid var(--ink,#3b2a2a);color:#3b2a2a;
  width:44px;height:44px;min-width:44px;min-height:44px;
  border-radius:50%;
  font-size:22px;cursor:pointer;
  line-height:1;touch-action:manipulation;
  -webkit-user-select:none;user-select:none;
}

#family-chat-root{
  padding:12px 14px 14px;
  overflow:hidden;
  display:flex;flex-direction:column;
  min-height:0;
  flex:1;
}

.chat-hint{font-size:13px;color:rgba(59,42,42,.78);line-height:1.55;margin-bottom:12px}
.chat-lock{display:flex;flex-direction:column;gap:10px}
.chat-lock.shake{animation:chat-shake .35s ease}
@keyframes chat-shake{0%,100%{transform:translateX(0)}25%{transform:translateX(-6px)}75%{transform:translateX(6px)}}
.chat-pin-in,.chat-text-in{
  width:100%;background:#fffdf5;
  border:2px solid rgba(59,42,42,.78);border-radius:12px;
  padding:12px 14px;font-family:'Nunito',system-ui,sans-serif;font-size:16px;color:#3b2a2a;
  outline:none;min-height:44px;-webkit-appearance:none;
}
.chat-pin-in:focus,.chat-text-in:focus{border-color:var(--ink,#3b2a2a)}
.chat-send-btn{
  width:100%;padding:12px;
  background:linear-gradient(135deg,var(--pink,#ff2d87),var(--orange,#ff9a3c));
  border-radius:12px;
  font-family:'Fredoka','Nunito',ui-rounded,sans-serif;font-weight:700;font-size:17px;color:#fff;
  cursor:pointer;min-height:44px;
  border:3px solid var(--ink,#3b2a2a);
  box-shadow:0 3px 0 var(--ink,#3b2a2a);touch-action:manipulation;
}
.chat-send-btn:active{transform:translateY(2px);box-shadow:0 1px 0 var(--ink,#3b2a2a)}
.chat-send-btn:disabled{opacity:.55}
.chat-err{font-size:13px;color:#c2452b;font-weight:700}
.chat-role-row{display:flex;gap:10px}
.chat-role-btn{
  flex:1;padding:12px 8px;
  background:#ffd9e8;border:3px solid var(--ink,#3b2a2a);
  border-radius:12px;font-family:'Fredoka','Nunito',ui-rounded,sans-serif;font-weight:700;font-size:16px;color:#3b2a2a;
  cursor:pointer;min-height:48px;touch-action:manipulation;
}
.chat-role-btn.dad{background:#d6f0ff;border-color:var(--ink,#3b2a2a)}
.chat-head{display:flex;align-items:center;gap:6px;flex-wrap:wrap;margin-bottom:8px;font-size:13px;color:rgba(59,42,42,.78)}
.chat-you{flex:1;min-width:100px}
.chat-link-btn{
  background:none;border:none;color:#c2452b;
  font-size:13px;font-weight:700;cursor:pointer;
  padding:8px 10px;min-height:44px;min-width:44px;
  font-family:'Nunito',system-ui,sans-serif;
  touch-action:manipulation;
}
.chat-log{
  flex:1;min-height:120px;max-height:min(36dvh,36vh,280px);
  overflow-y:auto;-webkit-overflow-scrolling:touch;
  overscroll-behavior:contain;
  display:flex;flex-direction:column;gap:8px;
  padding:8px 4px 10px;margin-bottom:8px;
  background:#fffdf5;border:3px solid var(--ink,#3b2a2a);border-radius:12px;
}
.chat-empty{text-align:center;font-size:13px;color:rgba(59,42,42,.78);padding:20px 8px}
/* Top-of-log marker: 'loading older…' while a page is in flight, then the start-of-chat note. */
.chat-older{text-align:center;font-size:13px;color:rgba(59,42,42,.72);padding:10px 8px 14px}
/* Day divider: the only place a date appears. Same quiet ink as the other meta rows, with a hairline
   either side so it reads as a break in the conversation, not as a message. */
.chat-day{display:flex;align-items:center;gap:8px;margin:6px 4px 0;font-size:13px;font-weight:700;color:rgba(59,42,42,.72);flex-shrink:0}
.chat-day::before,.chat-day::after{content:"";flex:1;height:2px;border-radius:2px;background:rgba(59,42,42,.14)}
.chat-bubble{max-width:92%;padding:9px 11px;border-radius:14px;font-size:13px;line-height:1.45;color:#3b2a2a}
.chat-bubble.mine{
  align-self:flex-end;
  background:#ffe6b8;
  border:3px solid var(--ink,#3b2a2a);
  border-radius:14px 14px 4px 14px;
}
.chat-bubble.theirs{
  align-self:flex-start;
  background:#d6f0ff;
  border:3px solid var(--ink,#3b2a2a);
  border-radius:14px 14px 14px 4px;
}
.chat-bubble.dad.theirs{background:#efe3ff;border-color:var(--ink,#3b2a2a)}
.chat-bubble.local-note{opacity:.95;border-style:dashed}
.chat-who{display:block;font-size:13px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;color:#c2452b;margin-bottom:3px}
.chat-bubble.maya .chat-who{color:#b3175e}
.chat-body{display:block;word-break:break-word}
.chat-time{display:block;font-size:13px;color:rgba(59,42,42,.72);margin-top:4px;text-align:right}
.chat-form{display:flex;gap:8px;align-items:stretch;flex-shrink:0}
.chat-form .chat-text-in{
  flex:1;min-height:48px;
  font-size:16px;padding:12px 14px;
}
.chat-form .chat-send-btn{
  width:auto;min-width:76px;min-height:48px;
  padding:12px 14px;font-size:16px;
}

/* iPhone / narrow phones — full-screen chat (keyboard-friendly) */
@media(max-width:640px){
  .dad-peek{
    bottom:72px;
    width:min(300px,calc(100vw - 24px));
  }
  #family-chat-widget.fcw-panel-open #family-chat-fab{
    visibility:hidden;
    pointer-events:none;
  }
  #family-chat-panel{
    position:fixed;
    bottom:0;
    top:env(safe-area-inset-top,0);
    left:env(safe-area-inset-left,0);
    right:env(safe-area-inset-right,0);
    bottom:env(safe-area-inset-bottom,0);
    width:auto;
    max-height:none;
    height:100%;
    height:100dvh;
    border-radius:0;
    border-left:none;border-right:none;
    transform:translateY(100%);
  }
  #family-chat-panel.open{
    transform:translateY(0);
  }
  #family-chat-panel.fcw-kb-adjust{
    height:auto;
    max-height:none;
    bottom:auto;
  }
  .chat-log{
    max-height:none;
    flex:1;
    min-height:0;
  }
  #family-chat-root{
    flex:1;
    display:flex;
    flex-direction:column;
    min-height:0;
    padding-bottom:max(14px,env(safe-area-inset-bottom));
  }
}

@media(max-width:380px){
  #family-chat-fab{width:52px;height:52px;min-width:52px;min-height:52px;font-size:24px}
}

/* Inline image thumbnails in chat bubbles (posted from games via a hosted URL) */
.chat-body .chat-img{
  /* min() not a bare 180px: a fixed cap doesn't shrink with the panel, so once the
     bubble was narrower than 180px the picture spilled out of it and gave the log a
     horizontal scrollbar. 100% keeps it inside the bubble at any width. */
  max-width:min(180px,100%);
  max-height:140px;
  width:auto;
  height:auto;
  border-radius:8px;
  display:block;
  margin-top:4px;
}
