/* ============================================================
   HANZI FLASHCARDS — Feuille de style
   Design épuré, animations 3D, responsive
   ============================================================ */

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Palette */
  --color-bg:            #faf8f5;
  --color-surface:       #ffffff;
  --color-text:          #2c2c2c;
  --color-text-secondary:#6b6b6b;
  --color-text-muted:    #9a9a9a;
  --color-accent:        #c2413b;  /* rouge chinois doux */
  --color-accent-hover:  #a8322c;
  --color-accent-light:  #fce8e6;
  --color-gold:          #d4983c;
  --color-gold-light:    #fdf3e0;
  --color-border:        #e8e4df;
  --color-shadow:        rgba(0, 0, 0, 0.06);

  /* Typographie */
  --font-sans:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-hanzi:     'Noto Sans SC', 'Ma Shan Zheng', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --font-display:   'Ma Shan Zheng', 'Noto Sans SC', cursive;

  /* Dimensions */
  --card-width:     380px;
  --card-height:    520px;
  --card-radius:    20px;
  --header-height:  auto;

  /* Transitions */
  --ease-smooth:    cubic-bezier(0.4, 0, 0.2, 1);
  --flip-duration:  0.6s;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.6;
  overflow-x: hidden;
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(194, 65, 59, 0.03) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(212, 152, 60, 0.04) 0%, transparent 60%),
    radial-gradient(ellipse at 50% 80%, rgba(194, 65, 59, 0.02) 0%, transparent 60%);
}

/* ============================================================
   EN-TÊTE
   ============================================================ */

.app-header {
  width: 100%;
  padding: 1.8rem 1.5rem 0;
  text-align: center;
}

.header-content {
  max-width: 600px;
  margin: 0 auto;
}

.app-title {
  font-family: var(--font-hanzi);
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.title-icon {
  font-size: 2.2rem;
  line-height: 1;
}

.app-subtitle {
  color: var(--color-text-secondary);
  font-size: 0.95rem;
  margin-top: 0.25rem;
  font-weight: 400;
}

/* Bannière de statut */
.status-banner {
  margin: 1.2rem auto 0;
  max-width: 500px;
  padding: 0.6rem 1.2rem;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all 0.3s var(--ease-smooth);
}

.status-loading {
  background: var(--color-gold-light);
  color: var(--color-gold);
  border: 1px solid rgba(212, 152, 60, 0.2);
}

.status-success {
  background: #e8f5e9;
  color: #2e7d32;
  border: 1px solid rgba(46, 125, 50, 0.15);
}

.status-error {
  background: var(--color-accent-light);
  color: var(--color-accent);
  border: 1px solid rgba(194, 65, 59, 0.15);
}

.status-demo {
  background: #eef2ff;
  color: #4f46e5;
  border: 1px solid rgba(79, 70, 229, 0.15);
}

/* ============================================================
   BARRE DE PROGRESSION & FILTRES
   ============================================================ */

.progress-section {
  width: 100%;
  max-width: 600px;
  margin: 1.5rem auto 0;
  padding: 0 1.5rem;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.4rem;
}

.progress-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.progress-count {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

.progress-bar-container {
  width: 100%;
  height: 6px;
  background: var(--color-border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--color-accent), var(--color-gold));
  border-radius: 3px;
  width: 0%;
  transition: width 0.4s var(--ease-smooth);
}

/* Filtres */
.filter-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.9rem;
  flex-wrap: wrap;
}

.filter-label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.filter-select {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.4rem 2rem 0.4rem 0.75rem;
  border: 1.5px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b6b6b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.filter-select:hover {
  border-color: var(--color-accent);
}

.filter-select:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-color: var(--color-accent);
}

/* ============================================================
   SCÈNE DE LA CARTE
   ============================================================ */

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 1.5rem 1rem 2rem;
}

.card-scene {
  perspective: 1200px;
  width: var(--card-width);
  height: var(--card-height);
  max-width: 90vw;
}

/* ---------- Flashcard ---------- */
.flashcard {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform var(--flip-duration) var(--ease-smooth);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.flashcard:focus-visible {
  border-radius: var(--card-radius);
  box-shadow: 0 0 0 3px var(--color-accent);
}

/* État retourné */
.flashcard.is-flipped {
  transform: rotateY(180deg);
}

/* ---------- Faces ---------- */
.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--card-radius);
  background: var(--color-surface);
  box-shadow:
    0 1px 3px var(--color-shadow),
    0 8px 32px rgba(0, 0, 0, 0.07),
    0 2px 8px rgba(0, 0, 0, 0.04);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  will-change: transform;
}

/* Face arrière : pivotée */
.card-back {
  transform: rotateY(180deg);
}

/* ---------- Badge (niveau HSK) ---------- */
.card-badge {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: var(--color-accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  z-index: 2;
  pointer-events: none;
}

/* ============================================================
   FACE AVANT (RECTO)
   ============================================================ */

.card-front {
  justify-content: center;
  align-items: center;
  padding: 2rem;
}

.card-char-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.card-char {
  font-family: var(--font-hanzi);
  font-size: clamp(6rem, 18vw, 10rem);
  font-weight: 900;
  color: var(--color-text);
  line-height: 1;
  text-shadow:
    0 2px 4px rgba(0, 0, 0, 0.06),
    0 8px 16px rgba(0, 0, 0, 0.04);
  user-select: none;
  transition: transform 0.3s var(--ease-smooth);
}

/* Léger effet au survol */
.flashcard:not(.is-flipped):hover .card-char {
  transform: scale(1.04);
}

.card-front-footer {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 0.5rem;
}

.card-counter {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   FACE ARRIÈRE (VERSO)
   ============================================================ */

.card-back {
  padding: 2.5rem 1.8rem 1.5rem;
}

.card-back-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
  padding-right: 0.2rem;
}

.card-back-content::-webkit-scrollbar {
  width: 4px;
}

.card-back-content::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 2px;
}

/* Sections du verso */
.back-section {
  padding: 0.3rem 0;
}

/* Pinyin */
.card-pinyin {
  font-family: var(--font-sans);
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-accent);
  letter-spacing: 0.02em;
  text-align: center;
}

/* Radical */
.back-radical {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--color-text-secondary);
}

.radical-icon {
  font-size: 1rem;
}

.radical-label {
  font-weight: 500;
}

.radical-value {
  font-family: var(--font-hanzi);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--color-text);
  margin-left: 0.15rem;
}

/* Animation des traits */
.back-strokes {
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 0.7rem;
  background: #fdfdfc;
}

.strokes-header {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.4rem;
}

.strokes-icon {
  font-size: 0.9rem;
}

.stroke-container {
  display: flex;
  justify-content: center;
  min-height: 90px;
  align-items: center;
}

.hanzi-writer-target {
  width: 90px;
  height: 90px;
}

.hanzi-writer-target svg {
  width: 100%;
  height: 100%;
}

.strokes-controls {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.4rem;
}

.btn-stroke {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.35rem 0.8rem;
  border: 1.5px solid var(--color-accent);
  border-radius: 6px;
  background: transparent;
  color: var(--color-accent);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-stroke:hover {
  background: var(--color-accent);
  color: #fff;
}

.btn-stroke-secondary {
  border-color: var(--color-gold);
  color: var(--color-gold);
}

.btn-stroke-secondary:hover {
  background: var(--color-gold);
  color: #fff;
}

/* Traduction */
.card-traduction {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-text);
  text-align: center;
}

/* Phrase d'exemple */
.back-exemple {
  margin-top: 0.3rem;
}

.exemple-block {
  background: #f9f8f6;
  border-left: 3px solid var(--color-gold);
  border-radius: 0 8px 8px 0;
  padding: 0.6rem 0.8rem;
}

.exemple-phrase {
  font-family: var(--font-hanzi);
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: 0.15rem;
}

.exemple-pinyin {
  font-size: 0.78rem;
  color: var(--color-accent);
  font-weight: 500;
  margin-bottom: 0.15rem;
}

.exemple-traduction {
  font-size: 0.82rem;
  color: var(--color-text-secondary);
  font-style: italic;
}

/* Bouton audio verso */
.btn-icon-back {
  align-self: center;
  margin-top: 0.3rem;
}

/* ============================================================
   BOUTONS ICÔNES
   ============================================================ */

.btn-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--color-accent-light);
  color: var(--color-accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: var(--color-accent);
  color: #fff;
  transform: scale(1.08);
}

.btn-icon:active {
  transform: scale(0.95);
}

.btn-icon:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* ============================================================
   NAVIGATION
   ============================================================ */

.nav-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.btn-nav {
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.6rem 1.2rem;
  border: 1.5px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-nav:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
  box-shadow: 0 2px 8px rgba(194, 65, 59, 0.1);
}

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

.btn-nav:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.btn-random {
  border-color: var(--color-gold);
  color: var(--color-gold);
}

.btn-random:hover {
  background: var(--color-gold);
  color: #fff;
  border-color: var(--color-gold);
}

/* ============================================================
   RACCOURCIS CLAVIER
   ============================================================ */

.keyboard-hints {
  margin-top: 1rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  text-align: center;
}

.keyboard-hints kbd {
  display: inline-block;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

/* ============================================================
   PIED DE PAGE
   ============================================================ */

.app-footer {
  width: 100%;
  text-align: center;
  padding: 1.2rem 1rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
  margin-top: auto;
}

.app-footer a {
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 500;
}

.app-footer a:hover {
  text-decoration: underline;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* Tablettes */
@media (max-width: 768px) {
  :root {
    --card-width:  340px;
    --card-height: 470px;
  }

  .app-title {
    font-size: 1.6rem;
  }

  .card-pinyin {
    font-size: 1.7rem;
  }

  .card-char {
    font-size: clamp(5rem, 16vw, 8rem);
  }

  .card-back {
    padding: 2rem 1.4rem 1.2rem;
  }
}

/* Mobiles */
@media (max-width: 480px) {
  :root {
    --card-width:  300px;
    --card-height: 430px;
  }

  .app-title {
    font-size: 1.4rem;
  }

  .app-subtitle {
    font-size: 0.82rem;
  }

  .card-char {
    font-size: clamp(4.5rem, 14vw, 7rem);
  }

  .card-pinyin {
    font-size: 1.4rem;
  }

  .card-traduction {
    font-size: 1rem;
  }

  .card-back {
    padding: 1.6rem 1rem 1rem;
  }

  .nav-controls {
    gap: 0.4rem;
  }

  .btn-nav {
    font-size: 0.8rem;
    padding: 0.5rem 0.9rem;
    border-radius: 8px;
  }

  .keyboard-hints {
    display: none;
  }

  .filter-controls {
    justify-content: center;
  }
}

/* Très petits écrans */
@media (max-width: 360px) {
  :root {
    --card-width:  260px;
    --card-height: 380px;
  }

  .card-char {
    font-size: clamp(3.8rem, 12vw, 5.5rem);
  }

  .card-pinyin {
    font-size: 1.2rem;
  }

  .btn-nav {
    font-size: 0.75rem;
    padding: 0.4rem 0.7rem;
  }
}

/* Grands écrans */
@media (min-width: 1200px) {
  :root {
    --card-width:  420px;
    --card-height: 560px;
  }

  .card-char {
    font-size: 11rem;
  }
}

/* ============================================================
   ANIMATIONS SUPPLÉMENTAIRES
   ============================================================ */

/* Apparition de la carte au changement */
@keyframes cardEnter {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.flashcard.card-enter {
  animation: cardEnter 0.35s var(--ease-smooth);
}

/* Préférences de réduction de mouvement */
@media (prefers-reduced-motion: reduce) {
  .flashcard {
    transition: transform 0.15s ease;
  }

  .flashcard.card-enter {
    animation: none;
  }

  .card-char {
    transition: none;
  }

  .progress-bar {
    transition: none;
  }

  .btn-icon:hover {
    transform: none;
  }

  .btn-nav:active {
    transform: none;
  }
}

/* Mode sombre (optionnel, s'active automatiquement) */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg:            #1a1a1c;
    --color-surface:       #252528;
    --color-text:          #e8e8ea;
    --color-text-secondary:#a0a0a5;
    --color-text-muted:    #6e6e73;
    --color-accent:        #e0554b;
    --color-accent-hover:  #c2413b;
    --color-accent-light:  #3d1f1d;
    --color-gold:          #e0a84c;
    --color-gold-light:    #3d2f1a;
    --color-border:        #38383c;
    --color-shadow:        rgba(0, 0, 0, 0.2);
  }

  .exemple-block {
    background: #1e1e20;
  }

  .back-strokes {
    background: #1e1e20;
  }

  .status-loading {
    background: #2d2510;
    color: #e0a84c;
  }

  .status-error {
    background: #3d1f1d;
    color: #e0554b;
  }
}
