/* ==========================================================================
   RACCONTI CINESI — FOGLIO DI STILE MOBILE-FIRST
   Design System Orientale Moderno con supporto Light & Dark Mode
   ========================================================================== */

:root {
  /* Palette Colori Light (Default) */
  --bg-main: #FAF7F2;
  --bg-card: #FFFFFF;
  --bg-card-subtle: #F5EFEB;
  --bg-card-hover: #F0E8E1;
  --border-color: #E8DFD5;
  --border-focus: #C83226;
  
  --text-primary: #221F1D;
  --text-secondary: #6B6560;
  --text-muted: #948D86;
  --text-inverse: #FFFFFF;
  
  /* Accenti tematici */
  --cinese-red: #C83226;
  --cinese-red-hover: #AB261C;
  --cinese-red-light: rgba(200, 50, 38, 0.08);
  --cinese-gold: #C69214;
  --cinese-gold-light: rgba(198, 146, 20, 0.12);
  --cinese-jade: #2A7B5F;
  --cinese-jade-light: rgba(42, 123, 95, 0.1);
  --cinese-indigo: #395B82;
  --cinese-indigo-light: rgba(57, 91, 130, 0.1);
  
  /* Righe di apprendimento colori */
  --gr-color: #000000;
  --gr-bg: rgba(0, 0, 0, 0.04);
  --trad-color: #2D3748;
  --trad-bg: rgba(45, 55, 72, 0.04);
  --hanzi-color: #1A1A1A;
  --hanzi-bg: rgba(200, 50, 38, 0.04);
  --pinyin-color: #245878;
  --pinyin-bg: rgba(36, 88, 120, 0.06);

  /* Ombreggiature e Bordi */
  --shadow-sm: 0 2px 6px rgba(45, 30, 20, 0.05);
  --shadow-md: 0 6px 18px rgba(45, 30, 20, 0.08);
  --shadow-lg: 0 12px 30px rgba(45, 30, 20, 0.12);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  /* Font Families */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-hanzi: "Noto Serif SC", "Source Han Serif SC", "STSong", "Songti SC", "SimSun", serif;
  --font-mono: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  
  --transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Modalità Scura */
[data-theme="dark"] {
  --bg-main: #131518;
  --bg-card: #1B1F24;
  --bg-card-subtle: #232830;
  --bg-card-hover: #2B313C;
  --border-color: #2F3642;
  --border-focus: #E05347;
  
  --text-primary: #F0F4F8;
  --text-secondary: #A6B2C0;
  --text-muted: #6E7987;
  --text-inverse: #131518;
  
  --cinese-red: #E05347;
  --cinese-red-hover: #F2675C;
  --cinese-red-light: rgba(224, 83, 71, 0.18);
  --cinese-gold: #E5B33A;
  --cinese-gold-light: rgba(229, 179, 58, 0.18);
  --cinese-jade: #3EB38D;
  --cinese-jade-light: rgba(62, 179, 141, 0.18);
  --cinese-indigo: #5F95CC;
  --cinese-indigo-light: rgba(95, 149, 204, 0.18);

  --gr-color: #FFFFFF;
  --gr-bg: rgba(255, 255, 255, 0.08);
  --trad-color: #E2E8F0;
  --trad-bg: rgba(255, 255, 255, 0.04);
  --hanzi-color: #F8FAFC;
  --hanzi-bg: rgba(240, 83, 71, 0.09);
  --pinyin-color: #79B8FF;
  --pinyin-bg: rgba(121, 184, 255, 0.12);

  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 12px 30px rgba(0, 0, 0, 0.6);
}

/* Reset base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  height: 100%;
}

body {
  min-height: 100%;
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.5;
  transition: background-color 0.3s ease, color 0.3s ease;
  overflow-x: hidden;
  padding-bottom: calc(75px + env(safe-area-inset-bottom, 16px));
}

/* Contenitore Mobile-First centrato con larghezza ottimale */
.app-container {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-main);
  position: relative;
}

/* ==========================================================================
   HEADER DELL'APP
   ========================================================================== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.brand-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--cinese-red), #901B12);
  color: #FFF;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-hanzi);
  font-size: 20px;
  font-weight: bold;
  box-shadow: 0 3px 8px rgba(200, 50, 38, 0.3);
  flex-shrink: 0;
}

.brand-titles h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  line-height: 1.2;
}

.brand-titles .brand-sub {
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: var(--transition);
}

.icon-btn:hover, .icon-btn:active {
  background: var(--bg-card-hover);
  transform: scale(1.05);
}

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.btn-back:hover {
  background: var(--bg-card-hover);
  color: var(--cinese-red);
}

/* ==========================================================================
   VISTA HOME: CATALOGO & RICERCA
   ========================================================================== */
.view-home {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: fadeIn 0.25s ease-out;
}

/* Hero card introduttiva */
.home-hero {
  background: linear-gradient(135deg, var(--bg-card), var(--bg-card-subtle));
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.home-hero::after {
  content: "书";
  position: absolute;
  right: -10px;
  bottom: -25px;
  font-family: var(--font-hanzi);
  font-size: 110px;
  color: var(--cinese-red);
  opacity: 0.05;
  pointer-events: none;
}

.home-hero h2 {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.home-hero p {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

/* Barra di Ricerca AJAX */
.search-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 14px;
  color: var(--text-muted);
  pointer-events: none;
  font-size: 1rem;
}

.search-input {
  width: 100%;
  padding: 13px 42px 13px 40px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  outline: none;
  transition: var(--transition);
}

.search-input:focus {
  border-color: var(--cinese-red);
  box-shadow: 0 0 0 3px var(--cinese-red-light);
}

.search-clear {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
  display: none;
}

.search-clear.visible {
  display: block;
}

/* Filtri per Livello */
.level-filters {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.level-filters::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}

.filter-chip:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.filter-chip.active {
  background: var(--cinese-red);
  border-color: var(--cinese-red);
  color: #FFF;
  box-shadow: 0 2px 8px rgba(200, 50, 38, 0.25);
}

/* Griglia / Lista Racconti */
.stories-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.story-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  gap: 14px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.story-card:hover, .story-card:active {
  transform: translateY(-2px);
  border-color: var(--cinese-red);
  box-shadow: var(--shadow-md);
}

.story-thumbnail {
  width: 86px;
  height: 86px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
}

.story-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.story-meta-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.badge-level {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.badge-a1 { background: var(--cinese-jade-light); color: var(--cinese-jade); }
.badge-a2 { background: var(--cinese-gold-light); color: var(--cinese-gold); }
.badge-b1 { background: var(--cinese-indigo-light); color: var(--cinese-indigo); }

.badge-words {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--cinese-indigo);
  background: var(--cinese-indigo-light);
  border: 1px solid rgba(57, 91, 130, 0.2);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  letter-spacing: 0.01em;
}

.story-title-it {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

.story-title-zh {
  font-family: var(--font-hanzi);
  font-size: 0.95rem;
  color: var(--cinese-red);
  font-weight: 600;
  margin-top: 1px;
}

.story-gr-preview {
  font-size: 0.76rem;
  color: var(--text-secondary);
  font-style: italic;
}

.story-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 5px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.35;
}

/* Empty state per ricerca */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  background: var(--bg-card);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
}

.empty-state h3 {
  font-size: 1.1rem;
  margin-bottom: 6px;
  color: var(--text-primary);
}

/* ==========================================================================
   VISTA RACCONTO: BLOCCHI DI APPRENDIMENTO & CONTROLLI
   ========================================================================== */
.view-story {
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.25s ease-out;
}

/* Intestazione e Copertina Racconto */
.story-header-section {
  padding: 16px 16px 0 16px;
}

.story-header-titles {
  margin-bottom: 12px;
}

.story-header-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.story-detail-level {
  display: inline-block;
}

.story-detail-title-it {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.25;
}

.story-detail-title-zh {
  font-family: var(--font-hanzi);
  font-size: 1.25rem;
  color: var(--cinese-red);
  font-weight: 700;
  margin-top: 2px;
}

.story-detail-title-gr {
  font-size: 0.86rem;
  color: var(--text-secondary);
  font-style: italic;
  margin-top: 2px;
}

/* Immagine dopo il titolo */
.story-cover-wrapper {
  margin: 10px 0 14px 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  background: var(--bg-card-subtle);
}

.story-cover-img {
  width: 100%;
  height: auto;
  max-height: 280px;
  object-fit: cover;
  display: block;
}

/* Barra Riproduzione Audio MP3 */
.audio-player-bar {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.audio-play-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--cinese-red);
  color: #FFF;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  box-shadow: 0 4px 10px rgba(200, 50, 38, 0.35);
  flex-shrink: 0;
  transition: var(--transition);
}

.audio-play-btn:hover {
  background: var(--cinese-red-hover);
  transform: scale(1.05);
}

.audio-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.audio-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.audio-status-pill {
  font-size: 0.68rem;
  background: var(--cinese-red-light);
  color: var(--cinese-red);
  padding: 2px 6px;
  border-radius: 4px;
}

.audio-progress-container {
  width: 100%;
  height: 6px;
  background: var(--bg-card-subtle);
  border-radius: 3px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.audio-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--cinese-red);
  border-radius: 3px;
  transition: width 0.1s linear;
}

/* ==========================================================================
   PANNELLO CONTROLLI VISIBILITÀ RIGHE E TRADUZIONE
   ========================================================================== */
.learning-controls-sticky {
  position: sticky;
  top: 59px;
  z-index: 90;
  background: var(--bg-main);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.controls-row-toggles {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.controls-row-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.toggles-group {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.toggle-chip {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: var(--transition);
  user-select: none;
}

.toggle-chip.active {
  background: var(--cinese-red-light);
  border-color: var(--cinese-red);
  color: var(--cinese-red);
}

.toggle-chip .chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}

.toggle-chip.active .chip-dot {
  background: var(--cinese-red);
}

/* Switcher Traduzione Normale / Letterale */
.translation-mode-switch {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 2px;
  align-self: flex-start;
}

.trans-btn {
  background: transparent;
  border: none;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}

.trans-btn.active {
  background: var(--cinese-red);
  color: #FFF;
  box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   BLOCCHI DI APPRENDIMENTO (RIGHE DEL RACCONTO)
   ========================================================================== */
.story-blocks-container {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.learning-block {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  transition: var(--transition);
}

.learning-block:hover {
  border-color: rgba(200, 50, 38, 0.3);
  box-shadow: var(--shadow-md);
}

.block-index-badge {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-card-subtle);
  padding: 2px 7px;
  border-radius: var(--radius-full);
}

/* RIGA 1: Pronuncia Gwoyeu Romatzyh (GR) */
.row-gr {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--gr-color);
  line-height: 1.4;
  letter-spacing: 0.01em;
  padding: 6px 10px;
  background: var(--gr-bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--gr-color);
  cursor: pointer;
  transition: filter 0.22s ease, opacity 0.22s ease;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
}

.row-gr:hover {
  filter: brightness(0.97);
}

/* Sfocatura esercizio di auto-verifica al click/tap */
.row-gr.gr-blurred {
  filter: blur(7px) grayscale(0.6);
  opacity: 0.65;
  background: var(--bg-card-subtle);
  border-left-color: var(--border-color);
}

.row-gr.gr-blurred:hover {
  filter: blur(5.5px) grayscale(0.4);
  opacity: 0.8;
}

.row-gr.gr-blurred::after {
  content: 'Tocca per rivelare pronuncia GR';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 3px 12px 3px 26px;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  pointer-events: none;
  white-space: nowrap;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='14' height='14' fill='none' stroke='%23C83226' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='11' width='18' height='11' rx='2' ry='2'/%3E%3Cpath d='M7 11V7a5 5 0 0 1 10 0v4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 8px center;
  background-size: 13px 13px;
}

/* RIGA 2: Traduzione Italiana (Normale o Letterale) */
.row-trad {
  font-size: 0.96rem;
  font-weight: 500;
  color: var(--trad-color);
  line-height: 1.45;
  padding: 6px 10px;
  background: var(--trad-bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--text-secondary);
}

.row-trad.literal {
  font-family: var(--font-mono);
  font-size: 0.84rem;
  color: var(--cinese-indigo);
  border-left-color: var(--cinese-indigo);
}

/* RIGA 3: Hanzi (con parole cliccabili/tappabili) */
.row-hanzi {
  font-family: var(--font-hanzi);
  font-size: 1.55rem;
  line-height: 1.6;
  color: var(--hanzi-color);
  padding: 8px 10px;
  background: var(--hanzi-bg);
  border-radius: var(--radius-sm);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 4px;
}

/* Singola parola interattiva Hanzi */
.word-token {
  display: inline-block;
  padding: 1px 4px;
  border-radius: 4px;
  cursor: pointer;
  transition: var(--transition);
  border-bottom: 2px solid rgba(200, 50, 38, 0.25);
}

.word-token:hover, .word-token:active, .word-token.active {
  background: var(--cinese-red-light);
  color: var(--cinese-red);
  border-bottom-color: var(--cinese-red);
  transform: translateY(-1px);
}

/* RIGA 4: Pin-yin */
.row-pinyin {
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--pinyin-color);
  line-height: 1.4;
  padding: 6px 10px;
  background: var(--pinyin-bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--pinyin-color);
  letter-spacing: 0.02em;
}

/* Stili per mostrare / nascondere le righe */
.line-hidden {
  display: none !important;
}

/* ==========================================================================
   BUBBLE / POPOVER DELLA PAROLA AL TOCCO
   ========================================================================== */
.word-popover {
  position: fixed;
  z-index: 1000;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-lg);
  width: 290px;
  max-width: 90vw;
  display: none;
  animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  pointer-events: auto;
}

.word-popover.visible {
  display: block;
}

.popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
  margin-bottom: 8px;
}

.popover-hanzi {
  font-family: var(--font-hanzi);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--cinese-red);
}

.popover-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1;
}

.popover-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.popover-pron-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.popover-gr {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--gr-color);
  background: var(--gr-bg);
  padding: 2px 8px;
  border-radius: 4px;
}

.popover-pinyin {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--pinyin-color);
}

.popover-it {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.35;
}

.popover-literal {
  font-size: 0.78rem;
  color: var(--text-secondary);
  background: var(--bg-card-subtle);
  padding: 4px 8px;
  border-radius: 6px;
}

.popover-tts-btn {
  align-self: flex-start;
  margin-top: 4px;
  background: var(--cinese-red-light);
  border: 1px solid rgba(200, 50, 38, 0.2);
  color: var(--cinese-red);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: var(--transition);
}

.popover-tts-btn:hover {
  background: var(--cinese-red);
  color: #FFF;
}

/* ==========================================================================
   SEZIONE PAROLE PRINCIPALI (LESSICO A FINE RACCONTO)
   ========================================================================== */
.vocabulary-section {
  padding: 8px 16px 32px 16px;
}

.vocab-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.vocab-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.vocab-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.vocab-count {
  font-size: 0.72rem;
  background: var(--cinese-gold-light);
  color: var(--cinese-gold);
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-weight: 700;
}

.vocab-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 520px) {
  .vocab-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.vocab-item {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.vocab-item-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.vocab-item-hanzi {
  font-family: var(--font-hanzi);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--cinese-red);
}

.vocab-item-tag {
  font-size: 0.65rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 1px 6px;
  border-radius: 4px;
}

.vocab-item-pron {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.vocab-item-gr {
  font-weight: 700;
  color: var(--gr-color);
}

.vocab-item-it {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 2px;
}

/* Pulsante Modalità Lettura Pulita */
.btn-clean-reading {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.btn-clean-reading:hover, .btn-clean-reading:active {
  background: var(--cinese-red-light);
  border-color: var(--cinese-red);
  color: var(--cinese-red);
  transform: translateY(-1px);
}

.btn-clean-reading.active-blur {
  background: var(--cinese-gold-light);
  border-color: var(--cinese-gold);
  color: #B45309;
}

[data-theme="dark"] .btn-clean-reading.active-blur {
  background: rgba(217, 119, 6, 0.25);
  border-color: #F59E0B;
  color: #FCD34D;
}

/* ==========================================================================
   MODAL LETTURA PULITA (SOLO GR / SOLO CARATTERI)
   ========================================================================== */
.reading-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.2s ease-out;
}

.reading-modal-overlay.visible {
  display: flex;
}

.reading-modal {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 600px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: popIn 0.22s cubic-bezier(0.175, 0.885, 0.32, 1.2);
}

.reading-modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-card-subtle);
}

.reading-modal-titles {
  min-width: 0;
}

.reading-modal-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reading-modal-sub {
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.reading-modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  transition: var(--transition);
}

.reading-modal-close:hover {
  color: var(--cinese-red);
}

/* Toolbar interna alla modal: tabs e font size */
.reading-modal-toolbar {
  padding: 10px 18px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-card);
  flex-wrap: wrap;
}

.reading-tabs {
  display: flex;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 3px;
  gap: 4px;
}

.reading-tab-btn {
  background: transparent;
  border: none;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}

.reading-tab-btn.active {
  background: var(--cinese-red);
  color: #FFF;
  box-shadow: 0 2px 6px rgba(200, 50, 38, 0.3);
}

.reading-font-ctrls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.font-size-btn {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.font-size-btn:hover {
  background: var(--bg-card-hover);
}

/* Area del Testo Pulito */
.reading-modal-body {
  padding: 22px 20px;
  overflow-y: auto;
  flex: 1;
  background: var(--bg-card);
  overscroll-behavior: contain;
}

/* Testo Solo GR */
.clean-text-gr {
  color: var(--gr-color);
  font-weight: 600;
  line-height: 1.9;
  letter-spacing: 0.015em;
  font-size: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.clean-text-gr p {
  padding-left: 0;
  border-left: none;
  margin: 0;
}

/* Testo Solo Hanzi */
.clean-text-hanzi {
  font-family: var(--font-hanzi);
  color: var(--hanzi-color);
  font-weight: 600;
  line-height: 2.1;
  letter-spacing: 0.04em;
  font-size: 1.45rem;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.clean-text-hanzi p {
  padding-left: 0;
  border-left: none;
  margin: 0;
}

/* ==========================================================================
   SEZIONE SPIEGAZIONE GRAMMATICALE A FINE RACCONTO
   ========================================================================== */
.grammar-section {
  padding: 0 16px 36px 16px;
}

.grammar-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-top: 4px solid var(--cinese-indigo);
}

.grammar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 10px;
}

.grammar-header h3 {
  font-size: 1.12rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.grammar-badge {
  font-size: 0.72rem;
  background: var(--cinese-indigo-light);
  color: var(--cinese-indigo);
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-weight: 700;
}

.grammar-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.grammar-item {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: var(--transition);
}

.grammar-item:hover {
  border-color: rgba(57, 91, 130, 0.35);
  box-shadow: var(--shadow-sm);
}

.grammar-item-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--cinese-indigo);
  display: flex;
  align-items: center;
  gap: 6px;
}

.grammar-item-desc {
  font-size: 0.86rem;
  color: var(--text-primary);
  line-height: 1.5;
}

.reading-modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-card-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.reading-modal-footer-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.reading-modal-footer-btn:hover {
  background: var(--bg-card-hover);
}

/* ==========================================================================
   ANIMAZIONI
   ========================================================================== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

/* ==========================================================================
   SEZIONE FLASHCARDS LESSICO (DA ITALIANO A CINESE)
   ========================================================================== */
.flashcards-section {
  padding: 0 16px 24px 16px;
}

.flashcards-card-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.flashcards-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
}

.flashcards-header-left h3 {
  font-size: 1.12rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}

.flashcards-sub {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.flashcards-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.fc-action-btn {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.76rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: var(--transition);
}

.fc-action-btn:hover, .fc-action-btn:active {
  background: var(--bg-card-hover);
  border-color: var(--text-secondary);
}

/* Barra progresso e contatore */
.fc-progress-wrapper {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.fc-counter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.fc-hint-desktop {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

.fc-progress-track {
  width: 100%;
  height: 6px;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.fc-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--cinese-red), #C22A1E);
  border-radius: var(--radius-full);
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Scena 3D Flip Card */
.fc-scene {
  perspective: 1000px;
  width: 100%;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
}

.fc-card {
  position: relative;
  width: 100%;
  height: 200px;
  transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  border-radius: var(--radius-md);
}

.fc-card.is-flipped {
  transform: rotateY(180deg);
}

.fc-face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 18px 20px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.fc-scene:hover .fc-face, .fc-scene:focus-visible .fc-face {
  box-shadow: var(--shadow-md);
  border-color: rgba(200, 50, 38, 0.35);
}

.fc-front {
  background: linear-gradient(150deg, var(--bg-card) 60%, var(--bg-card-subtle));
}

.fc-back {
  background: linear-gradient(150deg, var(--bg-card-subtle) 40%, var(--bg-card));
  transform: rotateY(180deg);
  border-color: rgba(200, 50, 38, 0.3);
}

.fc-word-it {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.25;
  margin-bottom: 8px;
}

.fc-category {
  font-size: 0.76rem;
  color: var(--cinese-indigo);
  background: var(--cinese-indigo-light);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-bottom: 0;
}

.fc-word-gr {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--gr-color);
  margin-bottom: 4px;
  line-height: 1.25;
}

.fc-word-hanzi {
  font-family: var(--font-hanzi);
  font-size: 2.2rem;
  color: var(--cinese-red);
  font-weight: 700;
  margin-bottom: 4px;
  line-height: 1.2;
}

.fc-word-pinyin {
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--pinyin-color);
  margin-bottom: 6px;
}

.fc-word-literal {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-style: italic;
  max-width: 90%;
  line-height: 1.35;
}

/* Barra Controlli Flashcard Mobile-First */
.fc-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 4px;
}

.fc-nav-btn {
  flex: 1;
  padding: 12px 10px;
  font-size: 0.88rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-card-subtle);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: var(--transition);
  touch-action: manipulation;
}

.fc-nav-btn:hover:not(:disabled), .fc-nav-btn:active:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--text-secondary);
  transform: translateY(-1px);
}

.fc-nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.fc-flip-btn {
  flex: 1.4;
  padding: 12px 14px;
  font-size: 0.95rem;
  font-weight: 800;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--cinese-red);
  color: #FFF;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(200, 50, 38, 0.35);
  transition: var(--transition);
  touch-action: manipulation;
}

.fc-flip-btn:hover, .fc-flip-btn:active {
  background: var(--cinese-red-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(200, 50, 38, 0.45);
}

/* ==========================================================================
   OTTIMIZZAZIONE TIPOGRAFIA MOBILE PER IL RACCONTO
   ========================================================================== */
@media (max-width: 680px) {
  .row-hanzi {
    font-size: 1.82rem;
    line-height: 1.65;
    padding: 10px 12px;
  }

  .row-gr {
    font-size: 1.20rem;
    line-height: 1.48;
    padding: 8px 12px;
  }

  .row-trad {
    font-size: 1.06rem;
    line-height: 1.5;
    padding: 8px 12px;
  }

  .row-trad.literal {
    font-size: 0.94rem;
    line-height: 1.5;
  }

  .row-pinyin {
    font-size: 1.02rem;
    line-height: 1.45;
    padding: 8px 12px;
  }

  .clean-text-gr {
    font-size: 1.28rem;
    line-height: 2.0;
  }

  .clean-text-hanzi {
    font-size: 1.72rem;
    line-height: 2.2;
  }

  .fc-card {
    height: 210px;
  }

  .fc-word-it {
    font-size: 1.8rem;
  }

  .fc-word-gr {
    font-size: 1.65rem;
  }

  .fc-word-hanzi {
    font-size: 2.35rem;
  }

  .fc-hint-desktop {
    display: none;
  }

  .btn-clean-reading {
    font-size: 0.74rem;
    padding: 5px 9px;
  }
}

/* Footer note */
.app-footer {
  text-align: center;
  padding: 20px 16px;
  color: var(--text-muted);
  font-size: 0.75rem;
  border-top: 1px solid var(--border-color);
  margin-top: auto;
}

.app-footer a,
.app-footer .footer-link,
.footer-link {
  color: var(--text-muted) !important;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.2s ease;
}

.app-footer a:hover,
.app-footer .footer-link:hover,
.footer-link:hover {
  color: var(--text-secondary) !important;
}

.footer-sep {
  margin: 0 6px;
  opacity: 0.45;
}

/* ==========================================================================
   APP BOTTOM BAR — BARRA IN STILE APPLICAZIONE NATIVA
   Navigazione fissa per muoversi tra storie, sezioni e catalogo
   ========================================================================== */
.app-bottom-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 680px;
  z-index: 150;
  background: rgba(250, 247, 242, 0.92);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--border-color);
  box-shadow: 0 -4px 20px rgba(45, 30, 20, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 12px));
  transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

[data-theme="dark"] .app-bottom-bar {
  background: rgba(19, 21, 24, 0.92);
  border-top-color: var(--border-color);
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.45);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-width: 0;
  min-height: 48px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  cursor: pointer;
  padding: 4px 2px;
  gap: 3px;
  transition: color 0.18s ease, transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.18s ease;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
}

.bottom-nav-item:hover:not(:disabled) {
  color: var(--cinese-red);
}

.bottom-nav-item:hover:not(:disabled) .nav-icon svg {
  transform: translateY(-2px);
}

.bottom-nav-item:active {
  transform: scale(0.91);
  color: var(--cinese-red);
}

.bottom-nav-item.active {
  color: var(--cinese-red);
  font-weight: 700;
}

.bottom-nav-item.active .nav-icon svg {
  transform: translateY(-1px);
}

/* Indicatore pillola sotto la scheda attiva */
.bottom-nav-item.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  width: 20px;
  height: 3px;
  background: var(--cinese-red);
  border-radius: 9999px;
  box-shadow: 0 1px 4px rgba(200, 50, 38, 0.4);
}

.bottom-nav-item:disabled,
.bottom-nav-item.disabled {
  opacity: 0.32;
  cursor: not-allowed;
  pointer-events: none;
}

.bottom-nav-item .nav-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.18s ease;
}

.bottom-nav-item .nav-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.18s ease, stroke 0.18s ease;
}

.bottom-nav-item .nav-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.bottom-nav-item .bottom-nav-badge {
  position: absolute;
  top: -4px;
  right: -10px;
  background: var(--cinese-red);
  color: #FFF;
  font-size: 0.58rem;
  font-weight: 800;
  padding: 1px 4px;
  border-radius: 9999px;
  min-width: 14px;
  text-align: center;
  line-height: 1.2;
  box-shadow: 0 1px 4px rgba(200, 50, 38, 0.4);
  pointer-events: none;
}

@media (max-width: 480px) {
  .app-bottom-bar {
    padding: 5px 4px calc(5px + env(safe-area-inset-bottom, 12px));
  }
  .bottom-nav-item {
    min-height: 46px;
    gap: 2px;
  }
  .bottom-nav-item .nav-label {
    font-size: 0.65rem;
  }
  .bottom-nav-item .nav-icon svg {
    width: 19px;
    height: 19px;
  }
}

/* ==========================================================================
   ICONE SVG INTEGRATE NEL FRONTEND (Badge, Bottoni, Header e Popover)
   ========================================================================== */
.badge-words svg,
.btn-clean-reading svg,
.fc-action-btn svg,
.fc-flip-btn svg,
.popover-tts-btn svg,
.popover-it svg,
.search-icon svg,
.search-clear svg,
.popover-close svg,
.reading-tab-btn svg,
.theme-icon {
  display: inline-block;
  vertical-align: -0.15em;
  flex-shrink: 0;
}

.btn-clean-reading svg,
.fc-action-btn svg,
.fc-flip-btn svg,
.popover-tts-btn svg,
.popover-it svg,
.reading-tab-btn svg {
  margin-right: 5px;
}

.badge-words svg {
  margin-right: 4px;
  vertical-align: -0.16em;
}

.grammar-header h3 svg,
.vocab-header h3 svg,
.flashcards-header-left h3 svg {
  display: inline-block;
  vertical-align: -0.15em;
  margin-right: 6px;
  color: var(--cinese-red);
}

.audio-play-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  margin-left: 2px;
}

.audio-play-btn.playing svg {
  margin-left: 0;
}

/* ==========================================================================
   PAGINAZIONE STILE GOOGLE
   ========================================================================== */

.pagination-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 24px 16px 8px;
}

.pagination-counter {
  font-size: 0.78rem;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: center;
}

.pg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 4px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  user-select: none;
}

.pg-btn:hover:not(.pg-disabled):not(.pg-active) {
  background: var(--cinese-red-light);
  color: var(--cinese-red);
  border-color: var(--cinese-red-light);
  transform: translateY(-1px);
}

.pg-btn.pg-active {
  background: var(--cinese-red);
  color: #fff;
  border-color: var(--cinese-red);
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(200, 50, 38, 0.35);
  pointer-events: none;
}

.pg-btn.pg-arrow {
  color: var(--text-secondary);
}

.pg-btn.pg-arrow:hover:not(.pg-disabled) {
  color: var(--cinese-red);
  background: var(--cinese-red-light);
}

.pg-btn.pg-disabled,
.pg-btn[disabled] {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

.pg-ellipsis {
  display: inline-flex;
  align-items: flex-end;
  justify-content: center;
  min-width: 30px;
  height: 36px;
  color: var(--text-muted);
  font-size: 0.88rem;
  padding-bottom: 4px;
  letter-spacing: 0.05em;
  user-select: none;
}

/* Dark Mode overrides */
[data-theme="dark"] .pg-btn.pg-active {
  background: var(--cinese-red);
  box-shadow: 0 2px 10px rgba(224, 83, 71, 0.4);
}

[data-theme="dark"] .pg-btn:hover:not(.pg-disabled):not(.pg-active) {
  background: var(--cinese-red-light);
  color: var(--cinese-red);
}

/* Animazione entrata paginazione */
.pagination-wrap {
  animation: fadeInUp 0.25s ease forwards;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}


/* ==========================================================================
   PAGINA GUIDA GR — Gwoyeu Romatzyh
   ========================================================================== */

.view-guida-gr {
  max-width: 780px;
  margin: 0 auto;
  padding: 0 0 80px;
  animation: fadeInUp 0.3s ease forwards;
}

/* ── Hero ─────────────────────────────────────────────────────────────────── */
.guida-hero {
  background: linear-gradient(135deg, var(--cinese-red) 0%, #9B1C15 100%);
  color: #fff;
  padding: 40px 24px 36px;
  text-align: center;
  margin-bottom: 0;
}

.guida-hero-badge {
  display: inline-block;
  font-family: var(--font-hanzi);
  font-size: 1.4rem;
  letter-spacing: 0.05em;
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: var(--radius-full);
  padding: 4px 18px;
  margin-bottom: 14px;
}

.guida-hero h2 {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 800;
  margin: 0 0 12px;
  color: #fff;
  letter-spacing: -0.02em;
}

.guida-hero-sub {
  font-size: 0.97rem;
  opacity: 0.92;
  line-height: 1.6;
  max-width: 520px;
  margin: 0 auto 28px;
  color: #fff;
}

.guida-hero-compare {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
}

.guida-compare-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.guida-compare-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.75;
}

.guida-compare-word {
  font-family: var(--font-mono);
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.guida-compare-word.pinyin-style {
  opacity: 0.75;
  text-decoration: line-through;
  text-decoration-color: rgba(255,255,255,0.4);
}

.guida-compare-word.gr-style {
  background: rgba(255,255,255,0.2);
  border: 1.5px solid rgba(255,255,255,0.4);
  border-radius: var(--radius-sm);
  padding: 4px 14px;
}

.guida-compare-arrow {
  font-size: 1.5rem;
  opacity: 0.7;
  margin-top: 18px;
}

/* ── Sezioni ──────────────────────────────────────────────────────────────── */
.guida-section {
  padding: 32px 20px;
  border-bottom: 1px solid var(--border-color);
}

.guida-section:last-of-type { border-bottom: none; }

.guida-section-accent {
  background: var(--cinese-indigo-light);
  border-radius: 0;
}

.guida-section-title {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 18px;
}

.guida-section-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--cinese-red);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 800;
  flex-shrink: 0;
}

.guida-section p {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text-secondary);
  margin: 0 0 16px;
}

/* ── Tabella toni ─────────────────────────────────────────────────────────── */
.guida-tone-table-wrap,
.guida-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin: 16px 0;
}

.guida-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 500px;
  font-size: 0.88rem;
}

.guida-table th {
  background: var(--bg-card-subtle);
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.guida-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-secondary);
  line-height: 1.5;
  vertical-align: top;
}

.guida-table tr:last-child td { border-bottom: none; }

.guida-table td:first-child {
  font-weight: 600;
  white-space: nowrap;
}

.guida-table code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--cinese-indigo);
}

/* ── Badge tono ───────────────────────────────────────────────────────────── */
.tone-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
}
.tone-badge.t1 { background: rgba(57,91,130,0.15); color: var(--cinese-indigo); }
.tone-badge.t2 { background: rgba(42,123,95,0.15); color: var(--cinese-jade); }
.tone-badge.t3 { background: rgba(198,146,20,0.18); color: var(--cinese-gold); }
.tone-badge.t4 { background: rgba(200,50,38,0.12); color: var(--cinese-red); }
.tone-badge.t0 { background: var(--bg-card-subtle); color: var(--text-muted); }

/* ── Callout ──────────────────────────────────────────────────────────────── */
.guida-callout {
  background: var(--cinese-gold-light);
  border-left: 3px solid var(--cinese-gold);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 12px 16px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-top: 16px;
}

.guida-callout code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: rgba(255,255,255,0.6);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ── Grid vantaggi ────────────────────────────────────────────────────────── */
.guida-advantages-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 8px;
}

.guida-adv-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.guida-adv-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--cinese-red-light);
}

.guida-adv-icon {
  font-size: 1.5rem;
  margin-bottom: 10px;
}

.guida-adv-card h4 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 8px;
  line-height: 1.3;
}

.guida-adv-card p {
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.55;
  margin: 0;
}

.guida-adv-card p code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-card-subtle);
  border-radius: 3px;
  padding: 1px 4px;
  color: var(--cinese-indigo);
}

/* ── Lista benefici italofoni ─────────────────────────────────────────────── */
.guida-list {
  padding-left: 20px;
  margin: 0 0 20px;
}

.guida-list li {
  font-size: 0.93rem;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 10px;
}

.guida-list li code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: rgba(255,255,255,0.7);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--cinese-indigo);
}

/* ── Blocco confronti italofoni ───────────────────────────────────────────── */
.guida-compare-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.guida-compare-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.88rem;
}

.gcr-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  min-width: 38px;
}

.gcr-pin {
  font-family: var(--font-mono);
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 2px 8px;
  color: var(--text-secondary);
}

.gcr-gr {
  font-family: var(--font-mono);
  background: var(--cinese-red-light);
  border: 1px solid rgba(200,50,38,0.2);
  border-radius: 4px;
  padding: 2px 8px;
  color: var(--cinese-red);
  font-weight: 600;
}

.gcr-arrow {
  color: var(--text-muted);
  font-weight: 300;
}

.gcr-note {
  color: var(--text-muted);
  font-size: 0.82rem;
  flex: 1;
  min-width: 160px;
}

/* ── Grid esempi ──────────────────────────────────────────────────────────── */
.guida-examples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.guida-ex-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  transition: var(--transition);
}

.guida-ex-card:hover {
  border-color: var(--cinese-red-light);
  box-shadow: var(--shadow-sm);
}

.gex-pin {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: var(--text-muted);
  text-decoration: line-through;
  text-decoration-color: var(--border-color);
}

.gex-arrow {
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.5;
  display: none; /* nascosta — usata solo come separatore logico */
}

.gex-gr {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--cinese-red);
  letter-spacing: 0.01em;
}

.gex-it {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Footer nota ──────────────────────────────────────────────────────────── */
.guida-footer-note {
  padding: 28px 20px;
  text-align: center;
  border-top: 1px solid var(--border-color);
}

.guida-footer-note p {
  font-size: 0.83rem;
  color: var(--text-muted);
  line-height: 1.6;
  max-width: 540px;
  margin: 0 auto 20px;
}

.guida-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 22px;
  background: var(--cinese-red);
  color: #fff;
  border-radius: var(--radius-full);
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  transition: var(--transition);
  box-shadow: 0 2px 8px rgba(200,50,38,0.3);
}

.guida-back-btn:hover {
  background: var(--cinese-red-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(200,50,38,0.4);
}

/* ── Dark Mode ────────────────────────────────────────────────────────────── */
[data-theme="dark"] .guida-hero {
  background: linear-gradient(135deg, #9B1C15 0%, #5C100C 100%);
}

[data-theme="dark"] .guida-table code,
[data-theme="dark"] .guida-adv-card p code,
[data-theme="dark"] .guida-list li code {
  background: var(--bg-card-subtle);
  color: var(--cinese-indigo);
  border-color: var(--border-color);
}

[data-theme="dark"] .gcr-gr {
  background: var(--cinese-red-light);
  border-color: rgba(224,83,71,0.3);
}

[data-theme="dark"] .guida-callout code {
  background: rgba(0,0,0,0.3);
}

[data-theme="dark"] .tone-badge.t1 { background: rgba(95,149,204,0.18); color: var(--cinese-indigo); }
[data-theme="dark"] .tone-badge.t2 { background: rgba(62,179,141,0.18); color: var(--cinese-jade); }
[data-theme="dark"] .tone-badge.t3 { background: rgba(229,179,58,0.22); color: var(--cinese-gold); }
[data-theme="dark"] .tone-badge.t4 { background: rgba(224,83,71,0.18); color: var(--cinese-red); }

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .guida-advantages-grid { grid-template-columns: 1fr; }
  .guida-examples-grid   { grid-template-columns: 1fr 1fr; }
  .guida-compare-row     { flex-direction: column; align-items: flex-start; }
  .guida-hero            { padding: 28px 16px 26px; }
  .guida-section         { padding: 24px 16px; }
  .guida-table           { min-width: 420px; font-size: 0.82rem; }
}


/* ==========================================================================
   COOKIE CONSENT BANNER
   ========================================================================== */

.cookie-banner {
  position: fixed;
  bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  width: min(560px, calc(100vw - 24px));
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.32s ease, transform 0.32s cubic-bezier(0.34, 1.2, 0.64, 1);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.cookie-banner--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.cookie-msg {
  flex: 1;
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--text-secondary);
  min-width: 180px;
}

.cookie-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.cookie-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  padding: 0 14px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
  white-space: nowrap;
}

.cookie-btn:hover { transform: translateY(-1px); }

.cookie-btn-accept {
  background: var(--cinese-red);
  color: #fff;
  border-color: var(--cinese-red);
  box-shadow: 0 2px 6px rgba(200, 50, 38, 0.25);
}

.cookie-btn-accept:hover {
  background: var(--cinese-red-hover);
  box-shadow: 0 3px 10px rgba(200, 50, 38, 0.35);
}

.cookie-btn-decline {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border-color);
}

.cookie-btn-decline:hover {
  background: var(--bg-card-subtle);
  color: var(--text-secondary);
  border-color: var(--text-muted);
}

[data-theme="dark"] .cookie-banner {
  background: rgba(27, 31, 36, 0.94);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.25);
}

@media (max-width: 480px) {
  .cookie-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 14px 12px;
  }
  .cookie-actions {
    width: 100%;
    justify-content: flex-end;
  }
}
