/* =========================================================================
   L'OFFICINA DI CARLO — sistema visivo v2 "storybook acquerello"
   Coerente con le illustrazioni nano banana: carta calda, bordi morbidi,
   ombre sfumate, niente flat-sticker. Overflow orizzontale azzerato.
   ========================================================================= */

:root{
  --paper:      #f4ead4;
  --paper-2:    #ecdfc1;
  --card:       #fcf6e8;
  --card-2:     #f7eed8;
  --ink:        #3a3026;
  --ink-soft:   #7a6c56;
  --line:       #cdb68c;      /* bordo caldo sottile */
  --line-soft:  #e3d4af;

  --wood:       #a9783f;
  --wood-dark:  #6b4a24;
  --lavagna:    #35564a;
  --chalk:      #f6f1e3;

  --ochre:      #e0a233;
  --ochre-deep: #c5851d;
  --terra:      #cf5536;
  --terra-deep: #b8431f;
  --leaf:       #6e8f4e;
  --sky:        #5ba2b3;
  --plum:       #876089;

  --good:       #6e8f4e;
  --retry:      #d9842a;

  --sh-1: 0 2px 8px rgba(90,62,24,.10);
  --sh-2: 0 8px 22px rgba(90,62,24,.16);
  --sh-3: 0 18px 44px rgba(90,62,24,.22);
  --radius: 20px;
  --radius-lg: 30px;

  --font-disp: "Fraunces", Georgia, serif;
  --font-kid:  "Baloo 2", "Trebuchet MS", sans-serif;
}

/* ----------------------------------------------------- reset + overflow */
*,*::before,*::after{ box-sizing:border-box; }
*{ margin:0; padding:0; min-width:0; }            /* min-width:0 = niente blowout grid/flex */
html,body{ max-width:100%; overflow-x:hidden; }
html{ height:100%; }
body{
  min-height:100%;
  font-family:var(--font-kid);
  color:var(--ink);
  background:var(--paper);
  -webkit-font-smoothing:antialiased;
  text-rendering:optimizeLegibility;
  line-height:1.4;
}
img{ max-width:100%; display:block; }
button{ font-family:inherit; cursor:pointer; border:none; background:none; color:inherit; }
a{ color:inherit; }
:focus-visible{ outline:3px solid var(--ochre); outline-offset:3px; border-radius:8px; }

/* atmosfera carta */
body::before{
  content:""; position:fixed; inset:0; z-index:-2;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(255,231,176,.6), rgba(255,231,176,0) 55%),
    radial-gradient(circle at 14% 6%, rgba(255,255,255,.4), transparent 42%),
    linear-gradient(160deg, var(--paper) 0%, var(--paper-2) 60%, #e3d3ac 100%);
}
body::after{
  content:""; position:fixed; inset:0; z-index:-1; pointer-events:none; opacity:.45;
  background-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.05'/></svg>");
  mix-blend-mode:multiply;
}

/* ----------------------------------------------------------- layout */
#app{ position:relative; }
.view{ display:none; animation:fade .5s ease both; }
.view.active{ display:block; }
@keyframes fade{ from{opacity:0; transform:translateY(8px);} to{opacity:1; transform:none;} }
.wrap{ width:100%; max-width:1100px; margin:0 auto; padding:0 20px; }

/* ------------------------------------------------- chips parola (tap-to-hear) */
.word{
  font-family:var(--font-kid); font-weight:700;
  display:inline-flex; align-items:center; gap:.4em;
  background:var(--card); color:var(--ink);
  border:2px solid var(--wood); border-radius:14px;
  padding:.34em .72em; margin:.18em;
  letter-spacing:.01em; line-height:1.05; cursor:pointer;
  box-shadow:var(--sh-1); transition:transform .12s, box-shadow .12s, background .2s;
  text-transform:uppercase; max-width:100%;
}
.word:hover{ background:#fff8ea; transform:translateY(-1px); box-shadow:var(--sh-2); }
.word:active,.word.speaking{ transform:translateY(1px); background:var(--ochre); border-color:var(--ochre-deep); }
.word::before{ content:"🔊"; font-size:.66em; opacity:.5; }
.word.big{ font-size:clamp(18px,4.2vw,32px); }

/* --------------------------------------------------------------- bottoni */
.btn{
  font-family:var(--font-kid); font-weight:700; font-size:18px;
  display:inline-flex; align-items:center; gap:.5em; max-width:100%;
  padding:.62em 1.2em; border-radius:999px;
  background:var(--ochre); color:#43310c;
  border:2px solid var(--ochre-deep);
  box-shadow:var(--sh-2);
  transition:transform .12s, box-shadow .12s, filter .2s;
  text-transform:uppercase; letter-spacing:.02em;
}
.btn:hover{ filter:brightness(1.04); transform:translateY(-2px); box-shadow:var(--sh-3); }
.btn:active{ transform:translateY(1px); box-shadow:var(--sh-1); }
.btn.green{ background:var(--leaf); border-color:#577a3c; color:#fff; }
.btn.terra{ background:var(--terra); border-color:var(--terra-deep); color:#fff; }
.btn.lav{ background:var(--lavagna); border-color:#26433a; color:var(--chalk); }
.btn.ghost{ background:#fff8ea; border-color:var(--line); color:var(--ink-soft); box-shadow:var(--sh-1); }
.btn.small{ font-size:14px; padding:.46em .85em; }

/* =========================================================== VISTA: PORTA */
#view-door{ min-height:100vh; padding:36px 16px 0; position:relative; }
#view-door.active{ display:grid; place-items:center; }
.door-stage{ text-align:center; max-width:760px; position:relative; z-index:2; }
.door-kicker{
  font-family:var(--font-kid); font-weight:600; letter-spacing:.3em; text-transform:uppercase;
  color:var(--wood-dark); font-size:12px; margin-bottom:10px;
}
.door-title{
  font-family:var(--font-disp); font-weight:900; font-optical-sizing:auto;
  font-size:clamp(44px,11vw,104px); line-height:.92; color:var(--ink);
  letter-spacing:-.02em; text-shadow:0 2px 0 rgba(255,255,255,.5);
}
.door-title em{ font-style:italic; color:var(--terra); }
.door-sub{ font-family:var(--font-disp); font-style:italic; font-size:clamp(18px,3.4vw,26px); color:var(--ink-soft); margin-top:6px; }
.door-illustration{ margin:22px auto 6px; width:min(440px,86vw); }
.door-illustration img,.door-illustration svg{ width:100%; border-radius:var(--radius-lg); border:6px solid #fff; box-shadow:var(--sh-3); }
.door-cta{ margin-top:20px; display:flex; gap:12px; justify-content:center; flex-wrap:wrap; }
.bell{ font-size:1.2em; animation:swing 3.5s ease-in-out infinite; transform-origin:top center; display:inline-block; }
@keyframes swing{ 0%,70%,100%{transform:rotate(0)} 78%{transform:rotate(12deg)} 86%{transform:rotate(-9deg)} 93%{transform:rotate(4deg)} }

.grownups{
  margin:30px auto 40px; max-width:680px; background:var(--card);
  border:2px solid var(--line); border-radius:var(--radius); padding:16px 20px;
  box-shadow:var(--sh-2); text-align:left;
}
.grownups summary{ font-family:var(--font-disp); font-weight:700; font-size:18px; cursor:pointer; list-style:none; display:flex; align-items:center; gap:8px; color:var(--wood-dark); }
.grownups summary::-webkit-details-marker{ display:none; }
.grownups summary::before{ content:"📖"; }
.grownups .body{ margin-top:12px; color:var(--ink-soft); font-size:15px; line-height:1.6; }
.grownups .body strong{ color:var(--ink); }
.badge-law{ display:inline-block; margin-top:10px; font-size:12px; font-weight:600; background:var(--lavagna); color:var(--chalk); padding:5px 12px; border-radius:999px; }

/* ======================================================= VISTA: OFFICINA */
.topbar{
  position:sticky; top:0; z-index:30; display:flex; align-items:center; gap:12px;
  padding:10px 20px; background:rgba(244,234,212,.9); backdrop-filter:blur(8px);
  border-bottom:2px solid var(--line);
}
.topbar .home{ display:flex; align-items:center; gap:10px; font-family:var(--font-disp); font-weight:800; font-size:19px; color:var(--wood-dark); text-decoration:none; min-width:0; }
.topbar .home .av{ width:42px; height:42px; flex:0 0 auto; border-radius:50%; border:2px solid var(--wood); background:var(--ochre) center/cover; box-shadow:var(--sh-1); overflow:hidden; }
.topbar .home span:last-child{ overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.topbar .spacer{ flex:1; }

.officina-hero{ text-align:center; padding:34px 16px 6px; }
.officina-hero h1{ font-family:var(--font-disp); font-weight:900; font-size:clamp(30px,6vw,52px); letter-spacing:-.02em; }
.officina-hero p{ color:var(--ink-soft); font-family:var(--font-disp); font-style:italic; font-size:17px; margin-top:4px; }

.shelf{ display:grid; grid-template-columns:repeat(auto-fill,minmax(min(240px,100%),1fr)); gap:20px; padding:24px 0 70px; }
.obj{
  position:relative; display:flex; flex-direction:column; text-decoration:none; color:var(--ink);
  background:var(--card); border:2px solid var(--line); border-radius:var(--radius-lg);
  box-shadow:var(--sh-2); overflow:hidden; transition:transform .16s, box-shadow .16s;
}
.obj:hover{ transform:translateY(-5px); box-shadow:var(--sh-3); }
.obj:active{ transform:translateY(-1px); }
.obj .thumb{ position:relative; aspect-ratio:4/3; background:var(--card-2) center/cover; border-bottom:2px solid var(--line-soft); }
.obj .thumb img{ width:100%; height:100%; object-fit:cover; }
.obj .thumb::after{ content:""; position:absolute; inset:0; box-shadow:inset 0 -30px 40px -20px rgba(90,62,24,.25); }
.obj .num{
  position:absolute; top:12px; left:12px; width:36px; height:36px; border-radius:50%;
  background:var(--theme,var(--ochre)); color:#fff; border:2.5px solid #fff;
  font-weight:800; display:grid; place-items:center; font-size:17px; box-shadow:var(--sh-1); z-index:2;
}
.obj .month{ position:absolute; top:14px; right:14px; z-index:2; font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.12em; color:#fff; background:rgba(58,48,38,.55); padding:3px 9px; border-radius:999px; backdrop-filter:blur(2px); }
.obj .tag-new{ position:absolute; top:54px; right:-30px; transform:rotate(38deg); background:var(--terra); color:#fff; font-size:11px; font-weight:800; letter-spacing:.1em; padding:4px 36px; box-shadow:var(--sh-1); z-index:2; }
.obj .body{ padding:14px 16px 16px; flex:1 1 auto; }
.obj .label{ font-family:var(--font-disp); font-weight:800; font-size:21px; line-height:1.1; }
.obj .concept{ font-size:13px; color:var(--ink-soft); margin-top:5px; line-height:1.4; }
.obj .ribbon{ height:6px; background:var(--theme,var(--ochre)); }

/* ======================================================== VISTA: CAPITOLO */
.chap-hero{ position:relative; width:100%; height:clamp(190px,34vw,320px); overflow:hidden; border-bottom:3px solid var(--line); }
.chap-hero > img,.chap-hero > .heroimg{ position:absolute; inset:0; width:100%; height:100%; }
.chap-hero > img{ object-fit:cover; object-position:center 20%; }
.chap-hero > .heroimg svg{ width:100%; height:100%; object-fit:cover; }
.chap-hero .veil{ position:absolute; inset:0; background:linear-gradient(180deg, rgba(58,48,38,.05) 0%, rgba(58,48,38,.0) 30%, rgba(20,14,8,.55) 100%); }
.chap-hero .heroinner{ position:absolute; left:0; right:0; bottom:0; }
.chap-hero .crumbs{ display:flex; align-items:center; gap:8px; color:#fff; font-weight:600; font-size:13px; opacity:.92; }
.chap-hero .crumbs a{ color:#fff; text-decoration:none; }
.chap-hero h1{ font-family:var(--font-disp); font-weight:900; color:#fff; font-size:clamp(26px,5.4vw,46px); line-height:1.02; margin-top:4px; text-shadow:0 2px 12px rgba(0,0,0,.5); }
.chap-hero .pills{ display:flex; gap:8px; flex-wrap:wrap; align-items:center; margin-top:8px; }
.chap-hero .pill{ background:var(--theme,var(--ochre)); color:#fff; border-radius:999px; padding:4px 12px; font-weight:700; font-size:12px; box-shadow:var(--sh-1); }
.chap-concept{ background:var(--card); border-bottom:2px solid var(--line-soft); }
.chap-concept .wrap{ padding:12px 20px; }
.chap-concept p{ font-family:var(--font-disp); font-style:italic; font-size:15.5px; color:var(--ink-soft); max-width:760px; }

.chap-body{ padding:24px 0 80px; display:grid; grid-template-columns:minmax(0,1fr); gap:24px; }
.chap-body > *{ min-width:0; }

/* video card */
.video-card{ background:var(--card); border:2px solid var(--line); border-radius:var(--radius);
  box-shadow:var(--sh-2); padding:16px; display:grid; grid-template-columns:minmax(0,auto) minmax(0,1fr); gap:18px; align-items:center; }
.phone{ width:200px; max-width:46vw; aspect-ratio:9/16; border-radius:24px; border:5px solid var(--ink); background:#000; overflow:hidden; box-shadow:var(--sh-2); position:relative; flex:0 0 auto; }
.phone video{ width:100%; height:100%; object-fit:cover; }
.phone .ph-poster{ position:absolute; inset:0; background:center/cover; display:grid; place-items:center; }
.phone .ph-play{ width:58px; height:58px; border-radius:50%; background:rgba(255,255,255,.94); border:3px solid var(--ink); display:grid; place-items:center; font-size:24px; box-shadow:var(--sh-2); }
.video-card .vmeta{ min-width:0; }
.video-card .vmeta h3{ font-family:var(--font-disp); font-size:21px; }
.video-card .vmeta p{ color:var(--ink-soft); margin-top:6px; line-height:1.5; font-size:14.5px; }
.video-soon{ display:inline-block; margin-top:8px; background:var(--card-2); border:2px dashed var(--line); padding:6px 12px; border-radius:12px; font-size:13px; font-weight:700; color:var(--ink-soft); }

/* carosello tavole */
.spreads{ min-width:0; }
h2.sec{ font-family:var(--font-disp); font-weight:800; font-size:21px; margin-bottom:12px; display:flex; align-items:center; gap:9px; color:var(--wood-dark); }
.spread-track{ display:flex; flex-direction:column; align-items:center; gap:26px; padding:4px 0 8px; }
.spread{ width:100%; max-width:600px; background:var(--card); border:2px solid var(--line); border-radius:var(--radius); box-shadow:var(--sh-2); overflow:hidden; display:flex; flex-direction:column; }
.spread .scene{ aspect-ratio:1/1; background:var(--scene,#efe2c4); position:relative; border-bottom:2px solid var(--line-soft); }
.spread .scene svg,.spread .scene img{ width:100%; height:100%; object-fit:cover; display:block; }
.scene-img{ width:100%; height:100%; object-fit:cover; display:block; }
.spread .cap{ padding:13px 15px 15px; }
.spread .cap .pagenum{ font-size:11px; font-weight:700; letter-spacing:.14em; text-transform:uppercase; color:var(--ink-soft); }
.spread .cap .words{ margin-top:8px; display:flex; flex-wrap:wrap; }
.narr{ font-family:var(--font-disp); font-style:italic; font-size:15.5px; color:var(--ink); line-height:1.45; margin:4px 0 10px; cursor:pointer; padding-left:24px; position:relative; }
.narr::before{ content:"🔈"; position:absolute; left:0; top:1px; font-size:14px; opacity:.55; }
.narr:hover,.narr.speaking{ color:var(--terra); }
.spread.scheda .scene{ background:repeating-linear-gradient(135deg,#fff8ea,#fff8ea 16px,#f3e6c8 16px,#f3e6c8 18px); }
.spread .perf{ border-top:2px dashed var(--line); }

.cta-row{ display:flex; gap:12px; flex-wrap:wrap; align-items:center; }

/* ============================================================= GIOCHI */
.game-shell{ background:var(--card); border:2px solid var(--line); border-radius:var(--radius); box-shadow:var(--sh-2); padding:18px; min-width:0; }
.game-shell h2{ font-family:var(--font-disp); font-size:22px; display:flex; align-items:center; gap:9px; color:var(--wood-dark); }
.game-shell .hint{ color:var(--ink-soft); margin:6px 0 14px; font-size:15px; }
.game-stage{ display:grid; gap:14px; min-width:0; }
.game-stage > *{ min-width:0; max-width:100%; }
.game-toast{ min-height:28px; font-weight:800; font-size:19px; text-align:center; }
.game-toast.ok{ color:var(--good); } .game-toast.no{ color:var(--retry); }

.tile{ background:#fff8ea; border:2.5px solid var(--wood); border-radius:16px; box-shadow:var(--sh-1); display:grid; place-items:center; user-select:none; transition:transform .12s, box-shadow .12s; max-width:100%; }
.tile:hover{ box-shadow:var(--sh-2); }
.slot{ border:2.5px dashed var(--line); border-radius:16px; background:rgba(120,90,40,.04); display:grid; place-items:center; }
.slot.over{ border-color:var(--ochre); background:rgba(224,162,51,.12); }
.slot.filled{ border-style:solid; }
.pop{ animation:pop .35s cubic-bezier(.2,1.4,.4,1); }
@keyframes pop{ from{transform:scale(.6); opacity:0;} to{transform:none; opacity:1;} }
.shake{ animation:shake .4s; }
@keyframes shake{ 0%,100%{transform:translateX(0)} 20%{transform:translateX(-6px)} 40%{transform:translateX(6px)} 60%{transform:translateX(-4px)} 80%{transform:translateX(4px)} }
.confetti{ position:fixed; inset:0; pointer-events:none; z-index:60; }

.palette{ display:flex; gap:10px; flex-wrap:wrap; max-width:100%; }
.grid-board{ display:grid; gap:6px; background:var(--lavagna); padding:10px; border-radius:16px; border:2.5px solid var(--wood-dark); width:max-content; max-width:100%; margin:4px auto; }
.grid-cell{ background:#3c6155; border-radius:8px; aspect-ratio:1; display:grid; place-items:center; position:relative; }
.grid-cell.goal{ background:#46763f; }
.cmd-row{ display:flex; gap:8px; flex-wrap:wrap; min-height:60px; padding:10px; background:#fff8ea; border:2.5px dashed var(--wood); border-radius:14px; }
.cmd{ width:50px; height:50px; border-radius:13px; background:var(--ochre); border:2.5px solid var(--ochre-deep); box-shadow:var(--sh-1); font-size:24px; font-weight:800; display:grid; place-items:center; }
.runner{ font-size:30px; transition:all .35s cubic-bezier(.4,1.2,.5,1); }

/* ============================================================ FOOTER */
.foot{ border-top:3px solid var(--line); background:var(--lavagna); color:var(--chalk); padding:28px 0; margin-top:30px; }
.foot .wrap{ display:flex; flex-wrap:wrap; gap:16px; justify-content:space-between; align-items:center; }
.foot .brand{ font-family:var(--font-disp); font-weight:800; font-size:19px; }
.foot small{ opacity:.82; }

/* =========================================================== SFOGLIA (flipbook) */
#view-flipbook{ background:radial-gradient(125% 90% at 50% 0%, #f7e8c2, #e6d2a4 55%, #d3b885); min-height:100vh; }
.flip-head{ text-align:center; padding:24px 16px 4px; }
.flip-head h1{ font-family:var(--font-disp); font-weight:900; font-size:clamp(28px,5vw,46px); color:var(--wood-dark); }
.flip-head p{ font-family:var(--font-disp); font-style:italic; color:var(--ink-soft); margin-top:2px; }
.flip-stage{ display:flex; flex-direction:column; align-items:center; gap:18px; padding:18px 12px 56px; }
.flip-book-wrap{ width:min(94vw,1200px); }
#flipbook{ margin:0 auto; filter:drop-shadow(0 26px 42px rgba(50,30,8,.42)); }
#flipbook img{ display:block; }
.flip-nav{ display:flex; align-items:center; gap:18px; }
.flip-arrow{ width:54px; height:54px; border-radius:50%; background:var(--card); border:2px solid var(--wood); color:var(--wood-dark); font-size:30px; font-weight:800; line-height:1; display:grid; place-items:center; box-shadow:var(--sh-2); transition:transform .12s, box-shadow .12s; }
.flip-arrow:hover{ transform:translateY(-2px); box-shadow:var(--sh-3); }
.flip-arrow:active{ transform:translateY(1px); }
.flip-ind{ font-family:var(--font-kid); font-weight:700; color:var(--wood-dark); min-width:92px; text-align:center; background:rgba(252,246,232,.72); border-radius:999px; padding:6px 14px; border:2px solid var(--line); }
.flip-hint{ font-family:var(--font-disp); font-style:italic; color:var(--ink-soft); font-size:14px; }

/* utilities */
@media (max-width:620px){
  .video-card{ grid-template-columns:minmax(0,1fr); justify-items:center; text-align:center; }
  .phone{ max-width:60vw; }
  .topbar .home{ font-size:16px; }
}
.center{ text-align:center; }
.mt{ margin-top:16px; } .mt2{ margin-top:30px; }
.hidden{ display:none !important; }

/* ====== Sfogliatore: tasto schermo intero + stato fullscreen ====== */
.flip-fs{ align-self:flex-end; font-family:var(--font-kid); font-weight:700; cursor:pointer; color:var(--wood-dark);
  background:var(--card); border:2px solid var(--wood); border-radius:999px; padding:8px 18px;
  box-shadow:var(--sh-2); transition:transform .12s, box-shadow .12s; }
.flip-fs:hover{ transform:translateY(-2px); box-shadow:var(--sh-3); }
.flip-fs:active{ transform:translateY(1px); }
html.flip-fs-lock, html.flip-fs-lock body{ overflow:hidden; }
/* fallback CSS (browser senza Fullscreen API, es. iPhone) */
.flip-stage.pseudo-fs{ position:fixed; inset:0; z-index:9999; width:100vw; height:100vh; overflow:auto; margin:0;
  background:radial-gradient(125% 90% at 50% 0%, #f7e8c2, #e6d2a4 55%, #d3b885);
  justify-content:center; gap:12px; padding:14px 12px; box-sizing:border-box; }
.flip-stage.pseudo-fs .flip-book-wrap{ width:min(98vw, calc((100vh - 120px) * 2)); }
/* fullscreen nativo (standard + WebKit) */
.flip-stage:fullscreen{ position:relative; width:100vw; height:100vh; overflow:auto; box-sizing:border-box;
  background:radial-gradient(125% 90% at 50% 0%, #f7e8c2, #e6d2a4 55%, #d3b885);
  justify-content:center; gap:12px; padding:14px 12px; }
.flip-stage:fullscreen .flip-book-wrap{ width:min(98vw, calc((100vh - 120px) * 2)); }
.flip-stage:-webkit-full-screen{ position:relative; width:100vw; height:100vh; overflow:auto; box-sizing:border-box;
  background:radial-gradient(125% 90% at 50% 0%, #f7e8c2, #e6d2a4 55%, #d3b885);
  justify-content:center; gap:12px; padding:14px 12px; }
.flip-stage:-webkit-full-screen .flip-book-wrap{ width:min(98vw, calc((100vh - 120px) * 2)); }
/* nello stato a schermo intero il bottone galleggia in alto a destra (non ruba spazio al libro) */
.flip-stage.pseudo-fs .flip-fs, .flip-stage:fullscreen .flip-fs, .flip-stage:-webkit-full-screen .flip-fs{
  position:absolute; top:14px; right:18px; margin:0; z-index:6; }
