/* static/web/hf-web.css — Happy Fox 2.0 Web: phone & tablet layer
 * ===========================================================================
 * ADDED IN: Happy Fox 2.0 web port (Nov 2026). Self-contained stylesheet.
 *
 * PURPOSE
 *   The SPA's own <style> block was written for a 1280x800 Electron window.
 *   This file only ADDS / OVERRIDES what phones and small tablets need. It
 *   is linked AFTER the base <style>, so equal-specificity rules win here.
 *   Desktop (> 760px wide and > 520px tall) keeps its layout; the only
 *   desktop-visible change is the game-modal header fix right below
 *   (title and × were clipped off-screen in v1.2).
 *
 * WHAT IT COVERS
 *   - Bottom tab bar + "Practice" sheet (markup built by hf-web.js)
 *   - Sidebar hidden on phones (base CSS hid it only below 540px, with no
 *     replacement nav — phones had no way to reach most screens)
 *   - Game modal full-screen on phones and short landscape screens
 *   - Safe areas (notch / home indicator), 16px inputs (stops iOS zoom),
 *     toast / announcement popup lifted above the tab bar
 *
 * WIRING
 *   index.html <head>, fenced block "[HF-WEB 2.0] web shell includes".
 * REMOVAL
 *   Remove that <link> line. Nothing else depends on this file.
 * ===========================================================================
 */

/* ── Elements created by hf-web.js: hidden unless phone layout ─────────── */
.hfw-tabbar, .hfw-sheet, .hfw-sheet-backdrop { display: none; }

/* ── Game modal header: fix inherited from v1.2 (all screen sizes) ────────
 * Base .modal-header-bar has margin:-2rem -2rem 1.5rem to bleed into the
 * 2rem padding of normal modals. The game modal's box has padding:0, so the
 * header was pulled up/right out of the box: title and the × close button
 * were clipped on desktop too (users could only leave with Esc or a click
 * outside). On a full-screen phone there is no "outside" and no Esc.     */
#gameModal .modal-header-bar { margin: 0 !important; }

/* ── Game Lab embed (Games screen; built by hf-web.js) ─────────────────── */
.hfw-gamelab {
  position: relative; border-radius: var(--radius); overflow: hidden;
  background: #fff; box-shadow: 0 2px 12px rgba(29,53,87,.08);
  /* [HF 2.1] header 64 + main padding 2×24 + bar 52 + a little air */
  height: calc(100vh - 64px - 48px - 60px); height: calc(100dvh - 64px - 48px - 60px); min-height: 420px;
}
/* [HF 2.1] Games screen uses the whole content width (other screens keep 960px) */
body.hfw-on-games .hf-main { max-width: none; }
.hfw-gl-bar { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .6rem !important; }
.hfw-gl-bar h2 { margin: 0 !important; }
.hfw-gl-actions { margin-left: auto; display: flex; align-items: center; gap: .4rem; position: relative; }
.hfw-gl-btn { display: inline-flex; align-items: center; gap: .35rem; border: 2px solid #eef0f4; background: #fff; color: var(--dark, #1d3557);
  font: 800 .8rem Nunito, sans-serif; padding: .4rem .75rem; border-radius: 12px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.hfw-gl-btn:hover { border-color: var(--blue, #e63946); }
.hfw-gl-fs { background: var(--blue, #e63946); border-color: var(--blue, #e63946); color: #fff; }
/* the "¿Cómo funciona?" card lives in the bar as a pill; open = dropdown over the game */
.hfw-gl-actions .hfp-help { margin: 0; }
.hfw-gl-actions .hfp-help .hfp-help-pill { display: inline-block; padding: .4rem .75rem; border-radius: 12px; }
.hfw-gl-actions .hfp-help:not(.closed) .hfp-help-body { position: absolute; right: 0; top: calc(100% + 8px); z-index: 30; width: min(440px, 92vw);
  box-shadow: 0 16px 40px rgba(29,53,87,.22); }
.hfw-gl-exit { display: none; position: absolute; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 5;
  border: none; background: rgba(15,23,42,.55); color: #fff; font: 800 .8rem Nunito, sans-serif; padding: .45rem .8rem; border-radius: 999px;
  cursor: pointer; backdrop-filter: blur(6px); opacity: .75; }
.hfw-gl-exit:hover { opacity: 1; }
/* full screen: the game covers the whole app (and the browser bars where the device allows) */
body.hfw-gl-full { overflow: hidden; }
body.hfw-gl-full .hfw-gamelab { position: fixed !important; inset: 0; z-index: 4000; width: 100vw; height: 100vh !important; height: 100dvh !important;
  min-height: 0; border-radius: 0 !important; box-shadow: none; }
body.hfw-gl-full .hfw-gl-exit { display: block; }
body.hfw-gl-full .hfw-tabbar { display: none !important; }
.hfw-gamelab:fullscreen { width: 100vw; height: 100vh !important; border-radius: 0; }
.hfw-gamelab iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; }
.hfw-gamelab-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: .5rem; color: var(--gray); font-weight: 700; }
.hfw-gamelab-open { display: inline-block; margin-top: .6rem; font-size: .8rem; font-weight: 700; text-decoration: none; }

/* ── Header respects the notch on every screen size ─────────────────────── */
.hf-header {
  padding-top: env(safe-area-inset-top);
  height: calc(64px + env(safe-area-inset-top));
  padding-left: max(1.5rem, env(safe-area-inset-left));
  padding-right: max(1.5rem, env(safe-area-inset-right));
}

/* ── Short screens (landscape phones): full-screen game ─────────────────── */
@media (max-height: 520px) {
  #gameModal .modal-box {
    width: 100% !important; max-width: none !important;
    height: 100vh !important; height: 100dvh !important;
    max-height: none !important; border-radius: 0 !important;
  }
  #gameModal .modal-header-bar { border-radius: 0 !important; padding: .45rem 1rem !important; }
  #game-iframe { min-height: 0 !important; }
}

/* ===========================================================================
 * PHONE LAYOUT (<= 760px wide)
 * =========================================================================== */
@media (max-width: 760px) {

  /* Sidebar replaced by the bottom tab bar */
  .hf-sidebar { display: none !important; }

  .hf-header { padding-left: max(1rem, env(safe-area-inset-left)); padding-right: max(1rem, env(safe-area-inset-right)); }
  .hf-logo { font-size: 1.15rem; }
  .hf-header-right { gap: 8px; }

  .hf-main {
    padding: 1rem max(.9rem, env(safe-area-inset-left)) calc(92px + env(safe-area-inset-bottom));
    max-width: 100%;
    overflow-x: hidden;
  }
  .hf-layout { min-height: 0; }
  .section-head h2 { font-size: 1.3rem; }

  /* Inputs at 16px so iOS doesn't zoom the page on focus */
  .lfield input, #conv-inp, textarea, select { font-size: 16px !important; }

  /* Login */
  #login-overlay { padding: 1rem; }
  .lcard { padding: 2rem 1.4rem; }

  /* Grade banner: stack instead of three cramped columns */
  .grade-banner { flex-wrap: wrap; gap: 1rem; padding: 1.1rem 1.2rem; }
  .grade-items { flex: 1 1 100%; margin: 0; order: 3; }
  .grade-row-label { width: 96px; }

  /* Progress grade row + cards */
  #prog-grade-row { padding: 1rem 1.1rem !important; gap: 1rem !important; }
  .progress-cards { grid-template-columns: 1fr; }

  /* Stats: two per row, tighter */
  .stat-card { padding: .8rem .85rem; gap: .6rem; }
  .stat-icon { width: 34px; height: 34px; font-size: .95rem; }
  .stat-value { font-size: 1.15rem; }

  /* Game Lab: use the whole screen between header and tab bar.
     [HF 2.1] keeps a slim bar (icons only) for help + full screen */
  #screen-games .section-head.hfw-gl-bar { display: flex; margin-bottom: .45rem !important; }
  .hfw-gl-bar h2 { font-size: 1.05rem !important; }
  .hfw-gl-btn span { display: none; }
  .hfw-gl-btn { padding: .38rem .6rem; }
  .hfw-gl-actions .hfp-help .hfp-help-pill { font-size: 0; padding: .38rem .6rem; }
  .hfw-gl-actions .hfp-help .hfp-help-pill::before { content: '❓'; font-size: .85rem; }
  .hfw-gamelab {
    border-radius: 14px; min-height: 320px;
    height: calc(100vh - 64px - 112px - 42px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    height: calc(100dvh - 64px - 112px - 42px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }

  /* Reading / voice / conversation */
  .reading-card { padding: 1.3rem 1.2rem; }
  .voice-prompt-card { padding: 1.4rem 1.1rem; }
  .voice-prompt-card .prompt-text { font-size: 1.4rem; word-break: break-word; }
  #conv-msgs { max-height: calc(100vh - 330px) !important; max-height: calc(100dvh - 330px) !important; min-height: 240px !important; }

  /* Generic modals: never taller than the screen */
  .modal-box { max-height: calc(100vh - 2rem); max-height: calc(100dvh - 2rem); overflow-y: auto; }

  /* Game modal: full screen */
  #gameModal .modal-box {
    width: 100% !important; max-width: none !important;
    height: 100vh !important; height: 100dvh !important;
    max-height: none !important; border-radius: 0 !important;
    overflow: hidden !important;
  }
  #gameModal .modal-header-bar {
    border-radius: 0 !important;
    padding: calc(.55rem + env(safe-area-inset-top)) 1rem .55rem !important;
  }
  #game-iframe { min-height: 0 !important; }

  /* Toast + announcement popup sit above the tab bar */
  .toast {
    left: 12px; right: 12px; justify-content: center; text-align: center;
    bottom: calc(80px + env(safe-area-inset-bottom));
  }
  #ann-popup { bottom: calc(84px + env(safe-area-inset-bottom)) !important; }

  /* ── Bottom tab bar ───────────────────────────────────────────────────── */
  .hfw-tabbar {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 900;
    background: var(--dark);
    padding: 6px max(6px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-right));
    box-shadow: 0 -6px 24px rgba(29,53,87,.25);
    justify-content: space-around;
  }
  .hfw-tab {
    flex: 1 1 0; min-width: 0;
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 6px 2px 4px; border: none; background: none; border-radius: 12px;
    color: rgba(255,255,255,.55);
    font-family: 'Nunito', sans-serif; font-size: .66rem; font-weight: 700;
    cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .hfw-tab i { font-size: 1.15rem; }
  .hfw-tab span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .hfw-tab.active { color: #fff; background: linear-gradient(135deg, var(--blue), var(--blue-dark)); }

  /* ── Practice sheet ───────────────────────────────────────────────────── */
  .hfw-sheet-backdrop {
    display: block; position: fixed; inset: 0; z-index: 950;
    background: rgba(0,0,0,.45);
    opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  .hfw-sheet {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 960;
    background: #fff; border-radius: 22px 22px 0 0;
    padding: .6rem 1rem calc(1rem + env(safe-area-inset-bottom));
    transform: translateY(105%); transition: transform .28s var(--ease);
    max-height: 80vh; max-height: 80dvh; overflow-y: auto;
  }
  .hfw-sheet-open .hfw-sheet-backdrop { opacity: 1; pointer-events: auto; }
  .hfw-sheet-open .hfw-sheet { transform: translateY(0); }
  .hfw-sheet-grip { width: 42px; height: 5px; border-radius: 3px; background: #dde3ea; margin: .2rem auto .8rem; }
  .hfw-sheet-title { font-family: 'Baloo 2', cursive; font-size: 1.05rem; font-weight: 800; color: var(--dark); margin: 0 .2rem .6rem; }
  .hfw-sheet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
  .hfw-sheet-item {
    display: flex; flex-direction: column; align-items: center; gap: .4rem;
    padding: .85rem .3rem; border-radius: 14px; border: 2px solid transparent;
    background: #f4f7fb; color: var(--dark);
    font-family: 'Nunito', sans-serif; font-size: .76rem; font-weight: 800;
    cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .hfw-sheet-item i { font-size: 1.25rem; }
  .hfw-sheet-item.active { border-color: var(--blue); background: #eef4ff; }
  .hfw-sheet-row { display: flex; gap: .6rem; margin-top: .8rem; }
  .hfw-sheet-row .hfw-sheet-item { flex: 1 1 0; flex-direction: row; justify-content: center; font-size: .78rem; }
  .hfw-sheet-item.danger { color: var(--red); }
}

/* Very narrow phones (iPhone SE / small Android) */
@media (max-width: 420px) {
  .hw-due { display: none; }
  .leaderboard-group { display: none; }
  .hf-logo span { display: none; }
  .hfw-tab { font-size: .62rem; }
}

/* [HF 2.2] Class A plays pill in the Game Lab bar */
.hfw-classa { cursor: pointer; background: #fff7d6 !important; border-color: #ffd166 !important; font-weight: 800; }
@media (max-width: 560px) { .hfw-classa { font-size: .78rem; padding: .3rem .55rem; } }

/* [HF 2.4] phones: the full-screen button says what it does */
@media (max-width: 760px) {
  #screen-games .hfw-gl-fs span { display: inline !important; font-size: .78rem; }
  #screen-games .hfw-gl-fs { background: #e63946; color: #fff; border-color: #e63946; }
  .hfw-gl-exit { font-size: .9rem; }
}
@media (max-width: 760px) {
  /* [HF 2.4] the Games help opens as a sheet that fits the phone screen */
  .hfw-gl-actions .hfp-help:not(.closed) .hfp-help-body { position: fixed; left: 12px; right: 12px; width: auto;
    top: calc(70px + env(safe-area-inset-top)); max-height: 70vh; overflow: auto; z-index: 4500; }
}
