/* ===========================
   RESET & VARIABLES
   =========================== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --green:        #58CC02;
  --green-dark:   #46A302;
  --green-pale:   #D7FFB8;
  --blue:         #1CB0F6;
  --blue-dark:    #0099D9;
  --blue-pale:    #DDF4FF;
  --red:          #FF4B4B;
  --red-dark:     #EA2B2B;
  --red-pale:     #FFDFE0;
  --yellow:       #FFC800;
  --yellow-dark:  #E5A800;
  --purple:       #CE82FF;
  --grey-bg:      #F7F7F7;
  --white:        #FFFFFF;
  --border:       #E5E5E5;
  --border-dark:  #CACACA;
  --text:         #3C3C3C;
  --text-muted:   #9B9B9B;
  --tile-hover:   #F5F5F5;
  --quenard-bg:   #F3E8FF;
  --quenard-text: #7C3AED;
  --savoyard-bg:  #FFFFFF;
  --savoyard-text:#CC0000;

  --r-sm:  8px;
  --r-md:  12px;
  --r-lg:  16px;
  --r-xl:  24px;

  --font: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

[data-theme="dark"] {
  --green-pale:    #14532d;
  --blue-pale:     #0c2a40;
  --red-pale:      #450a0a;
  --grey-bg:       #0f172a;
  --white:         #1e293b;
  --border:        #334155;
  --border-dark:   #475569;
  --text:          #f1f5f9;
  --text-muted:    #94a3b8;
  --tile-hover:    #253347;
  --quenard-bg:    #2e1a47;
  --quenard-text:  #c084fc;
  --savoyard-bg:   #1e1e2e;
  --savoyard-text: #f87171;
  color-scheme: dark;
}

body {
  font-family: var(--font);
  background: var(--grey-bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===========================
   HEADER
   =========================== */
.header {
  background: var(--white);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-inner {
  max-width: 660px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.logo-icon { font-size: 28px; }

.logo-text {
  font-size: 20px;
  font-weight: 900;
  color: var(--green);
  letter-spacing: 2px;
}

.header-stats {
  display: flex;
  align-items: center;
  gap: 18px;
}

.theme-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.theme-btn:hover { background: var(--border); }

.stat {
  display: flex;
  align-items: center;
  gap: 5px;
}

.stat-icon { font-size: 20px; }

.stat-value {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
  min-width: 20px;
}

/* ===========================
   MAIN LAYOUT
   =========================== */
.main {
  max-width: 660px;
  margin: 0 auto;
  padding: 20px 16px 100px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ===========================
   PROGRESS ROW
   =========================== */
.progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.close-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.close-btn:hover {
  background: var(--border);
  color: var(--text);
}

.progress-track {
  flex: 1;
  height: 16px;
  background: var(--border);
  border-radius: 100px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green) 0%, #73D500 100%);
  border-radius: 100px;
  width: 0%;
  transition: width 0.6s cubic-bezier(.4,0,.2,1);
}

.progress-label {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 36px;
  text-align: right;
}

/* ===========================
   EXERCISE CARD
   =========================== */
.exercise-card {
  background: var(--white);
  border: 2px solid var(--border);
  border-radius: var(--r-xl);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}


/* ===========================
   MASCOT ROW
   =========================== */
.mascot-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.mascot {
  font-size: 52px;
  line-height: 1;
  flex-shrink: 0;
  animation: mascotFloat 3s ease-in-out infinite;
  will-change: transform;
}

@keyframes mascotFloat {
  0%, 100% { transform: translateY(0px) rotate(-2deg); }
  50%       { transform: translateY(-8px) rotate(2deg); }
}

.bubble {
  position: relative;
  background: var(--white);
  border: 2px solid var(--border);
  border-radius: var(--r-lg);
  padding: 10px 14px;
  flex: 1;
}

.bubble::before {
  content: '';
  position: absolute;
  left: -9px;
  bottom: 14px;
  border: 8px solid transparent;
  border-right-color: var(--border);
  border-left: 0;
}

.bubble::after {
  content: '';
  position: absolute;
  left: -6px;
  bottom: 15px;
  border: 7px solid transparent;
  border-right-color: var(--white);
  border-left: 0;
}

.bubble-text {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.4;
}

/* ===========================
   SOURCE CARD
   =========================== */
.source-card {
  border: 2px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px 16px;
  background: var(--grey-bg);
}

.source-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 3px 10px;
  border-radius: 100px;
  margin-bottom: 8px;
}

.badge-grenoblois {
  background: var(--green-pale);
  color: var(--green-dark);
}

.badge-raphael_quenard {
  background: var(--quenard-bg);
  color: var(--quenard-text);
}

.badge-savoyard {
  background: var(--savoyard-bg);
  color: var(--savoyard-text);
}

.source-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.5;
}

/* ===========================
   HINT
   =========================== */
.hint-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.hint-btn {
  background: none;
  border: 2px solid var(--yellow);
  border-radius: var(--r-sm);
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 700;
  color: var(--yellow-dark);
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.hint-btn:hover {
  background: rgba(255, 200, 0, 0.1);
}

.hint-text {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  display: none;
}

.hint-text.visible {
  display: inline;
}

/* ===========================
   ANSWER AREA
   =========================== */
.answer-section {}

.answer-label {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.answer-area {
  min-height: 76px;
  border: 2.5px dashed var(--border);
  border-radius: var(--r-md);
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-content: flex-start;
  transition: border-color 0.2s;
  background: var(--white);
}

.answer-area.active {
  border-style: solid;
  border-color: var(--blue);
  background: var(--blue-pale);
}

.answer-placeholder {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  pointer-events: none;
}

/* ===========================
   WORD TILES
   =========================== */
.tile {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  background: var(--white);
  border: 2px solid var(--border-dark);
  border-bottom: 4px solid var(--border-dark);
  border-radius: var(--r-md);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.08s ease, border-bottom-width 0.08s ease, background 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.tile:hover {
  background: var(--tile-hover);
  transform: translateY(-1px);
}

.tile:active {
  transform: translateY(2px);
  border-bottom-width: 2px;
}

.tile.used {
  visibility: hidden;
  pointer-events: none;
}

/* Tiles inside answer area */
.tile.answer-tile {
  background: var(--white);
  border-color: var(--blue);
  border-bottom-color: var(--blue-dark);
  color: var(--blue-dark);
}

.tile.answer-tile:hover {
  background: var(--blue-pale);
}

/* ===========================
   WORD BANK
   =========================== */
.word-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding-top: 16px;
  border-top: 2px solid var(--border);
}

/* ===========================
   ACTION BAR
   =========================== */
.action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--white);
  border-top: 2px solid var(--border);
  padding: 12px 16px;
  z-index: 40;
}

.btn-check {
  width: 100%;
  max-width: 660px;
  display: block;
  margin: 0 auto;
  padding: 15px 24px;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--white);
  background: var(--green);
  border: none;
  border-bottom: 4px solid var(--green-dark);
  border-radius: var(--r-lg);
  cursor: pointer;
  transition: transform 0.08s ease, border-bottom-width 0.08s ease, background 0.15s;
}

.btn-check:hover:not(:disabled) {
  background: #62D900;
  transform: translateY(-1px);
}

.btn-check:active:not(:disabled) {
  transform: translateY(2px);
  border-bottom-width: 2px;
}

.btn-check:disabled {
  background: var(--border);
  border-bottom-color: var(--border-dark);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* ===========================
   FEEDBACK PANEL
   =========================== */
.feedback-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 60;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(.4,0,.2,1);
}

.feedback-panel.visible {
  transform: translateY(0);
}

.feedback-panel.correct .feedback-inner {
  background: var(--green-pale);
  border-top: 4px solid var(--green);
}

.feedback-panel.wrong .feedback-inner {
  background: var(--red-pale);
  border-top: 4px solid var(--red);
}

.feedback-inner {
  max-width: 660px;
  margin: 0 auto;
  padding: 16px 20px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.feedback-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.feedback-icon { font-size: 36px; flex-shrink: 0; }

.feedback-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
}

.feedback-sub {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 2px;
  word-break: break-word;
}

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

.btn-retry {
  display: none;
  padding: 14px 18px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--red);
  background: var(--white);
  border: 2px solid var(--red);
  border-bottom: 4px solid var(--red-dark);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: transform 0.08s ease, border-bottom-width 0.08s ease, background 0.1s;
}

.btn-retry:hover { background: var(--red-pale); transform: translateY(-1px); }
.btn-retry:active { transform: translateY(2px); border-bottom-width: 2px; }

.feedback-panel.wrong .btn-retry {
  display: block;
}

.btn-continue {
  flex-shrink: 0;
  padding: 14px 22px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--white);
  background: var(--green);
  border: none;
  border-bottom: 4px solid var(--green-dark);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: transform 0.08s ease, border-bottom-width 0.08s ease;
}

.btn-continue:hover { transform: translateY(-1px); }
.btn-continue:active { transform: translateY(2px); border-bottom-width: 2px; }

.feedback-panel.wrong .btn-continue {
  background: var(--red);
  border-bottom-color: var(--red-dark);
}

/* ===========================
   COMPLETION SCREEN
   =========================== */
.completion-screen {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeBg 0.35s ease;
}

.completion-screen.visible {
  display: flex;
}

@keyframes fadeBg {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.completion-card {
  background: var(--white);
  border-radius: var(--r-xl);
  padding: 36px 28px;
  text-align: center;
  width: 100%;
  max-width: 380px;
  animation: slideUp 0.35s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

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

.comp-trophy {
  font-size: 80px;
  animation: trophyBounce 0.6s cubic-bezier(.4,0,.2,1) 0.1s both;
}

@keyframes trophyBounce {
  0%   { transform: scale(0) rotate(-15deg); }
  60%  { transform: scale(1.2) rotate(5deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.comp-title {
  font-size: 30px;
  font-weight: 900;
  color: var(--text);
  margin-top: 12px;
}

.comp-sub {
  font-size: 15px;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 6px;
  margin-bottom: 28px;
}

.comp-stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 28px;
}

.comp-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.comp-stat-icon { font-size: 26px; }

.comp-stat-val {
  font-size: 26px;
  font-weight: 900;
  color: var(--text);
}

.comp-stat-lbl {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}

.btn-restart {
  padding: 15px 40px;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--white);
  background: var(--green);
  border: none;
  border-bottom: 4px solid var(--green-dark);
  border-radius: var(--r-lg);
  cursor: pointer;
  transition: transform 0.08s ease, border-bottom-width 0.08s ease;
}

.btn-restart:hover { transform: translateY(-2px); }
.btn-restart:active { transform: translateY(2px); border-bottom-width: 2px; }

/* ===========================
   LOADING SCREEN
   =========================== */
.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--white);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease;
}

.loading-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-content {
  text-align: center;
}

.loading-icon {
  font-size: 72px;
  animation: loadingPulse 1.2s ease-in-out infinite;
}

@keyframes loadingPulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.1); }
}

.loading-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-muted);
  margin-top: 16px;
}

/* ===========================
   ANIMATIONS
   =========================== */
@keyframes shakeX {
  0%, 100%  { transform: translateX(0); }
  20%       { transform: translateX(-8px); }
  40%       { transform: translateX(8px); }
  60%       { transform: translateX(-6px); }
  80%       { transform: translateX(6px); }
}

@keyframes popIn {
  0%   { transform: scale(0.8); opacity: 0; }
  60%  { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

.anim-shake { animation: shakeX 0.4s ease; }
.anim-pop   { animation: popIn  0.25s cubic-bezier(.4,0,.2,1); }

/* ===========================
   RESPONSIVE
   =========================== */
@media (max-width: 520px) {
  .header-inner { padding: 10px 14px; }
  .logo-text    { font-size: 17px; }
  .logo-icon    { font-size: 24px; }
  .header-stats { gap: 12px; }
  .stat-icon    { font-size: 18px; }
  .stat-value   { font-size: 14px; }

  .main { padding: 14px 12px 100px; gap: 12px; }
  .exercise-card { padding: 14px; gap: 14px; }

  .mascot { font-size: 42px; }
  .bubble-text { font-size: 13px; }

  .source-text { font-size: 16px; }

  .tile {
    font-size: 14px;
    padding: 7px 12px;
  }

  .feedback-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .feedback-actions {
    width: 100%;
    flex-direction: row;
  }

  .btn-retry,
  .btn-continue {
    flex: 1;
    text-align: center;
  }
}

@media (max-width: 360px) {
  .comp-stats { gap: 14px; }
  .comp-stat-val { font-size: 22px; }
}
