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

:root {
  --bg:      #0d0d1a;
  --panel:   #12122a;
  --card:    #18183a;
  --border:  #28285a;
  --accent:  #7c3aed;
  --accent2: #3b82f6;
  --green:   #10b981;
  --red:     #ef4444;
  --orange:  #f59e0b;
  --gold:    #fbbf24;
  --text:    #e2e0f5;
  --muted:   #6b6994;
  --glow:    rgba(124,58,237,0.22);
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ── Topbar ─────────────────────────────────────────────────────────────────── */
#topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: 52px;
}

#tb-level {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

#tb-lvl {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}
#tb-lvl b { color: var(--accent); font-size: 16px; }

#xp-wrap {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  max-width: 260px;
  min-width: 80px;
}

#xp-bar {
  height: 8px;
  background: #0f0f2a;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
}

#xp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 4px;
  width: 0%;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 10px rgba(124,58,237,0.7);
}

#xp-label {
  font-size: 10px;
  color: var(--muted);
}

#tb-center {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Combo */
#combo-widget {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 13px;
  border-radius: 20px;
  font-weight: 700;
  border: 1px solid transparent;
  white-space: nowrap;
  transition: all 0.3s;
}
#combo-widget:empty { display: none; }

#combo-widget .c-fire { font-size: 18px; }
#combo-widget .c-mult { font-size: 19px; line-height: 1; }
#combo-widget .c-word { font-size: 9px; letter-spacing: 1.5px; opacity: 0.65; align-self: flex-end; padding-bottom: 1px; }

.combo-pulse { animation: cpulse 0.9s ease-in-out infinite; }
@keyframes cpulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.06); }
}

/* Boost */
#boost-widget {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  background: #1f1500;
  border: 1px solid var(--gold);
  color: var(--gold);
}
#boost-widget:empty { display: none; }

/* Coins */
#tb-coins {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 17px;
  font-weight: 700;
  color: var(--gold);
  flex-shrink: 0;
}
.coin-icon { font-size: 16px; }

/* ── Mode bar ────────────────────────────────────────────────────────────────── */
#mode-bar {
  display: flex;
  gap: 6px;
  padding: 8px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.mb-btn {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 20px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  transition: all 0.15s;
}
.mb-btn:hover  { background: #1a1a3a; color: var(--text); }
.mb-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Direction badge in card */
.dir-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 20px;
  letter-spacing: 0.5px;
  margin-bottom: 18px;
  margin-left: 6px;
}
.dir-badge.en-fr { background: rgba(59,130,246,0.15); color: var(--accent2); border: 1px solid rgba(59,130,246,0.3); }
.dir-badge.fr-en { background: rgba(16,185,129,0.15); color: var(--green);   border: 1px solid rgba(16,185,129,0.3); }

.card-top { display: flex; align-items: center; flex-wrap: wrap; }

/* ── Main layout ─────────────────────────────────────────────────────────────── */
#main {
  display: flex;
  min-height: calc(100vh - 52px);
}

/* ── Game column ─────────────────────────────────────────────────────────────── */
#game-col {
  flex: 1;
  padding: 28px 24px;
  position: relative;
  max-width: 660px;
}

#loading-msg {
  text-align: center;
  padding: 5rem;
  color: var(--muted);
  font-size: 16px;
}

/* Floaters */
#floaters {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.floater {
  position: absolute;
  font-weight: 800;
  pointer-events: none;
  animation: float-up 1.1s ease-out forwards;
}
.fl-xp    { font-size: 20px; color: var(--accent); text-shadow: 0 0 14px var(--accent); }
.fl-xps   { font-size: 15px; color: var(--accent2); }
.fl-coin  { font-size: 16px; color: var(--gold); text-shadow: 0 0 12px var(--gold); }

@keyframes float-up {
  0%   { opacity: 1;   transform: translateY(0) scale(1); }
  20%  { transform: translateY(-10px) scale(1.1); }
  100% { opacity: 0;   transform: translateY(-90px) scale(0.9); }
}

/* ── Card ─────────────────────────────────────────────────────────────────────── */
#card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 30px;
  box-shadow: 0 4px 32px rgba(0,0,0,0.5), 0 0 0 1px rgba(124,58,237,0.08);
}

.tense-badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 18px;
  border: 1px solid;
}

.q-prompt {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  margin-bottom: 10px;
}

.q-text {
  font-size: 26px;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 8px;
  color: #f0eeff;
  word-break: break-word;
}

.xp-preview {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 18px;
}
.xp-preview .xv { color: var(--accent); font-weight: 700; }

textarea {
  width: 100%;
  background: #0c0c22;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  resize: none;
  outline: none;
  line-height: 1.5;
  transition: border-color 0.2s, box-shadow 0.2s;
}
textarea:focus    { border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); }
textarea.t-ok     { border-color: var(--green);  background: #091f16; }
textarea.t-close  { border-color: var(--orange); background: #1f1200; }
textarea.t-wrong  { border-color: var(--red);    background: #1f0808; }
textarea:disabled { opacity: 0.75; cursor: default; }

.hint-area { margin-top: 10px; min-height: 22px; }
.hint-text {
  font-size: 13px;
  font-family: ui-monospace, monospace;
  color: var(--muted);
  background: #0c0c22;
  padding: 6px 10px;
  border-radius: 6px;
  letter-spacing: 1.5px;
}

.feedback {
  margin-top: 14px;
  padding: 12px 15px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.6;
}
.fb-ok    { background: #081f14; border: 1px solid #1a5030; color: #6ee7b7; }
.fb-close { background: #1f1100; border: 1px solid #5a3800; color: #fcd34d; }
.fb-wrong { background: #1f0808; border: 1px solid #5a1818; color: #fca5a5; }
.feedback em  { font-style: normal; font-weight: 600; }
.feedback .combo-bonus { margin-left: 8px; font-weight: 700; }
.feedback .shield-note { display: block; margin-top: 4px; color: #93c5fd; font-size: 12px; }

.btn-row { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

button {
  font-family: inherit;
  font-size: 14px;
  border-radius: 9px;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all 0.15s;
  padding: 10px 20px;
  color: var(--text);
  background: transparent;
}
button:active:not(:disabled) { transform: scale(0.97); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: #6d28d9; border-color: #6d28d9; }

.btn-secondary { color: var(--muted); }
.btn-secondary:hover:not(:disabled) { background: #1a1a3a; color: var(--text); }

.btn-link {
  background: none;
  border-color: transparent;
  color: var(--accent2);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-size: 13px;
  padding: 10px 12px;
}
.btn-link:hover:not(:disabled) { color: #93c5fd; }

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
#sidebar {
  width: 278px;
  min-width: 278px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  max-height: calc(100vh - 52px);
  position: sticky;
  top: 52px;
  align-self: flex-start;
}

.sb-block {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.sb-head {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.8px;
  color: var(--muted);
  margin-bottom: 10px;
}

/* Shop buttons */
.shop-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  margin-bottom: 6px;
  background: #0c0c22;
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  color: var(--text);
  font-family: inherit;
}
.shop-btn:last-child { margin-bottom: 0; }
.shop-btn:hover:not(:disabled) { border-color: var(--accent); background: #14143a; }
.shop-btn:disabled { opacity: 0.38; cursor: not-allowed; }
.shop-btn:active:not(:disabled) { transform: scale(0.98); }

.si-icon { font-size: 20px; flex-shrink: 0; }
.si-info { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.si-name { font-size: 13px; font-weight: 600; line-height: 1.3; }
.si-desc { font-size: 11px; color: var(--muted); line-height: 1.3; }
.si-cost { font-size: 13px; font-weight: 700; color: var(--gold); white-space: nowrap; flex-shrink: 0; }
.si-cost.broke { color: var(--muted); }

/* Stats */
.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 13px;
  border-bottom: 1px solid #1e1e40;
}
.stat-row:last-child { border-bottom: none; }
.stat-row .sr-k { color: var(--muted); }
.stat-row .sr-v { font-weight: 600; }

/* Achievements */
.ach-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 13px;
  line-height: 1.3;
}
.ach-icon { font-size: 16px; flex-shrink: 0; }
.ach-earned { color: var(--text); }
.ach-locked { color: var(--muted); }
.ach-locked .ach-icon { filter: grayscale(1) opacity(0.35); }

/* ── Achievement toast ───────────────────────────────────────────────────────── */
#ach-toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--card);
  border: 1px solid var(--gold);
  border-radius: 14px;
  padding: 12px 22px;
  font-size: 14px;
  font-weight: 500;
  color: var(--gold);
  box-shadow: 0 8px 40px rgba(0,0,0,0.6), 0 0 24px rgba(251,191,36,0.2);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}
#ach-toast.toast-in  { opacity: 1; transform: translateX(-50%) translateY(0); }
#ach-toast.toast-out { opacity: 0; transform: translateX(-50%) translateY(10px); }

/* ── Level-up overlay ────────────────────────────────────────────────────────── */
#lvlup-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  animation: lvl-anim 2.2s ease-out forwards;
  background: radial-gradient(ellipse at center, rgba(124,58,237,0.18) 0%, transparent 65%);
}

#lvlup-box { text-align: center; }

#lvlup-label {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 5px;
  color: var(--accent);
  text-shadow: 0 0 40px var(--accent), 0 0 80px rgba(124,58,237,0.5);
}

#lvlup-num {
  font-size: 110px;
  font-weight: 900;
  color: #fff;
  line-height: 1;
  text-shadow: 0 0 60px var(--accent), 0 0 120px rgba(124,58,237,0.4);
}

@keyframes lvl-anim {
  0%   { opacity: 0; transform: scale(0.4); }
  18%  { opacity: 1; transform: scale(1.08); }
  35%  { transform: scale(1); }
  72%  { opacity: 1; }
  100% { opacity: 0; transform: scale(1.15); }
}

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  #main { flex-direction: column; }
  #sidebar {
    width: 100%;
    min-width: 0;
    max-height: none;
    position: static;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  #xp-wrap { max-width: 140px; }
  #tb-lvl b { font-size: 14px; }
  .q-text { font-size: 21px; }
  #game-col { padding: 20px 16px; }
  #card { padding: 20px; }
  #combo-widget .c-word { display: none; }
}
