/* ==========================================================================
   SHUI (水) - Clean, Orderly & Intuitive Electric Blue Interface
   - Raggruppamento coerente e logico delle sezioni
   - Typeface geometrica moderna: Outfit & Plus Jakarta Sans
   - Font weight leggero, sottile ed elegante
   - Ampia spaziatura ed aria nella zona centrale di studio
   - Palette scura e nitida in Blu Elettrico (#0070ff / #2979ff)
   - Spiegazione contestuale delle parole Pinyin al passaggio del mouse
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;600&family=Noto+Sans+SC:wght@300;400;500;600&family=Outfit:wght@300;400;500;600;700&family=Plus+Jakarta+Sans:wght@300;400;500;600;700&display=swap');

:root {
  /* Palette Blu Elettrico */
  --bg-color: #080c16;         /* Sfondo profondo scuro */
  --bg-sub: #0e1626;
  --bg-panel: #131d32;
  --bg-pill: #0e172a;

  --main-color: #0070ff;       /* Blu Elettrico Primario */
  --main-hover: #338cfc;
  --accent-electric: #2979ff;  /* Blu Elettrico Brillante */
  --correct-color: #f8fafc;    /* Carattere digitato corretto (bianco pulito) */
  --untyped-color: #384a6b;    /* Carattere non ancora digitato */
  --error-color: #ef4444;      /* Errore */
  --caret-color: #0070ff;      /* Cursore in blu elettrico netto */

  --text-main: #f1f5f9;
  --text-sub: #7a8fae;
  --text-muted: #4e6284;

  /* Typeface geometrica moderna */
  --font-geometric: 'Outfit', 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --font-hanzi: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

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

html, body {
  width: 100%;
  min-height: 100vh;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-geometric);
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  overflow-x: hidden;
  position: relative;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ==========================================================================
   FLOATING TOOLTIP SPIEGAZIONE PINYIN (ALTO CONTRASTO, NITIDO E DEFINITO)
   ========================================================================== */
.pinyin-tooltip {
  position: fixed;
  z-index: 99999;
  background: #111a2e;
  border: 1.5px solid #0070ff;
  border-radius: 12px;
  padding: 12px 18px;
  min-width: 220px;
  max-width: 340px;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
  text-align: left;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.85);
}

.pinyin-tooltip.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.tooltip-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.tooltip-pinyin {
  font-family: var(--font-geometric);
  font-size: 1.25rem;
  font-weight: 600;
  color: #38bdf8;
  letter-spacing: 0.02em;
}

.tooltip-hanzi {
  font-family: var(--font-hanzi);
  font-size: 1.4rem;
  font-weight: 600;
  color: #ffffff;
}

.tooltip-divider {
  width: 100%;
  height: 1px;
  background: rgba(0, 112, 255, 0.35);
  margin: 8px 0;
}

.tooltip-meaning {
  font-family: var(--font-geometric);
  font-size: 1.05rem;
  font-weight: 500;
  color: #ffffff;
  line-height: 1.35;
}

.tooltip-note {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 400;
  color: #cbd5e1;
  margin-top: 6px;
  line-height: 1.35;
}

/* Viewport Principale */
.app-viewport {
  position: relative;
  width: 100%;
  min-height: 100vh;
  padding: 20px 4vw 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

/* ==========================================================================
   1. ZONA SUPERIORE: SELEZIONE CATEGORIA & GRUPPO TEMATICO
   ========================================================================== */
.section-theme-nav {
  width: 100%;
  max-width: 1500px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* Riga 1: Brand + 10 Macrocategorie */
.macro-nav-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  width: 100%;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-sub);
  border: 1px solid rgba(0, 112, 255, 0.2);
  padding: 6px 14px;
  border-radius: 10px;
  user-select: none;
}

.brand-icon {
  font-family: var(--font-hanzi);
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--main-color);
}

.brand-name {
  font-family: var(--font-geometric);
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.macro-bar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
  background: var(--bg-pill);
  border: 1px solid rgba(0, 112, 255, 0.18);
  padding: 4px 10px;
  border-radius: 12px;
}

.macro-pill {
  font-family: var(--font-geometric);
  font-size: 0.84rem;
  font-weight: 400;
  background: transparent;
  border: none;
  color: var(--text-sub);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s ease, background 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.macro-pill:hover {
  color: var(--text-main);
  background: rgba(0, 112, 255, 0.1);
}

.macro-pill.active {
  color: #ffffff;
  background: var(--main-color);
  font-weight: 500;
}

/* Riga 2: Navigazione del Gruppo Tematico */
.group-nav-row {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--bg-pill);
  border: 1px solid rgba(0, 112, 255, 0.18);
  padding: 6px 14px;
  border-radius: 12px;
}

.group-btn {
  font-family: var(--font-geometric);
  font-size: 0.84rem;
  font-weight: 400;
  background: transparent;
  border: none;
  color: var(--text-sub);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color 0.15s ease, background 0.15s ease;
}

.group-btn:hover {
  color: var(--main-color);
  background: rgba(0, 112, 255, 0.1);
}

.group-btn:active {
  transform: scale(0.97);
}

.btn-arrow {
  font-size: 0.8rem;
}

.group-btn-random {
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.theme-select-container {
  position: relative;
  min-width: 240px;
  max-width: 440px;
}

.theme-select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background: #080d1a;
  border: 1px solid rgba(0, 112, 255, 0.25);
  color: var(--text-main);
  padding: 6px 30px 6px 12px;
  border-radius: 8px;
  font-family: var(--font-geometric);
  font-size: 0.86rem;
  font-weight: 400;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.theme-select:hover, .theme-select:focus {
  border-color: var(--main-color);
  color: var(--main-hover);
}

.theme-select-container::after {
  content: '▾';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--main-color);
  font-size: 0.8rem;
  pointer-events: none;
}

.theme-select optgroup {
  background: var(--bg-color);
  color: var(--main-color);
  font-weight: 500;
}

.theme-select option {
  background: var(--bg-panel);
  color: var(--text-main);
}

/* ==========================================================================
   2. ZONA CENTRALE: APPRENDIMENTO FRASE & SCRITTURA
   ========================================================================== */
.section-exercise {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 20px;
  padding: 2vh 2vw;
  cursor: text;
}

/* Frase in Italiano */
.italian-phrase {
  font-family: var(--font-geometric);
  font-size: clamp(1.15rem, 1.5vw, 1.4rem);
  font-weight: 300;
  color: var(--text-sub);
  line-height: 1.5;
  letter-spacing: 0.03em;
  max-width: 1500px;
  width: 100%;
}

/* Trascrizione PINYIN (Hero Font Geometrico a tutta larghezza in Blu Elettrico) */
.pinyin-phrase {
  font-family: var(--font-geometric);
  font-size: clamp(3rem, 5.4vw, 5.2rem);
  font-weight: 400;       /* Sottile e arioso */
  color: var(--main-color);
  letter-spacing: 0.02em;
  line-height: 1.25;
  width: 100%;
  max-width: 1800px;
  margin: 4px 0 10px;
  word-break: break-word;
  user-select: none;
}

/* Singola parola Pinyin interattiva al passaggio del mouse */
.pinyin-word {
  display: inline-block;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}

.pinyin-word:hover {
  background: rgba(0, 112, 255, 0.22);
  color: #ffffff;
}

/* Riga Ideogrammi Cinesi + Audio */
.hanzi-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  width: 100%;
  max-width: 1600px;
  flex-wrap: wrap;
}

.hanzi-live-display {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
  font-family: var(--font-hanzi);
  font-size: clamp(2.3rem, 4.2vw, 3.6rem);
  font-weight: 400;
  letter-spacing: 0.12em;
  user-select: none;
  padding: 4px 10px;
}

/* Singolo carattere Hanzi */
.char-glyph {
  position: relative;
  display: inline-block;
  color: var(--untyped-color);
  transition: color 0.12s ease;
}

.char-glyph.correct {
  color: var(--correct-color);
}

.char-glyph.has-caret::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 12%;
  height: 76%;
  width: 2px;
  background-color: var(--caret-color);
  border-radius: 1px;
  animation: monkeyBlink 1s infinite cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes monkeyBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.char-punc {
  color: var(--untyped-color);
  margin-left: 2px;
}

/* Pulsante Audio Integrato */
.inline-audio-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-panel);
  border: 1px solid rgba(0, 112, 255, 0.3);
  color: var(--main-color);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  flex-shrink: 0;
}

.inline-audio-btn:hover {
  color: #ffffff;
  border-color: var(--main-color);
  background: var(--main-color);
}

.inline-audio-btn.speaking {
  color: #ffffff;
  border-color: var(--main-color);
  background: var(--main-color);
}

/* Unità di Input Testuale */
.input-unit {
  position: relative;
  width: 100%;
  max-width: 580px;
  margin-top: 4px;
}

.chinese-input {
  width: 100%;
  background: #0b1120;
  border: 1px solid rgba(0, 112, 255, 0.3);
  border-radius: 12px;
  padding: 13px 44px 13px 20px;
  font-family: var(--font-hanzi);
  font-size: clamp(1.35rem, 2.3vw, 1.85rem);
  font-weight: 400;
  color: var(--text-main);
  text-align: center;
  letter-spacing: 0.14em;
  outline: none;
  transition: border-color 0.15s ease;
}

.chinese-input:focus {
  border-color: var(--main-color);
}

.chinese-input::placeholder {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 300;
  color: var(--text-muted);
  letter-spacing: normal;
}

.chinese-input.correct {
  border-color: #22c55e;
}

.input-clear-btn {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.8rem;
  transition: color 0.15s ease;
}

.input-clear-btn:hover {
  color: #ef4444;
}

/* Keycaps Rapidi */
.keycaps-container {
  width: 100%;
  max-width: 1200px;
  margin-top: 6px;
}

.quick-keycaps {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.keycap-btn {
  font-family: var(--font-hanzi);
  font-size: 1.15rem;
  font-weight: 400;
  background: var(--bg-panel);
  border: 1px solid rgba(0, 112, 255, 0.25);
  color: var(--text-main);
  padding: 7px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
  user-select: none;
}

.keycap-btn:hover {
  color: #ffffff;
  border-color: var(--main-color);
  background: var(--main-color);
}

.keycap-btn:active {
  transform: translateY(1px);
}

/* ==========================================================================
   3. ZONA INFERIORE: NAVIGAZIONE FRASE 1-15 & CONTROLLI VOCE/SHORTCUTS
   ========================================================================== */
.section-footer-nav {
  width: 100%;
  max-width: 1400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* Riga 1: Stepper e Navigazione Frasi Unificata */
.phrase-stepper-bar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--bg-pill);
  border: 1px solid rgba(0, 112, 255, 0.2);
  padding: 6px 14px;
  border-radius: 12px;
}

.phrase-nav-btn {
  font-family: var(--font-geometric);
  font-size: 0.86rem;
  font-weight: 400;
  background: transparent;
  border: 1px solid rgba(0, 112, 255, 0.2);
  color: var(--text-sub);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.phrase-nav-btn:hover {
  color: var(--text-main);
  border-color: var(--main-color);
  background: rgba(0, 112, 255, 0.1);
}

.phrase-btn-next {
  color: #ffffff;
  background: var(--main-color);
  border-color: var(--main-color);
  font-weight: 500;
}

.phrase-btn-next:hover {
  background: var(--main-hover);
  border-color: var(--main-hover);
  color: #ffffff;
}

.phrase-btn-random {
  padding: 6px 10px;
}

.stepper-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 4px;
}

.step-btn {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 400;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: transparent;
  border: none;
  color: var(--text-sub);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, background 0.15s ease;
}

.step-btn:hover {
  color: var(--text-main);
  background: rgba(0, 112, 255, 0.12);
}

.step-btn.active {
  color: #ffffff;
  background: var(--main-color);
  font-weight: 500;
}

/* Riga 2: Velocità Voce & Scorciatoie da Tastiera */
.footer-meta-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 16px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.tts-speed-cluster {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(0, 112, 255, 0.15);
  padding: 4px 12px;
  border-radius: 8px;
}

.meta-label {
  color: var(--text-sub);
  margin-right: 2px;
}

.speed-pill {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 400;
  background: transparent;
  border: none;
  color: var(--text-sub);
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}

.speed-pill:hover {
  color: var(--text-main);
  background: rgba(0, 112, 255, 0.12);
}

.speed-pill.active {
  color: #ffffff;
  background: var(--main-color);
  font-weight: 500;
}

.speed-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 50px;
  height: 3px;
  border-radius: 2px;
  background: rgba(0, 112, 255, 0.3);
  outline: none;
  cursor: pointer;
  margin: 0 4px;
}

.speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--main-color);
  cursor: pointer;
}

.speed-slider::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--main-color);
  border: none;
  cursor: pointer;
}

.meta-divider {
  width: 1px;
  height: 14px;
  background: rgba(0, 112, 255, 0.2);
}

.shortcuts-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.shortcuts-group kbd {
  background: rgba(0, 112, 255, 0.1);
  border: 1px solid rgba(0, 112, 255, 0.22);
  color: var(--main-hover);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.72rem;
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 768px) {
  .app-viewport {
    padding: 14px 8px;
    gap: 16px;
  }
  .macro-pill {
    font-size: 0.76rem;
    padding: 4px 8px;
  }
  .pinyin-phrase {
    font-size: clamp(2.2rem, 7.5vw, 3.2rem);
  }
  .hanzi-live-display {
    font-size: clamp(1.9rem, 6.5vw, 2.7rem);
  }
  .meta-divider, .shortcuts-group {
    display: none;
  }
}
