:root {
  --bg: #fff7ef;
  --bg-2: #ffe9d2;
  --card: #ffffff;
  --line: #ead9c8;
  --text: #2f221a;
  --muted: #7d6d62;
  --accent: #ff7a59;
  --accent-2: #ffb703;
  --sky: #65d3ff;
  --mint: #7ad66f;
  --pink: #ff82a9;
  --good: #2f9d62;
  --bad: #cf3f4f;
  --shadow: 0 14px 34px rgba(120, 73, 32, .14);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top right, rgba(255,184,107,.30), transparent 28%),
    radial-gradient(circle at bottom left, rgba(101,211,255,.18), transparent 28%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
  min-height: 100vh;
}
button { font: inherit; }
.sr-only { position:absolute!important; width:1px; height:1px; margin:-1px; padding:0; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }
.app-shell { width: min(1120px, calc(100% - 24px)); margin: 0 auto; padding: 24px 0 44px; }
.hero { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 22px; }
.hero-copy { max-width: 760px; }
.eyebrow { margin: 0 0 8px; color: #ca5f49; font-size: .78rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(2rem, 4vw, 3.4rem); line-height: 1.02; margin-bottom: 12px; }
.subtitle { margin: 0; color: var(--muted); font-size: 1.04rem; line-height: 1.6; }
.game-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 16px; }
.game-card, .game-area, .summary-card, .hud-card {
  background: rgba(255,255,255,.88);
  border: 1px solid rgba(234, 217, 200, .95);
  border-radius: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.game-card { padding: 24px; display: flex; flex-direction: column; gap: 14px; min-height: 280px; position: relative; overflow: hidden; }
.game-card::before {
  content: '';
  position: absolute;
  inset: auto -20% -20% auto;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  opacity: .35;
  pointer-events: none;
}
.game-card.memory::before { background: radial-gradient(circle, rgba(101,211,255,.35), transparent 65%); }
.game-card.bomb::before { background: radial-gradient(circle, rgba(255,122,89,.35), transparent 65%); }
.game-card.puzzle::before { background: radial-gradient(circle, rgba(122,214,111,.35), transparent 65%); }
.game-card .icon-bubble {
  width: 70px; height: 70px; border-radius: 22px; display: grid; place-items: center; font-size: 2rem; box-shadow: inset 0 1px 0 rgba(255,255,255,.8);
}
.game-card.memory .icon-bubble { background: linear-gradient(180deg, #d8f5ff, #b7e8ff); }
.game-card.bomb .icon-bubble { background: linear-gradient(180deg, #ffe0d7, #ffd0c0); }
.game-card.puzzle .icon-bubble { background: linear-gradient(180deg, #e1fadf, #c9f5c5); }
.game-card h3 { margin: 0; font-size: 1.35rem; }
.game-card p { margin: 0; line-height: 1.6; color: var(--muted); flex: 1; }
.feature-list { margin: 0; padding-left: 18px; color: var(--muted); display: grid; gap: 8px; font-size: .96rem; }
.game-history { padding: 8px 10px; border-radius: 12px; background: #fff7ed; color: #9a583f; font-size: .86rem; font-weight: 800; }
.pill-btn {
  min-height: 48px; border-radius: 16px; border: 0; cursor: pointer; font-weight: 900; letter-spacing: .01em;
  padding: 12px 18px; transition: transform .14s ease, box-shadow .14s ease, opacity .14s ease;
}
.pill-btn:hover, .pill-btn:focus-visible { transform: translateY(-1px); box-shadow: 0 10px 18px rgba(0,0,0,.08); outline: none; }
.pill-btn.primary { background: linear-gradient(180deg, #ff8d6d, var(--accent)); color: white; }
.pill-btn.secondary { background: white; color: var(--text); border: 1px solid var(--line); }
.play-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; }
.status-badges { display: flex; gap: 10px; flex-wrap: wrap; }
.status-badge {
  min-width: 88px; padding: 10px 14px; border-radius: 999px; background: linear-gradient(180deg, #fff0ea, #ffe3d7); color: #c15a42; font-weight: 900; text-align: center; border: 1px solid #ffd4c5;
}
.status-badge.soft { background: linear-gradient(180deg, #f6f7ff, #eeefff); color: #5960b5; border-color: #dce0ff; }
.game-area { padding: 22px; }
.feedback { min-height: 54px; padding: 12px 2px 0; font-weight: 800; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }
.hud-row { display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.hud-card { padding: 14px 16px; min-width: 130px; }
.hud-label { font-size: .78rem; text-transform: uppercase; color: var(--muted); letter-spacing: .06em; font-weight: 800; display: block; margin-bottom: 5px; }
.hud-value { font-size: 1.2rem; font-weight: 900; }
.jp, .kana-big { font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif; }

/* MEMORY */
.memory-board { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; }
.memory-card { perspective: 900px; min-width: 0; }
.memory-btn {
  width: 100%; aspect-ratio: 1 / 1; background: transparent; border: 0; padding: 0; cursor: pointer;
}
.memory-inner {
  display: block; position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .42s ease;
}
.memory-btn.flipped .memory-inner, .memory-btn.matched .memory-inner { transform: rotateY(180deg); }
.memory-face {
  position: absolute; inset: 0; backface-visibility: hidden; border-radius: 26px; border: 1px solid var(--line); overflow: hidden;
  box-shadow: var(--shadow); background: white; display: grid; place-items: center; padding: 12px; text-align: center;
}
.memory-back {
  background:
    linear-gradient(140deg, rgba(255,255,255,.88), rgba(255,255,255,.66)),
    radial-gradient(circle at top left, rgba(255,122,89,.24), transparent 24%),
    radial-gradient(circle at bottom right, rgba(101,211,255,.30), transparent 28%),
    linear-gradient(180deg, #fff4ea, #ffe6d5);
}
.memory-back .back-mark { font-size: 2rem; }
.memory-front { transform: rotateY(180deg); }
.memory-front.image-side { background: linear-gradient(180deg, #fffaf5, #fff0dd); }
.memory-front.word-side { background: linear-gradient(180deg, #f6fcff, #e8f7ff); }
.tile-emoji { font-size: clamp(2.4rem, 7vw, 3.2rem); line-height: 1; }
.tile-title { font-size: 1.34rem; font-weight: 900; }
.tile-kana { font-size: 1.18rem; color: #43607b; margin-top: 4px; }
.tile-sub { margin-top: 4px; font-size: .88rem; color: var(--muted); line-height: 1.35; }

/* BOMB */
.bomb-shell {
  display: grid; gap: 18px;
}
.bomb-strip {
  position: relative; min-height: 120px; padding: 18px 20px 18px 126px; border-radius: 26px; overflow: hidden;
  background: linear-gradient(180deg, #fff7f1, #ffe9dc); border: 1px solid #ffd7c6;
}
.bomb-icon {
  position: absolute; left: 18px; bottom: 14px; width: 84px; height: 84px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #505050, #1f1f1f 70%); box-shadow: inset -8px -10px 0 rgba(0,0,0,.18);
}
.bomb-icon::before {
  content: ''; position: absolute; top: -11px; left: 55px; width: 18px; height: 20px; border: 5px solid #74533a; border-bottom: 0; border-radius: 12px 12px 0 0; transform: rotate(14deg);
}
.fuse-track {
  position: absolute; left: 88px; right: 18px; top: 38px; height: 10px;
}
.fuse-bg {
  position: absolute; left: 0; top: 50%; transform: translateY(-50%); width: 100%; height: 7px; border-radius: 999px;
  background: linear-gradient(90deg, #8d8179, #aaa09a); transition: width .15s linear;
  box-shadow: inset 0 1px 1px rgba(255,255,255,.45);
}
.spark {
  position: absolute; top: 50%; transform: translate(-50%, -50%); width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.98) 0 12%, #ffd166 18%, #ff8d00 42%, rgba(255,141,0,0) 72%);
  filter: drop-shadow(0 0 7px rgba(255,164,0,.75)); transition: left .15s linear;
}
.spark::before, .spark::after {
  content: ''; position: absolute; inset: 11px; background: transparent; border-top: 3px solid #ffd166; border-radius: 999px;
}
.spark::before { transform: rotate(55deg); }
.spark::after { transform: rotate(-45deg); }
.bomb-copy { max-width: 610px; }
.bomb-copy h3 { margin: 0 0 8px; font-size: 1.25rem; }
.bomb-copy p { margin: 0; color: var(--muted); line-height: 1.55; }
.question-card { padding: 20px; border-radius: 24px; background: white; border: 1px solid var(--line); box-shadow: inset 0 1px 0 rgba(255,255,255,.8); }
.question-card h3 { margin: 0 0 10px; font-size: 1.35rem; line-height: 1.45; }
.choice-grid { display: grid; gap: 10px; }
.choice-btn {
  min-height: 56px; text-align: left; padding: 14px 16px; border-radius: 16px; border: 1px solid var(--line); background: white; cursor: pointer; font-weight: 800; color: var(--text);
}
.choice-btn:hover, .choice-btn:focus-visible { outline: none; border-color: #ffbb9d; background: #fff8f4; }
.choice-btn.correct { border-color: #84dcaa; background: #eefcf4; }
.choice-btn.wrong { border-color: #f4a0ad; background: #fff0f3; }
.helper-line { margin: 12px 0 0; color: var(--muted); font-size: .94rem; }

/* PUZZLE */
.puzzle-shell { display: grid; gap: 18px; }
.puzzle-stage {
  background: linear-gradient(180deg, #fff8f0, #fff1e3); border: 1px solid #f0dcc7; border-radius: 28px; padding: 22px;
}
.puzzle-top { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; margin-bottom: 20px; }
.puzzle-top p { margin: 0; color: var(--muted); }
.puzzle-arena { display: grid; gap: 28px; }
.puzzle-prompt-row { display: flex; justify-content: center; }
.puzzle-piece {
  min-height: 142px; display: flex; flex-direction: column; justify-content: center; padding: 20px;
  background: white; border: 1px solid #e6ddd4; box-shadow: 0 10px 22px rgba(88, 60, 39, .12); text-align: center;
  border-radius: 24px;
}
.puzzle-piece.left { width: min(320px, 100%); }
.puzzle-piece.right { width: 100%; }
.puzzle-piece .tiny { font-size: .82rem; color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.puzzle-piece.left .kana-big { font-size: clamp(3.2rem, 8vw, 4.4rem); font-weight: 900; line-height: 1; }
.puzzle-piece.right .tile-emoji { font-size: clamp(3.1rem, 8vw, 4rem); }
.puzzle-piece.right .tile-sub { font-size: .95rem; }
.choice-pieces { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 22px; }
.piece-btn { background: transparent; border: 0; padding: 0; cursor: pointer; }
.piece-btn .puzzle-piece { transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease, background .16s ease; }
.piece-btn:hover .puzzle-piece, .piece-btn:focus-visible .puzzle-piece { transform: translateY(-2px); border-color: #ffbb9d; outline: none; }
.piece-btn.correct .puzzle-piece { border-color: #8fd9aa; background: #f2fff7; }
.piece-btn.wrong .puzzle-piece { border-color: #f5a6b1; background: #fff3f5; }
.puzzle-joined { display: grid; gap: 16px; justify-items: center; }
.puzzle-joined .puzzle-piece { width: min(320px, 100%); }
.puzzle-note { margin-top: 20px; padding: 14px 16px; border-radius: 18px; background: rgba(255,255,255,.84); border: 1px solid var(--line); }
.puzzle-note h4 { margin: 0 0 8px; font-size: 1.02rem; }
.puzzle-note p { margin: 0; color: var(--muted); }

.summary-card { text-align: center; padding: 28px 22px; }
.summary-card .big-score { font-size: clamp(2.2rem, 6vw, 3.8rem); font-weight: 1000; margin: 8px 0; }
.summary-card p { color: var(--muted); line-height: 1.6; }
.summary-card .action-row { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; margin-top: 20px; }
.summary-card ul { list-style: none; padding: 0; margin: 18px 0 0; display: grid; gap: 8px; color: var(--muted); }
.summary-card li strong { color: var(--text); }

@media (max-width: 860px) {
  .game-grid { grid-template-columns: 1fr; }
  .memory-board { grid-template-columns: repeat(3, minmax(0,1fr)); }
}
@media (max-width: 640px) {
  .app-shell { width: min(100% - 16px, 1120px); padding-top: 18px; }
  .hero, .play-header, .puzzle-top { flex-direction: column; align-items: stretch; }
  .status-badges { justify-content: flex-start; }
  .memory-board { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
  .game-area { padding: 16px; }
  .bomb-strip { padding-left: 104px; }
  .bomb-icon { left: 14px; width: 72px; height: 72px; }
  .fuse-track { left: 76px; }
  .choice-pieces { grid-template-columns: 1fr; gap: 14px; }
  .puzzle-piece { min-height: 118px; }
}


/* Memory: immagine grande, parola solo in giapponese */
.memory-front.image-side { padding: 8px; }
.memory-front.word-side { padding: 14px; }
.memory-image { font-size: clamp(4.3rem, 10vw, 6.4rem); line-height: 1; }
.memory-kanji { font-size: clamp(2.3rem, 6vw, 3.8rem); line-height: 1.05; }
.memory-kana { font-size: clamp(1.15rem, 3vw, 1.55rem); margin-top: 10px; color: #526a80; font-weight: 800; }

/* Puzzle: incastro maschio/femmina pulito. Il colore del foro coincide con lo sfondo dello stage. */
.puzzle-stage { --puzzle-stage-bg: #fff4e8; background: var(--puzzle-stage-bg); }
.puzzle-piece.left,
.puzzle-piece.right {
  clip-path: none;
  overflow: visible;
  border-radius: 22px;
}
.puzzle-piece.left { padding-right: 30px; border-radius: 22px 12px 12px 22px; }
.puzzle-piece.right { padding-left: 30px; border-radius: 12px 22px 22px 12px; }
.piece-btn.correct .piece-btn.wrong /* v4 · Retro Memory più leggibile, stile carta da gioco */
.memory-back {
  border: 3px solid rgba(255,255,255,.92);
  outline: 2px solid #315b91;
  outline-offset: -7px;
  background:
    radial-gradient(circle at 25% 25%, rgba(255,255,255,.18) 0 3px, transparent 4px),
    radial-gradient(circle at 75% 75%, rgba(255,255,255,.18) 0 3px, transparent 4px),
    repeating-linear-gradient(45deg, rgba(255,255,255,.10) 0 8px, rgba(255,255,255,0) 8px 16px),
    repeating-linear-gradient(-45deg, rgba(255,255,255,.08) 0 8px, rgba(255,255,255,0) 8px 16px),
    linear-gradient(135deg, #244c8d 0%, #4a63b8 38%, #cf477a 72%, #f28b48 100%);
}
.memory-back::before {
  content: '';
  position: absolute;
  inset: 14px;
  border: 2px solid rgba(255,255,255,.72);
  border-radius: 18px;
  box-shadow: inset 0 0 0 5px rgba(255,255,255,.08);
}
.memory-back::after {
  content: '';
  position: absolute;
  width: 58%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.82);
  background:
    radial-gradient(circle, rgba(255,255,255,.17) 0 34%, transparent 35%),
    conic-gradient(from 45deg, rgba(255,255,255,.22), transparent 25%, rgba(255,255,255,.22) 50%, transparent 75%, rgba(255,255,255,.22));
  box-shadow: 0 0 0 5px rgba(255,255,255,.08);
}
.memory-back .back-mark {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 48%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(32,42,93,.58);
  color: white;
  border: 2px solid rgba(255,255,255,.88);
  font-size: clamp(2rem, 5vw, 3.15rem);
  font-weight: 900;
  text-shadow: 0 2px 0 rgba(0,0,0,.18);
  box-shadow: inset 0 0 0 5px rgba(255,255,255,.10), 0 8px 18px rgba(24,36,83,.26);
}

/* v4 · Puzzle verticale: hiragana sopra, tre immagini sotto */
.puzzle-arena {
  display: grid;
  grid-template-columns: 1fr;
  gap: 40px;
  align-items: start;
  justify-items: center;
  padding: 12px 0 8px;
}
.puzzle-arena > .puzzle-piece.left {
  width: min(280px, 78%);
  min-height: 150px;
}
.choice-pieces {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 28px;
  align-items: stretch;
}
/* v6 · Schede rettangolari pure: nessun pseudo-elemento puzzle */
.puzzle-piece.left,
.puzzle-piece.right {
  border-radius: 22px;
  padding: 20px;
  overflow: hidden;
}
.puzzle-piece.left { padding: 20px; }
.puzzle-piece.right { padding: 20px; min-height: 150px; }
.puzzle-arena {
  display: grid;
  grid-template-columns: 1fr;
  gap: 30px;
  justify-items: center;
  padding: 8px 0;
}
.puzzle-arena > .puzzle-piece.left { width: min(300px, 82%); min-height: 140px; }
.choice-pieces { width: 100%; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 24px; }
@media (max-width:640px){
  .choice-pieces{grid-template-columns:1fr;gap:14px;}
  .puzzle-arena > .puzzle-piece.left{width:min(260px,92%);}
}

/* Trova l'intruso */
.game-card.intruder::before { background: radial-gradient(circle, rgba(255,130,169,.34), transparent 65%); }
.game-card.intruder .icon-bubble { background: linear-gradient(180deg, #ffe2ec, #ffcddd); }
.intruder-shell { display: grid; gap: 22px; }
.intruder-stage {
  background: linear-gradient(180deg, #fff8f5, #fff0f4);
  border: 1px solid #efd9e2;
  border-radius: 28px;
  padding: 22px;
}
.intruder-prompt { display: grid; justify-items: center; gap: 10px; margin-bottom: 24px; text-align: center; }
.intruder-initial {
  width: min(300px, 82%);
  min-height: 140px;
  display: grid; place-items: center;
  border-radius: 24px;
  background: white;
  border: 1px solid #e6ddd4;
  box-shadow: 0 10px 22px rgba(88,60,39,.10);
  font-size: clamp(3.4rem, 9vw, 5rem);
  font-weight: 900;
}
.intruder-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 18px; }
.intruder-btn { border: 0; background: transparent; padding: 0; cursor: pointer; }
.intruder-card {
  min-height: 152px;
  border-radius: 22px;
  border: 1px solid #e7dce2;
  background: white;
  display: grid;
  place-items: center;
  padding: 14px;
  box-shadow: 0 10px 20px rgba(88,60,39,.09);
  transition: transform .15s ease,border-color .15s ease,background .15s ease;
}
.intruder-card .tile-emoji { font-size: clamp(3rem,8vw,4.2rem); }
.intruder-label {
  display: grid;
  gap: 2px;
  margin-top: 12px;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .18s ease, transform .18s ease;
  pointer-events: none;
}
.show-intruder-labels .intruder-label { opacity: 1; transform: translateY(0); }
.intruder-word { font-size: 1.18rem; font-weight: 900; line-height: 1.2; color: var(--text); }
.intruder-kana { font-size: .94rem; font-weight: 800; line-height: 1.2; color: var(--muted); }
.intruder-btn:hover .intruder-card, .intruder-btn:focus-visible .intruder-card { transform: translateY(-2px); border-color: #f29ab6; outline: none; }
.intruder-btn.correct .intruder-card { border-color: #8fd9aa; background: #f2fff7; }
.intruder-btn.wrong .intruder-card { border-color: #f5a6b1; background: #fff3f5; }
.intruder-explain { margin-top: 18px; padding: 14px 16px; border-radius: 18px; background: white; border: 1px solid var(--line); color: var(--muted); }
@media (max-width:700px){ .intruder-grid{grid-template-columns:repeat(2,minmax(0,1fr));} }
