/* ============================================================
   PATTERN MASTER — Layout pattern visivi
   ============================================================ */

:root {
  --pm-bg-1: #12071f;
  --pm-bg-2: #1f0a3a;
  --pm-bg-3: #0a1830;
  --pm-accent: #a855f7;
  --pm-accent-2: #ffd23f;
  --pm-green: #4ade80;
  --pm-red: #ef476f;
  --pm-text: #f5eaff;
  --pm-text-dim: rgba(245, 234, 255, 0.65);
  --pm-text-mute: rgba(245, 234, 255, 0.35);
  --pm-glass: rgba(255, 255, 255, 0.05);
  --pm-glass-border: rgba(255, 255, 255, 0.12);
  --pm-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  --pm-font: 'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
  --pm-mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100vh;
  font-family: var(--pm-font);
  color: var(--pm-text);
  background:
    radial-gradient(ellipse at 20% 10%, rgba(168, 85, 247, 0.25) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(255, 210, 63, 0.12) 0%, transparent 50%),
    linear-gradient(135deg, var(--pm-bg-1), var(--pm-bg-2) 50%, var(--pm-bg-3));
  background-attachment: fixed;
  overflow-x: hidden;
}

.pm-wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

/* ─── HEADER ─── */
.pm-header {
  text-align: center;
  margin-bottom: 1.8rem;
  animation: pmFadeDown 0.7s ease-out;
}
@keyframes pmFadeDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

.pm-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(168, 85, 247, 0.15);
  border: 1px solid rgba(168, 85, 247, 0.4);
  padding: 0.4rem 1rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #d8b4fe;
  margin-bottom: 1rem;
  box-shadow: 0 0 20px rgba(168, 85, 247, 0.3);
  font-family: var(--pm-mono);
}

.pm-header h1 {
  font-size: clamp(1.7rem, 5vw, 2.6rem);
  font-weight: 700;
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #fff 0%, #d8b4fe 50%, #ffd23f 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.15;
}

.pm-header p {
  font-size: 1rem;
  color: var(--pm-text-dim);
  max-width: 500px;
  margin: 0 auto;
}

/* ─── SETUP ─── */
.pm-setup {
  background: var(--pm-glass);
  border: 1px solid var(--pm-glass-border);
  border-radius: 20px;
  padding: 2rem;
  max-width: 520px;
  margin: 2rem auto;
  backdrop-filter: blur(15px);
  box-shadow: var(--pm-shadow);
  text-align: center;
  animation: pmFadeDown 1s ease-out 0.1s both;
}

.pm-setup h2 {
  font-family: var(--pm-mono);
  font-size: 1.15rem;
  color: var(--pm-accent-2);
  margin-bottom: 1.2rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.pm-setup-info {
  background: rgba(255, 210, 63, 0.06);
  border: 1px solid rgba(255, 210, 63, 0.2);
  border-radius: 12px;
  padding: 1rem 1.2rem;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--pm-text-dim);
  text-align: left;
}
.pm-setup-info strong {
  color: var(--pm-accent-2);
  font-family: var(--pm-mono);
}

.pm-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.9rem 1.8rem;
  border-radius: 12px;
  border: 2px solid transparent;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  letter-spacing: 0.02em;
}

.pm-btn-main {
  background: linear-gradient(135deg, var(--pm-accent), var(--pm-accent-2));
  color: #12071f;
  padding: 1rem 2rem;
  font-size: 1.05rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  box-shadow: 0 8px 30px rgba(168, 85, 247, 0.4);
  width: 100%;
}
.pm-btn-main:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(168, 85, 247, 0.6);
}

/* ─── GIOCO ─── */
.pm-game {
  animation: pmFadeIn 0.5s ease-out;
}
@keyframes pmFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.pm-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.pm-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(168, 85, 247, 0.15);
  border: 1px solid rgba(168, 85, 247, 0.4);
  padding: 0.4rem 1rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #d8b4fe;
  font-family: var(--pm-mono);
}

.pm-status-dots {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}
.pm-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  transition: all 0.3s ease;
}
.pm-dot.is-current {
  background: var(--pm-accent-2);
  box-shadow: 0 0 12px var(--pm-accent-2);
  transform: scale(1.3);
}
.pm-dot.is-done {
  background: var(--pm-green);
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.6);
}
.pm-dot.is-wrong {
  background: var(--pm-red);
  box-shadow: 0 0 8px rgba(239, 71, 111, 0.6);
}

/* Timer */
.pm-timer {
  position: relative;
  width: 76px;
  height: 76px;
  margin-left: auto;
}
.pm-timer svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.pm-timer-bg { fill: none; stroke: rgba(255, 255, 255, 0.08); stroke-width: 6; }
.pm-timer-bar {
  fill: none;
  stroke: var(--pm-accent-2);
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.1s linear, stroke 0.3s ease;
  filter: drop-shadow(0 0 6px rgba(255, 210, 63, 0.6));
}
.pm-timer.is-warning .pm-timer-bar { stroke: #ff9f1c; filter: drop-shadow(0 0 6px rgba(255, 159, 28, 0.7)); }
.pm-timer.is-danger .pm-timer-bar { stroke: var(--pm-red); filter: drop-shadow(0 0 8px rgba(239, 71, 111, 0.8)); }
.pm-timer-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--pm-mono);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--pm-accent-2);
}
.pm-timer.is-warning .pm-timer-text { color: #ff9f1c; animation: pmPulse 0.5s infinite; }
.pm-timer.is-danger .pm-timer-text { color: var(--pm-red); animation: pmPulseFast 0.3s infinite; }

@keyframes pmPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}
@keyframes pmPulseFast {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* Griglia 3x3 */
.pm-grid-wrap {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  padding: 1.5rem;
  margin-bottom: 1.3rem;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  position: relative;
  overflow: hidden;
}
.pm-grid-wrap::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--pm-accent), var(--pm-accent-2), transparent);
  animation: pmScan 2s infinite;
}
@keyframes pmScan {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

.pm-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  max-width: 380px;
  margin: 0 auto;
}

.pm-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  background: rgba(255, 255, 255, 0.04);
  border: 2px solid rgba(168, 85, 247, 0.25);
  border-radius: 14px;
  transition: all 0.3s ease;
  user-select: none;
  line-height: 1;
}

.pm-cell.is-empty {
  background: rgba(255, 210, 63, 0.08);
  border: 2px dashed var(--pm-accent-2);
  animation: pmBlink 1.5s infinite;
}
@keyframes pmBlink {
  0%, 100% { background: rgba(255, 210, 63, 0.08); }
  50% { background: rgba(255, 210, 63, 0.18); }
}

.pm-cell.is-empty::after {
  content: '?';
  font-size: 3rem;
  color: var(--pm-accent-2);
  font-family: var(--pm-mono);
  font-weight: 700;
  text-shadow: 0 0 20px var(--pm-accent-2);
}

/* Opzioni */
.pm-options-wrap {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
  margin-bottom: 1.2rem;
}

.pm-option {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  background: rgba(255, 255, 255, 0.04);
  border: 2px solid rgba(168, 85, 247, 0.3);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  padding: 0;
  line-height: 1;
}
.pm-option:hover:not(:disabled) {
  border-color: var(--pm-accent-2);
  background: rgba(255, 210, 63, 0.1);
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(255, 210, 63, 0.25);
}
.pm-option:disabled { cursor: not-allowed; }
.pm-option.is-correct {
  background: rgba(74, 222, 128, 0.2);
  border-color: var(--pm-green);
  box-shadow: 0 0 25px rgba(74, 222, 128, 0.5);
  animation: pmPulse 0.4s ease;
}
.pm-option.is-wrong {
  background: rgba(239, 71, 111, 0.15);
  border-color: var(--pm-red);
  animation: pmShake 0.4s ease;
}
.pm-option.is-dim { opacity: 0.4; }

@keyframes pmShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

/* Feedback */
.pm-feedback {
  border-radius: 12px;
  padding: 1rem 1.2rem;
  margin-bottom: 1rem;
  font-size: 0.95rem;
  line-height: 1.55;
  display: none;
  animation: pmSlideIn 0.4s ease-out;
}
@keyframes pmSlideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.pm-feedback.is-visible { display: block; }
.pm-feedback.is-correct {
  background: linear-gradient(135deg, rgba(74, 222, 128, 0.15), rgba(74, 222, 128, 0.05));
  border: 1px solid rgba(74, 222, 128, 0.4);
  border-left: 4px solid var(--pm-green);
  color: #b8f5c8;
}
.pm-feedback.is-wrong {
  background: linear-gradient(135deg, rgba(239, 71, 111, 0.15), rgba(239, 71, 111, 0.05));
  border: 1px solid rgba(239, 71, 111, 0.4);
  border-left: 4px solid var(--pm-red);
  color: #f5b8c8;
}
.pm-feedback.is-timeout {
  background: linear-gradient(135deg, rgba(255, 210, 63, 0.15), rgba(255, 210, 63, 0.05));
  border: 1px solid rgba(255, 210, 63, 0.4);
  border-left: 4px solid var(--pm-accent-2);
  color: #f5e6a8;
}
.pm-feedback strong {
  display: block;
  margin-bottom: 0.4rem;
  font-family: var(--pm-mono);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 0.75rem;
}

/* Pulsante Avanti */
.pm-next-wrap { text-align: center; margin-top: 0.5rem; }
.pm-next-wrap.hidden { display: none; }
.pm-btn-next {
  background: linear-gradient(135deg, var(--pm-accent), var(--pm-accent-2));
  color: #12071f;
  padding: 0.9rem 2rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  box-shadow: 0 6px 25px rgba(168, 85, 247, 0.4);
}
.pm-btn-next:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 35px rgba(168, 85, 247, 0.6);
}

/* ─── FINALE ─── */
.pm-final { animation: pmFadeIn 0.6s ease-out; text-align: center; }

.pm-final-score-box {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.15), rgba(255, 210, 63, 0.08));
  border: 2px solid var(--pm-accent-2);
  border-radius: 20px;
  padding: 2.5rem 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 0 60px rgba(255, 210, 63, 0.2);
  position: relative;
  overflow: hidden;
}
.pm-final-score-box::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--pm-accent-2), var(--pm-accent), transparent);
  animation: pmScan 2s infinite;
}

.pm-final-label {
  font-family: var(--pm-mono);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #d8b4fe;
  margin-bottom: 0.5rem;
}
.pm-final-score {
  font-family: var(--pm-mono);
  font-size: clamp(3.5rem, 12vw, 5.5rem);
  font-weight: 700;
  line-height: 1;
  background: linear-gradient(135deg, var(--pm-accent-2), var(--pm-accent), #fff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 30px rgba(255, 210, 63, 0.5));
  margin-bottom: 0.5rem;
}
.pm-final-rating {
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 0.3rem;
}
.pm-final-sub {
  font-size: 0.85rem;
  color: var(--pm-text-dim);
  font-family: var(--pm-mono);
}

.pm-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.7rem;
  margin-bottom: 1.8rem;
}
.pm-stat {
  background: var(--pm-glass);
  border: 1px solid var(--pm-glass-border);
  border-radius: 12px;
  padding: 1rem 0.6rem;
  text-align: center;
}
.pm-stat-value {
  font-family: var(--pm-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--pm-accent-2);
  display: block;
  margin-bottom: 0.2rem;
}
.pm-stat-value.is-green { color: var(--pm-green); }
.pm-stat-value.is-red { color: var(--pm-red); }
.pm-stat-label {
  font-size: 0.7rem;
  color: var(--pm-text-mute);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: var(--pm-mono);
}

/* ─── RESPONSIVE ─── */
@media (max-width: 640px) {
  .pm-wrap { padding: 1rem 0.8rem 3rem; }
  .pm-header h1 { font-size: 1.5rem; }
  .pm-setup { padding: 1.5rem 1.2rem; }
  .pm-cell { font-size: 2.2rem; border-radius: 10px; }
  .pm-cell.is-empty::after { font-size: 2.2rem; }
  .pm-option { font-size: 1.8rem; border-radius: 10px; }
  .pm-grid-wrap { padding: 1rem; }
  .pm-grid { gap: 0.35rem; }
  .pm-options-wrap { gap: 0.4rem; }
  .pm-timer { width: 64px; height: 64px; }
  .pm-timer-text { font-size: 1rem; }
  .pm-stats { grid-template-columns: 1fr 1fr; }
  .pm-stats .pm-stat:last-child { grid-column: 1 / -1; }
}