/* ═══════════════════════════════════════════════════════════════
   games.css — Stili condivisi per hub giochi + componenti UI
   Usa var(--ps-*) e var(--td-*) per rispettare temi e custom
   ═══════════════════════════════════════════════════════════════ */

/* ── Hub giochi ── */
.game-hub-header {
  text-align: center;
  padding: var(--ps-header-pad-top, 48px) var(--ps-wrapper-home, 24px) var(--ps-header-pad-bottom, 32px);
}
.game-hub-title {
  font-family: var(--ps-font-display, 'Playfair Display', serif);
  font-size: 28px;
  font-weight: 700;
  color: var(--ink, #0f0e17);
  margin: 0 0 8px;
}
.game-hub-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 12px;
  font-size: 14px;
  color: rgba(15,14,23,.6);
}
.game-hub-level {
  font-weight: 700;
  color: var(--accent, #c8533a);
}
.game-hub-xp-bar {
  width: 120px;
  height: 6px;
  background: rgba(15,14,23,.08);
  border-radius: 3px;
  overflow: hidden;
}
.game-hub-xp-fill {
  height: 100%;
  background: var(--accent, #c8533a);
  border-radius: 3px;
  transition: width .3s ease;
}

/* ── Card gioco (hub) ── */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--ps-card-gap, 16px);
  margin-bottom: 32px;
}
.game-card {
  display: flex;
  flex-direction: column;
  padding: var(--ps-card-body-pad, 28px);
  background: var(--ps-bg-card, var(--card-bg, #fff));
  border-radius: var(--ps-radius-card, 20px);
  border: var(--ps-border-card, none);
  box-shadow: var(--td-shadow, 0 6px 24px rgba(15,14,23,.08));
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  text-decoration: none;
  color: inherit;
}
.game-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--td-shadow-hover, 0 8px 32px rgba(15,14,23,.12));
}
.game-card.disabled {
  opacity: .4;
  pointer-events: none;
}
.game-card-icon {
  font-size: 36px;
  margin-bottom: 8px;
}
.game-card-name {
  font-family: var(--ps-font-display, 'Playfair Display', serif);
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 4px;
}
.game-card-desc {
  font-size: 13px;
  color: rgba(15,14,23,.5);
  margin: 0 0 12px;
}
.game-card-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: rgba(15,14,23,.45);
  margin-top: auto;
}
.game-card-stars { letter-spacing: 2px; }
.game-card-best { font-weight: 600; }

/* ── Card giochi in home (hub link) ── */
.game-hub-card {
  background: linear-gradient(135deg, rgba(200,83,58,.08), rgba(90,156,197,.08));
  border: 1px solid rgba(200,83,58,.15);
}
.game-hub-card:hover {
  border-color: rgba(200,83,58,.3);
}

/* ── Game play header ── */
.game-play-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px var(--ps-wrapper-quiz, 20px);
  gap: 12px;
  flex-wrap: wrap;
}
.game-play-header > * { flex-shrink: 0; }

/* ── Game area ── */
.game-area {
  padding: 16px var(--ps-wrapper-quiz, 20px);
  min-height: 300px;
}

/* ── Game result overlay ── */
.game-result-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 800;
  align-items: center;
  justify-content: center;
}
.game-result-overlay.show { display: flex; }

/* ── GameUI components ── */

/* Timer */
.gu-timer {
  position: relative;
  height: 6px;
  background: rgba(15,14,23,.08);
  border-radius: 3px;
  overflow: hidden;
  flex: 1;
  min-width: 80px;
}
.gu-timer-fill {
  height: 100%;
  background: var(--accent, #c8533a);
  border-radius: 3px;
  transition: width .15s linear;
}
.gu-timer-fill.gu-timer-danger { background: #e74c3c; }
.gu-timer-text {
  position: absolute;
  right: 0;
  top: -18px;
  font-size: 12px;
  font-weight: 600;
  color: rgba(15,14,23,.6);
}

/* Score */
.gu-score {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.gu-score-label { font-size: 11px; color: rgba(15,14,23,.4); text-transform: uppercase; letter-spacing: 1px; }
.gu-score-val { font-size: 20px; font-weight: 700; color: var(--ink, #0f0e17); }

/* Lives */
.gu-lives { display: flex; gap: 4px; font-size: 20px; }
.gu-heart-empty { opacity: .3; }

/* Combo */
.gu-combo-val {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent, #c8533a);
  transition: transform .15s;
}
.gu-combo-active { display: inline-block; }
.gu-combo-pop { animation: gu-pop .3s ease; }
@keyframes gu-pop { 0% { transform: scale(1); } 50% { transform: scale(1.4); } 100% { transform: scale(1); } }

/* Stars */
.gu-stars { display: flex; gap: 4px; font-size: 24px; }
.gu-star-big { font-size: 40px; }
.gu-star-empty { opacity: .3; }

/* Result screen */
.gu-result {
  background: var(--ps-bg-card, var(--card-bg, #fff));
  border-radius: var(--ps-radius-card, 20px);
  padding: 32px 28px;
  text-align: center;
  max-width: 460px;
  width: 90%;
  box-shadow: 0 16px 48px rgba(0,0,0,.2);
}
@media (min-width: 600px) {
  .gu-result { max-width: 520px; padding: 40px 36px; }
  .gu-result-btns { flex-direction: row; justify-content: center; }
  .gu-result-btns .gu-btn { width: auto; min-width: 140px; }
}
.gu-result-stars { margin-bottom: 16px; }
.gu-result-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: rgba(15,14,23,.4); margin-bottom: 4px; }
.gu-result-score { font-size: 48px; font-weight: 800; color: var(--ink, #0f0e17); margin-bottom: 8px; }
.gu-result-xp { font-size: 18px; font-weight: 600; color: var(--accent, #c8533a); margin-bottom: 16px; }
.gu-result-stats { display: flex; justify-content: center; gap: 16px; margin-bottom: 20px; font-size: 14px; }
.gu-rs-item { white-space: nowrap; }
.gu-result-badges { margin-bottom: 20px; }
.gu-result-badge-title { font-size: 14px; font-weight: 600; color: var(--accent, #c8533a); margin-bottom: 8px; }
.gu-result-badge { display: inline-block; padding: 4px 12px; background: rgba(200,83,58,.08); border-radius: 20px; font-size: 13px; margin: 2px; }
.gu-result-btns { display: flex; flex-direction: column; gap: 8px; }

/* Buttons */
.gu-btn {
  display: block;
  width: 100%;
  padding: 12px 20px;
  border: none;
  border-radius: var(--ps-radius-btn, 10px);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .1s, opacity .1s;
}
.gu-btn:active { transform: scale(.97); }
.gu-btn-primary { background: var(--accent, #c8533a); color: #fff; }
.gu-btn-accent { background: var(--accent2, #5a9cc5); color: #fff; }
.gu-btn-ghost { background: transparent; color: var(--ink, #0f0e17); border: 1px solid rgba(15,14,23,.15); }

/* Animations */
@keyframes gu-correct-pulse { 0% { box-shadow: 0 0 0 0 rgba(39,174,96,.4); } 100% { box-shadow: 0 0 0 12px rgba(39,174,96,0); } }
@keyframes gu-wrong-shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-6px); } 40%,80% { transform: translateX(6px); } }
.gu-anim-correct { animation: gu-correct-pulse .5s ease; }
.gu-anim-wrong { animation: gu-wrong-shake .4s ease; }

/* Toast */
.gu-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(15,14,23,.85);
  color: #fff;
  padding: 10px 24px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  z-index: 900;
  opacity: 0;
  transition: opacity .3s, transform .3s;
  pointer-events: none;
}
.gu-toast-show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Flip Card ── */
.flip-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-width: 480px;
  margin: 0 auto;
}
@media (max-width: 400px) { .flip-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; } }
@media (min-width: 600px) { .flip-grid.flip-6 { grid-template-columns: repeat(4, 1fr); } .flip-grid.flip-8 { grid-template-columns: repeat(4, 1fr); } }

.flip-card {
  perspective: 600px;
  cursor: pointer;
  aspect-ratio: 3/4;
}
.flip-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform .4s ease;
}
.flip-card.flipped .flip-inner { transform: rotateY(180deg); }
.flip-front, .flip-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--ps-radius-sm, 6px);
  font-size: 14px;
  font-weight: 600;
  padding: 8px;
  text-align: center;
  word-break: break-word;
}
.flip-front {
  background: var(--accent, #c8533a);
  color: #fff;
  font-size: 24px;
}
.flip-back {
  background: var(--ps-bg-card, var(--card-bg, #fff));
  color: var(--ink, #0f0e17);
  border: 2px solid rgba(15,14,23,.1);
  transform: rotateY(180deg);
}
.flip-card.matched .flip-back { border-color: #27ae60; background: rgba(39,174,96,.08); }
.flip-card.matched { pointer-events: none; }
.flip-card.wrong .flip-inner { animation: gu-wrong-shake .4s ease; }
.flip-card.locked { pointer-events: none; }

/* ── Speed Quiz ── */
.sq-question {
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  padding: 24px 16px;
  color: var(--ink, #0f0e17);
}
.sq-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 400px;
  margin: 0 auto;
}
.sq-choice {
  display: block;
  width: 100%;
  padding: 14px 20px;
  border: 2px solid rgba(15,14,23,.1);
  border-radius: var(--ps-radius-btn, 10px);
  background: var(--ps-bg-card, var(--card-bg, #fff));
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  color: var(--ink, #0f0e17);
  transition: border-color .15s, background .15s;
}
.sq-choice:active { transform: scale(.98); }
.sq-choice.correct { border-color: #27ae60; background: rgba(39,174,96,.1); }
.sq-choice.wrong { border-color: #e74c3c; background: rgba(231,76,60,.08); }
.sq-choice.reveal { border-color: #27ae60; opacity: .6; }
.sq-timer-bar {
  height: 4px;
  background: rgba(15,14,23,.06);
  border-radius: 2px;
  margin: 0 auto 16px;
  max-width: 400px;
  overflow: hidden;
}
.sq-timer-fill {
  height: 100%;
  background: var(--accent, #c8533a);
  border-radius: 2px;
}
.sq-progress {
  text-align: center;
  font-size: 12px;
  color: rgba(15,14,23,.4);
  margin-bottom: 8px;
}

/* ── Word Scramble ── */
.ws-hint {
  text-align: center;
  font-size: 16px;
  color: rgba(15,14,23,.5);
  margin-bottom: 20px;
  font-style: italic;
}
.ws-letters, .ws-slots {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.ws-letter, .ws-slot {
  width: 40px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  border-radius: var(--ps-radius-sm, 6px);
  cursor: pointer;
  transition: transform .15s, background .15s;
  user-select: none;
  -webkit-user-select: none;
}
.ws-letter {
  background: var(--accent, #c8533a);
  color: #fff;
}
.ws-letter:active { transform: scale(.9); }
.ws-letter.placed { opacity: .2; pointer-events: none; }
.ws-letter.dragging { opacity: .7; transform: scale(1.1); z-index: 10; }
.ws-slot {
  background: rgba(15,14,23,.04);
  border: 2px dashed rgba(15,14,23,.15);
  color: var(--ink, #0f0e17);
}
.ws-slot.filled { border-style: solid; border-color: rgba(15,14,23,.2); background: rgba(15,14,23,.06); }
.ws-slot.correct { border-color: #27ae60; background: rgba(39,174,96,.08); }
.word-complete { animation: gu-correct-pulse .6s ease; }

/* ── Word Fall ── */
.wf-area {
  position: relative;
  height: 350px;
  overflow: hidden;
  border-radius: var(--ps-radius-card, 20px);
  background: rgba(15,14,23,.02);
  margin-bottom: 12px;
}
.wf-word {
  position: absolute;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink, #0f0e17);
  background: var(--ps-bg-card, var(--card-bg, #fff));
  padding: 6px 14px;
  border-radius: var(--ps-radius-sm, 6px);
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
  white-space: nowrap;
  will-change: transform;
}
@keyframes fall {
  from { transform: translateY(0); }
  to   { transform: translateY(calc(350px - 40px)); }
}
.wf-word.falling { animation: fall linear forwards; }
.wf-word.caught {
  color: #27ae60;
  animation: gu-correct-pulse .4s ease;
  opacity: 0;
  transition: opacity .3s;
}
.wf-word.missed {
  color: #e74c3c;
  animation: gu-wrong-shake .3s ease;
  opacity: 0;
  transition: opacity .3s;
}
.wf-danger-line {
  position: absolute;
  bottom: 40px;
  left: 10%;
  right: 10%;
  border-top: 2px dashed rgba(231,76,60,.3);
}
.wf-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
  max-width: 400px;
  margin: 0 auto;
}
.wf-input {
  flex: 1;
  padding: 10px 16px;
  border: 2px solid rgba(15,14,23,.12);
  border-radius: var(--ps-radius-input, 8px);
  font-size: 16px;
  outline: none;
  background: var(--ps-bg-card, var(--card-bg, #fff));
  color: var(--ink, #0f0e17);
}
.wf-input:focus { border-color: var(--accent, #c8533a); }

/* ── Word Grid ── */
.wg-container {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: center;
}
.wg-grid {
  display: grid;
  gap: 1px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background: rgba(15,14,23,.06);
  border-radius: var(--ps-radius-sm, 6px);
  overflow: hidden;
}
.wg-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  font-size: 14px;
  font-weight: 600;
  font-family: 'Courier New', monospace;
  background: var(--ps-bg-card, var(--card-bg, #fff));
  color: var(--ink, #0f0e17);
  cursor: pointer;
  transition: background .1s;
}
@media (max-width: 400px) { .wg-cell { width: 26px; height: 26px; font-size: 12px; } }
.wg-cell.selecting { background: rgba(200,83,58,.2); }
.wg-cell.found-0 { background: rgba(200,83,58,.2); color: #c8533a; }
.wg-cell.found-1 { background: rgba(90,156,197,.2); color: #5a9cc5; }
.wg-cell.found-2 { background: rgba(39,174,96,.2); color: #27ae60; }
.wg-cell.found-3 { background: rgba(155,89,182,.2); color: #9b59b6; }
.wg-cell.found-4 { background: rgba(243,156,18,.2); color: #f39c12; }
.wg-cell.found-5 { background: rgba(26,188,156,.2); color: #1abc9c; }
.wg-cell.found-6 { background: rgba(231,76,60,.2); color: #e74c3c; }
.wg-cell.found-7 { background: rgba(52,73,94,.2); color: #34495e; }

.wg-wordlist {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 120px;
}
.wg-word {
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 4px;
  background: rgba(15,14,23,.03);
}
.wg-word.found {
  text-decoration: line-through;
  opacity: .4;
}

/* ── Back button ── */
.game-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--ps-radius-btn, 10px);
  background: rgba(15,14,23,.05);
  color: var(--ink, #0f0e17);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s;
}
.game-back-btn:hover { background: rgba(15,14,23,.1); }

/* ── Dark mode ── */
body.dark .game-card { background: var(--ps-bg-card, #1e1e2e); color: #e0e0e0; border-color: rgba(255,255,255,.06); }
body.dark .game-card:hover { box-shadow: 0 8px 32px rgba(0,0,0,.3); }
body.dark .game-hub-title { color: #e0e0e0; }
body.dark .game-hub-stats { color: rgba(255,255,255,.5); }
body.dark .game-hub-xp-bar { background: rgba(255,255,255,.08); }
body.dark .game-card-name { color: #e0e0e0; }
body.dark .game-card-desc { color: rgba(255,255,255,.4); }
body.dark .game-card-meta { color: rgba(255,255,255,.35); }
body.dark .gu-timer { background: rgba(255,255,255,.08); }
body.dark .gu-timer-text { color: rgba(255,255,255,.5); }
body.dark .gu-score-label { color: rgba(255,255,255,.35); }
body.dark .gu-score-val { color: #e0e0e0; }
body.dark .gu-result { background: #1e1e2e; }
body.dark .gu-result-score { color: #e0e0e0; }
body.dark .gu-result-label { color: rgba(255,255,255,.4); }
body.dark .gu-result-stats { color: rgba(255,255,255,.6); }
body.dark .gu-btn-ghost { color: #e0e0e0; border-color: rgba(255,255,255,.15); }
body.dark .flip-front { background: var(--accent, #c8533a); }
body.dark .flip-back { background: #1e1e2e; color: #e0e0e0; border-color: rgba(255,255,255,.1); }
body.dark .sq-question { color: #e0e0e0; }
body.dark .sq-choice { background: #1e1e2e; color: #e0e0e0; border-color: rgba(255,255,255,.1); }
body.dark .wf-area { background: rgba(255,255,255,.02); }
body.dark .wf-word { background: #1e1e2e; color: #e0e0e0; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
body.dark .wf-input { background: #1e1e2e; color: #e0e0e0; border-color: rgba(255,255,255,.12); }
body.dark .wg-grid { background: rgba(255,255,255,.04); }
body.dark .wg-cell { background: #1e1e2e; color: #e0e0e0; }
body.dark .wg-word { background: rgba(255,255,255,.04); color: #e0e0e0; }
body.dark .ws-letter { background: var(--accent, #c8533a); }
body.dark .ws-slot { background: rgba(255,255,255,.04); border-color: rgba(255,255,255,.12); color: #e0e0e0; }
body.dark .ws-hint { color: rgba(255,255,255,.45); }
body.dark .game-back-btn { background: rgba(255,255,255,.06); color: #e0e0e0; }
body.dark .game-back-btn:hover { background: rgba(255,255,255,.1); }
body.dark .gu-toast { background: rgba(255,255,255,.9); color: #0f0e17; }
