/* ==========================================================================
   CANVAS TRACING & ITALIANO COMPACT LAYOUT (Single-Screen / Zero-Scroll)
   ========================================================================== */

/* Authentic Italian Primary School Cursive Fonts (Playwrite IT Trad & Moderna) */
@font-face {
  font-family: 'Playwrite IT Trad';
  font-style: normal;
  font-weight: 100 400;
  font-display: swap;
  src: url('../fonts/playwrite_it_trad.woff2') format('woff2');
}

@font-face {
  font-family: 'Playwrite IT Moderna';
  font-style: normal;
  font-weight: 100 400;
  font-display: swap;
  src: url('../fonts/playwrite_it_moderna.woff2') format('woff2');
}

.tracing-compact-header {
  padding: 8px 16px;
  gap: 10px;
  flex-wrap: wrap;
}

.tracing-top-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.italian-mode-tabs-compact {
  display: flex;
  gap: 3px;
  background: #f1f5f9;
  padding: 3px;
  border-radius: 30px;
}

.mode-tab-btn-compact {
  padding: 5px 12px;
  font-size: 0.82rem;
  font-weight: 800;
  border-radius: 20px;
  border: 1.5px solid transparent;
  cursor: pointer;
  background: transparent;
  color: #475569;
  transition: all 0.15s ease;
}

.mode-tab-btn-compact.active {
  background: #f43f5e;
  color: #ffffff;
  border-color: #be123c;
  box-shadow: 0 2px 6px rgba(244, 63, 94, 0.3);
}

.style-selector-tabs-compact {
  display: flex;
  gap: 3px;
  background: #f1f5f9;
  padding: 3px;
  border-radius: 30px;
}

.style-btn-compact {
  padding: 5px 9px;
  font-size: 0.80rem;
  font-weight: 800;
  border-radius: 18px;
  border: 1.5px solid transparent;
  cursor: pointer;
  background: transparent;
  color: #64748b;
  transition: all 0.15s ease;
}

.style-btn-compact.active {
  background: #ffffff;
  color: #e11d48;
  border-color: #fecdd3;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
}

.canvas-wrapper.tracing-compact-wrapper {
  background: #ffffff;
  border-radius: var(--radius-lg);
  padding: 8px 12px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 3px solid var(--c-wood-border);
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  gap: 6px;
  box-sizing: border-box;
  overflow: hidden;
}

/* TOP: Carousel delle lettere & parole IMMEDIATAMENTE SOPRA AL CANVAS */
.tracing-carousel-area {
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-sizing: border-box;
  overflow: hidden;
}

.letter-carousel-compact, .letter-carousel {
  display: flex;
  overflow-x: auto;
  gap: 6px;
  padding: 3px 2px;
  width: 100%;
  max-width: 100%;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
  justify-content: flex-start;
  box-sizing: border-box;
}

.letter-btn {
  min-width: 44px;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 12px;
  border: 2px solid #cbd5e1;
  background: #ffffff;
  font-size: 1.25rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.letter-btn.active {
  background: var(--c-red);
  color: #fff;
  border-color: var(--c-red-dark);
  transform: scale(1.08);
  box-shadow: 0 3px 8px rgba(225, 29, 72, 0.3);
}

.word-filter-tabs-compact {
  display: flex;
  gap: 4px;
  margin-bottom: 3px;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  padding: 2px 2px 6px 2px;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
  justify-content: flex-start;
  box-sizing: border-box;
}

.filter-btn-compact {
  background: #f1f5f9;
  border: 1.5px solid #e2e8f0;
  border-radius: 16px;
  padding: 3px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #64748b;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
  white-space: nowrap;
}

.filter-btn-compact.active {
  background: #0ea5e9;
  color: #ffffff;
  border-color: #0284c7;
}

.word-carousel-compact, .word-carousel {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 3px 2px;
  width: 100%;
  max-width: 100%;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
}

.word-card-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #ffffff;
  border: 2px solid #e2e8f0;
  border-radius: 30px;
  padding: 4px 12px;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.word-card-btn.active {
  background: #f43f5e;
  color: #ffffff;
  border-color: #be123c;
  transform: scale(1.05);
  box-shadow: 0 3px 8px rgba(244, 63, 94, 0.3);
}

/* Inline Slim Info Pill */
.tracing-info-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fdf2f8;
  padding: 3px 14px;
  border-radius: 30px;
  border: 1.5px solid #fbcfe8;
  font-size: 0.92rem;
  margin: 1px 0;
}

.tracing-info-emoji {
  font-size: 1.25rem;
  line-height: 1;
}

.tracing-info-text {
  font-weight: 800;
  color: #9d174d;
}

.tracing-info-speak {
  background: none;
  border: none;
  font-size: 1.05rem;
  cursor: pointer;
  padding: 1px 3px;
  line-height: 1;
  transition: transform 0.15s;
}

.tracing-info-speak:active {
  transform: scale(1.25);
}

/* Generous Interactive Tracing Canvas (TOUCH FRIENDLY & FULLY RESPONSIVE) */
.tracing-box {
  position: relative;
  width: 100%;
  max-width: 360px;
  height: 360px;
  max-height: 48vh;
  background: #fffdfa;
  border: 3px solid #cbd5e1;
  border-radius: var(--radius-md);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.05);
  touch-action: none;
  margin: 0 auto;
  box-sizing: border-box;
  overflow: hidden;
}

.tracing-box.words-mode {
  width: 100%;
  max-width: 620px;
  height: 230px;
  max-height: 36vh;
  box-sizing: border-box;
}

/* 3-line ruling guidelines */
.tracing-guidelines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px 0;
  opacity: 0.55;
  box-sizing: border-box;
}

.line-sky, .line-grass, .line-ground {
  border-top: 2px dashed #94a3b8;
  position: relative;
}

.line-grass {
  border-top: 2px solid #22c55e;
}

.line-ground {
  border-top: 2px solid #991b1b;
}

#guideCanvas, #tracingCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#guideCanvas {
  pointer-events: none;
  z-index: 1;
}

#tracingCanvas {
  cursor: crosshair;
  z-index: 2;
}

/* BOTTOM: Action Bar IMMEDIATAMENTE SOTTO AL RIQUADRO (Reset & Verifica affiancati) */
.tracing-bottom-action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  max-width: 580px;
  margin-top: 4px;
  box-sizing: border-box;
  flex-wrap: wrap;
}

.btn-tracing-compact {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px 16px;
  border-radius: 24px;
  font-weight: 800;
  font-size: 0.90rem;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
  white-space: nowrap;
  box-shadow: 0 2px 5px rgba(0,0,0,0.08);
}

.btn-tracing-compact.btn-reset {
  background: #fee2e2;
  color: #991b1b;
  border: 1.5px solid #fca5a5;
}

.btn-tracing-compact.btn-reset:hover {
  background: #fecaca;
  transform: translateY(-1px);
}

.btn-tracing-compact.btn-reset:active {
  transform: scale(0.96);
}

.btn-tracing-compact.btn-verify {
  background: #22c55e;
  color: #ffffff;
  border: 1.5px solid #16a34a;
  box-shadow: 0 2px 8px rgba(34, 197, 94, 0.35);
}

.btn-tracing-compact.btn-verify:hover {
  background: #16a34a;
  transform: translateY(-1px);
}

.btn-tracing-compact.btn-verify:active {
  transform: scale(0.96);
}

.tracing-compact-feedback {
  flex: 1;
  min-width: 110px;
  max-width: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.feedback-gauge-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  font-size: 0.76rem;
  font-weight: 700;
  color: #475569;
}

.feedback-label {
  color: #334155;
}

.fidelity-score-badge {
  background: #e2e8f0;
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 800;
  color: #1e293b;
}

.fidelity-meter-bg {
  width: 100%;
  height: 7px;
  background: #e2e8f0;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.fidelity-meter-bar {
  height: 100%;
  width: 0%;
  background: #ef4444;
  border-radius: 6px;
  transition: width 0.3s ease, background-color 0.3s ease;
}

.fidelity-message {
  font-size: 0.70rem;
  color: #64748b;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
  min-height: 14px;
  text-align: center;
}

.btn-random-trace {
  padding: 6px 10px;
  font-size: 1.1rem;
  background: #f8fafc;
  border: 2px solid #cbd5e1;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(0,0,0,0.06);
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.btn-random-trace:hover {
  background: #fdf2f8;
  border-color: #f43f5e;
  transform: scale(1.08) rotate(5deg);
}

.btn-random-trace:active {
  transform: scale(0.95);
}

.number-btn {
  font-weight: 800 !important;
  color: #1e293b;
}

/* ==========================================================================
   MOBILE RESPONSIVE BREAKPOINTS (Smartphones & Small Tablets)
   ========================================================================== */
@media (max-width: 640px) {
  .tracing-compact-header {
    padding: 6px 10px;
    gap: 6px;
  }

  .canvas-wrapper.tracing-compact-wrapper {
    padding: 6px 8px;
    border-width: 2px;
    gap: 4px;
    border-radius: var(--radius-md);
  }

  .tracing-box {
    max-width: 100%;
    height: 300px;
    max-height: 44vh;
    border-width: 2px;
  }

  .tracing-box.words-mode {
    max-width: 100%;
    height: 190px;
    max-height: 30vh;
  }

  .tracing-guidelines {
    padding: 10px 0;
  }

  .tracing-bottom-action-bar {
    gap: 6px;
    justify-content: center;
  }

  .btn-tracing-compact {
    padding: 6px 12px;
    font-size: 0.82rem;
  }

  .tracing-compact-feedback {
    min-width: 90px;
    max-width: 140px;
  }
}
