/* ============================================================
   Quiz Lessico Tecnico — Styles
   Design System: shared-design-system.md
   ============================================================ */

/* === Tokens === */
:root, [data-theme='light'] {
  --font-display: 'Chillax', 'Arial', sans-serif;
  --font-body: 'Nunito', 'Helvetica Neue', sans-serif;

  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);
  --text-2xl: clamp(2rem, 1.2rem + 2.5vw, 3.5rem);

  --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem;
  --space-4: 1rem; --space-5: 1.25rem; --space-6: 1.5rem;
  --space-8: 2rem; --space-10: 2.5rem; --space-12: 3rem;
  --space-16: 4rem; --space-20: 5rem; --space-24: 6rem;

  --color-bg: #f5f7fa;
  --color-surface: #ffffff;
  --color-surface-2: #f0f4f8;
  --color-border: #d0d7e0;
  --color-divider: #e2e8f0;

  --color-text: #1a2a3a;
  --color-text-muted: #5a6a7a;
  --color-text-faint: #94a3b8;

  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: #dbeafe;
  --color-primary-dark: #1e40af;

  --color-success: #16a34a;
  --color-success-light: #dcfce7;
  --color-success-dark: #15803d;

  --color-error: #dc2626;
  --color-error-light: #fee2e2;
  --color-error-dark: #b91c1c;

  --color-warning: #d97706;
  --color-warning-light: #fef3c7;

  --color-accent: #0d9488;
  --color-accent-light: #ccfbf1;

  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.25rem;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.12);

  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme='dark'] {
  --color-bg: #0f172a;
  --color-surface: #1e293b;
  --color-surface-2: #283548;
  --color-border: #334155;
  --color-divider: #1e293b;
  --color-text: #e2e8f0;
  --color-text-muted: #94a3b8;
  --color-text-faint: #64748b;
  --color-primary: #60a5fa;
  --color-primary-hover: #3b82f6;
  --color-primary-light: #1e3a5f;
  --color-primary-dark: #93c5fd;
  --color-success: #4ade80;
  --color-success-light: #14532d;
  --color-error: #f87171;
  --color-error-light: #450a0a;
  --color-warning: #fbbf24;
  --color-warning-light: #451a03;
  --color-accent: #2dd4bf;
  --color-accent-light: #134e4a;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.5);
}

/* === Base Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}
body {
  min-height: 100dvh;
  line-height: 1.6;
  font-family: var(--font-body, sans-serif);
  font-size: var(--text-base);
  color: var(--color-text);
  background-color: var(--color-bg);
}
img, svg { display: block; max-width: 100%; height: auto; }
button { cursor: pointer; background: none; border: none; font: inherit; color: inherit; }
a, button, [role='button'] {
  transition: color var(--transition-interactive), background var(--transition-interactive);
}
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* === Header === */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.header-icon {
  flex-shrink: 0;
  color: var(--color-text);
}
.header-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 1.2;
}
.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}
.score-display {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-lg);
  color: var(--color-warning);
}
.score-display svg {
  flex-shrink: 0;
}
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-lg);
  color: var(--color-text-muted);
  transition: background var(--transition-interactive), color var(--transition-interactive);
}
.theme-toggle:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

/* === Progress === */
.progress-container {
  padding: var(--space-4) var(--space-6);
  background: var(--color-surface);
}
.progress-labels {
  display: flex;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}
.progress-step {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: color var(--transition-normal);
}
.progress-step.active {
  color: var(--color-primary);
}
.progress-step.completed {
  color: var(--color-success);
}
.progress-track {
  height: 6px;
  background: var(--color-surface-2);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
  border-radius: var(--radius-full);
  transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

/* === Game Area === */
.game-area {
  max-width: 800px;
  margin: 0 auto;
  padding: var(--space-6);
}

/* Round header */
.round-header {
  text-align: center;
  margin-bottom: var(--space-6);
}
.round-header h2 {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  margin-bottom: var(--space-2);
}
.round-header p {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  max-width: 100%;
}

/* === Round 1 & 3 — Card Matching === */
.card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
}
@media (max-width: 560px) {
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.match-card {
  position: relative;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-4) var(--space-3);
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-xl);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition:
    transform var(--transition-interactive),
    border-color var(--transition-interactive),
    box-shadow var(--transition-interactive),
    background var(--transition-interactive),
    opacity var(--transition-normal);
  box-shadow: var(--shadow-sm);
}
.match-card:hover:not(.matched):not(.selected) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary);
}
.match-card.selected {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 25%, transparent);
  transform: scale(1.03);
}
.match-card.matched {
  border-color: var(--color-success);
  background: var(--color-success-light);
  cursor: default;
  opacity: 0.85;
}
.match-card.matched::after {
  content: '';
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  width: 22px;
  height: 22px;
  background: var(--color-success);
  border-radius: var(--radius-full);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 14px;
}
.match-card.wrong {
  animation: shake 0.4s ease;
  border-color: var(--color-error);
  background: var(--color-error-light);
}
.match-card .card-label {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-faint);
  position: absolute;
  top: var(--space-2);
  left: var(--space-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.match-card .card-text {
  line-height: 1.3;
}

/* === Round 2 — Image Matching === */
.image-match-area {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}
.svg-views {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
}
@media (max-width: 560px) {
  .svg-views {
    grid-template-columns: 1fr;
  }
}

.svg-view-card {
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-4);
  text-align: center;
  transition: border-color var(--transition-interactive), box-shadow var(--transition-interactive);
  position: relative;
}
.svg-view-card svg.tech-drawing {
  width: 100%;
  max-width: 160px;
  height: auto;
  margin: 0 auto var(--space-3);
  display: block;
}
.svg-view-card .drop-zone {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-faint);
  cursor: pointer;
  transition: all var(--transition-interactive);
}
.svg-view-card .drop-zone:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}
.svg-view-card .drop-zone.filled {
  border-style: solid;
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  color: var(--color-text);
}
.svg-view-card .drop-zone.correct {
  border-color: var(--color-success);
  background: var(--color-success-light);
  color: var(--color-success-dark);
}
.svg-view-card .drop-zone.incorrect {
  border-color: var(--color-error);
  background: var(--color-error-light);
  color: var(--color-error-dark);
  animation: shake 0.4s ease;
}
.svg-view-card.matched-view {
  border-color: var(--color-success);
}

.term-bank {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  justify-content: center;
}
.term-chip {
  display: inline-flex;
  align-items: center;
  padding: var(--space-3) var(--space-5);
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition:
    transform var(--transition-interactive),
    border-color var(--transition-interactive),
    background var(--transition-interactive),
    box-shadow var(--transition-interactive);
  box-shadow: var(--shadow-sm);
  min-height: 44px;
}
.term-chip:hover:not(.used) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary);
}
.term-chip.selected-chip {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 25%, transparent);
}
.term-chip.used {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

/* Check button for round 2 */
.check-btn-container {
  display: flex;
  justify-content: center;
  margin-top: var(--space-4);
}

/* === Feedback Toast === */
.feedback-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  padding: var(--space-4) var(--space-8);
  border-radius: var(--radius-2xl);
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  color: #fff;
  pointer-events: none;
  opacity: 0;
  z-index: 200;
  transition: opacity 0.2s ease, transform 0.2s ease;
  text-align: center;
  white-space: nowrap;
}
.feedback-toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
.feedback-toast.success {
  background: var(--color-success);
}
.feedback-toast.error {
  background: var(--color-error);
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  border-radius: var(--radius-xl);
  min-height: 48px;
  text-decoration: none;
  transition:
    background var(--transition-interactive),
    transform var(--transition-interactive),
    box-shadow var(--transition-interactive);
}
.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--color-primary-hover);
}
.btn-secondary {
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover {
  background: var(--color-surface);
}
.btn-success {
  background: var(--color-success);
  color: #fff;
}
.btn-success:hover {
  background: var(--color-success-dark);
}

/* === Summary Screen === */
.summary-screen[hidden] {
  display: none !important;
}
.summary-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--color-bg) 90%, transparent);
  z-index: 300;
  padding: var(--space-6);
  animation: fadeIn 0.4s ease;
}
.summary-card {
  background: var(--color-surface);
  border-radius: var(--radius-2xl);
  padding: var(--space-10) var(--space-8);
  text-align: center;
  box-shadow: var(--shadow-lg);
  max-width: 440px;
  width: 100%;
  animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
.summary-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  margin-bottom: var(--space-4);
}
.summary-stars {
  display: flex;
  justify-content: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.summary-stars svg {
  width: 40px;
  height: 40px;
}
.summary-score {
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: var(--space-2);
}
.summary-message {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-6);
}
.summary-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  justify-content: center;
}

/* === Animations === */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}
.pop {
  animation: pop 0.3s ease;
}

/* Round transition */
.game-area.round-exit {
  animation: fadeOutDown 0.3s ease forwards;
}
.game-area.round-enter {
  animation: fadeInUp 0.4s ease;
}
@keyframes fadeOutDown {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(16px); }
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === Responsive === */
@media (max-width: 480px) {
  .app-header {
    padding: var(--space-3) var(--space-4);
  }
  .header-title {
    font-size: var(--text-base);
  }
  .game-area {
    padding: var(--space-4);
  }
  .match-card {
    min-height: 64px;
    padding: var(--space-3) var(--space-2);
    font-size: var(--text-xs);
  }
  .round-header h2 {
    font-size: var(--text-lg);
  }
  .card-grid {
    gap: var(--space-3);
  }
}

/* === Accessibility: sr-only === */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}
