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

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #252545;
  --accent: #7c6af7;
  --accent2: #a855f7;
  --plus: #22d3a0;
  --moins: #f87171;
  --text: #f1f0ff;
  --text-dim: #9090b0;
  --radius: 20px;
  --radius-sm: 12px;
  font-size: 16px;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ── Screens ── */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top, 24px) 24px env(safe-area-inset-bottom, 24px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  transform: translateY(20px);
}

.screen.active {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}

/* ── HOME ── */
#screen-home {
  justify-content: space-between;
  align-items: center;
  background: radial-gradient(ellipse at top, #1e1540 0%, var(--bg) 60%);
}

.hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding-top: 40px;
}

.logo-icon {
  font-size: 80px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

h1 {
  font-size: 2.8rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1.1;
}

.accent {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  color: var(--text-dim);
  font-size: 1rem;
  text-align: center;
  line-height: 1.6;
  margin-top: 8px;
}

.home-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 320px;
  padding-bottom: 16px;
}

.best-score {
  font-size: 0.85rem;
  color: var(--text-dim);
  text-align: center;
  padding-bottom: 8px;
}

.best-score.hidden { display: none; }

.btn-gear {
  position: absolute;
  top: max(env(safe-area-inset-top), 16px);
  right: 20px;
  background: var(--surface2);
  border: none;
  color: var(--text-dim);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  z-index: 10;
}

/* ── Settings modal specifics ── */
.setting-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.setting-label {
  font-size: 0.9rem;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.duration-chips {
  display: flex;
  gap: 10px;
}

.chip {
  flex: 1;
  padding: 12px 0;
  border-radius: var(--radius-sm);
  border: 2px solid var(--surface2);
  background: var(--surface2);
  color: var(--text-dim);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.chip.active {
  border-color: var(--accent);
  background: rgba(124, 106, 247, 0.15);
  color: var(--text);
}

/* ── Buttons ── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 28px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 700;
  transition: transform 0.1s ease, opacity 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.96); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  box-shadow: 0 8px 32px rgba(124, 106, 247, 0.4);
}

.btn-ghost {
  background: var(--surface2);
  color: var(--text-dim);
}

.btn-icon {
  font-size: 1.3rem;
}

.pulse {
  animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 8px 32px rgba(124, 106, 247, 0.4); }
  50% { box-shadow: 0 8px 48px rgba(168, 85, 247, 0.7); }
}

/* ── GAME ── */
#screen-game {
  gap: 0;
  background: var(--bg);
  padding-top: max(env(safe-area-inset-top), 20px);
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 12px;
}

.btn-icon-sm {
  background: var(--surface2);
  border: none;
  color: var(--text-dim);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.timer {
  font-size: 2.2rem;
  font-weight: 900;
  min-width: 60px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  transition: color 0.3s;
}

.timer.warning { color: var(--moins); animation: shake 0.3s ease; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.attempts {
  font-size: 0.85rem;
  color: var(--text-dim);
  min-width: 60px;
  text-align: right;
}

.game-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 16px 0;
}

.feedback-bubble {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  border-radius: 100px;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 1px;
  transition: background 0.25s, color 0.25s, transform 0.2s;
  min-width: 160px;
  justify-content: center;
}

.feedback-bubble.idle    { background: var(--surface2); color: var(--text-dim); }
.feedback-bubble.plus    { background: rgba(34,211,160,0.2); color: var(--plus); transform: scale(1.05); }
.feedback-bubble.moins   { background: rgba(248,113,113,0.2); color: var(--moins); transform: scale(1.05); }
.feedback-bubble.win     { background: rgba(124,106,247,0.2); color: var(--accent2); transform: scale(1.08); }
.feedback-bubble.listen  { background: rgba(124,106,247,0.15); color: var(--accent); }
.feedback-bubble.thinking{ background: var(--surface2); color: var(--text-dim); }

.guess-display {
  font-size: 3.5rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: 6px;
  min-height: 60px;
  transition: transform 0.15s;
}

.guess-display.pop { animation: pop 0.25s ease; }

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* ── History ── */
.history-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 0 4px;
  mask-image: linear-gradient(to bottom, transparent 0%, black 15%, black 85%, transparent 100%);
}

.history-list {
  list-style: none;
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  padding: 20px 0;
}

.history-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 0.95rem;
  animation: slide-in 0.2s ease;
}

@keyframes slide-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.history-list li .h-num { font-weight: 700; font-size: 1.1rem; }
.history-list li .h-res { font-weight: 800; font-size: 1rem; }
.history-list li.plus  .h-res { color: var(--plus); }
.history-list li.moins .h-res { color: var(--moins); }
.history-list li.win   { background: rgba(124,106,247,0.15); }

/* ── Listen section ── */
.listen-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px 0 14px;
}

.listen-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 56px;
}

.wave-bar {
  display: block;
  width: 5px;
  border-radius: 3px;
  background: var(--accent);
  height: 8px;
  transition: background 0.3s;
}

/* idle: flat bars */
.listen-indicator.idle .wave-bar {
  height: 8px;
  background: var(--surface2);
}

/* listening: animated wave */
.listen-indicator.listening .wave-bar {
  background: var(--plus);
  animation: wave-anim 0.9s ease-in-out infinite;
}
.listen-indicator.listening .wave-bar:nth-child(1) { animation-delay: 0s;    height: 16px; }
.listen-indicator.listening .wave-bar:nth-child(2) { animation-delay: 0.15s; height: 28px; }
.listen-indicator.listening .wave-bar:nth-child(3) { animation-delay: 0.3s;  height: 40px; }
.listen-indicator.listening .wave-bar:nth-child(4) { animation-delay: 0.15s; height: 28px; }
.listen-indicator.listening .wave-bar:nth-child(5) { animation-delay: 0s;    height: 16px; }

@keyframes wave-anim {
  0%, 100% { transform: scaleY(0.4); opacity: 0.7; }
  50%       { transform: scaleY(1);   opacity: 1; }
}

/* speaking: accent color, gentle pulse */
.listen-indicator.speaking .wave-bar {
  background: var(--accent2);
  animation: wave-speak 0.6s ease-in-out infinite alternate;
}
.listen-indicator.speaking .wave-bar:nth-child(1) { animation-delay: 0s;    height: 12px; }
.listen-indicator.speaking .wave-bar:nth-child(2) { animation-delay: 0.1s;  height: 22px; }
.listen-indicator.speaking .wave-bar:nth-child(3) { animation-delay: 0.2s;  height: 32px; }
.listen-indicator.speaking .wave-bar:nth-child(4) { animation-delay: 0.1s;  height: 22px; }
.listen-indicator.speaking .wave-bar:nth-child(5) { animation-delay: 0s;    height: 12px; }

@keyframes wave-speak {
  from { transform: scaleY(0.6); }
  to   { transform: scaleY(1); }
}

/* thinking: dim flicker */
.listen-indicator.thinking .wave-bar {
  background: var(--text-dim);
  height: 18px;
  animation: wave-think 0.4s ease-in-out infinite alternate;
}

@keyframes wave-think {
  from { opacity: 0.3; }
  to   { opacity: 0.8; }
}

.mic-hint {
  font-size: 0.85rem;
  color: var(--text-dim);
  text-align: center;
  min-height: 1.2em;
}

/* ── RESULT ── */
#screen-result {
  justify-content: center;
  align-items: center;
  background: radial-gradient(ellipse at center, #1e1540 0%, var(--bg) 70%);
}

.result-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 340px;
}

.result-emoji { font-size: 80px; animation: bounce-in 0.5s cubic-bezier(0.34,1.56,0.64,1); }

@keyframes bounce-in {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.result-content h2 { font-size: 2.2rem; font-weight: 900; }

.result-content p { color: var(--text-dim); text-align: center; font-size: 1rem; }

.result-number {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.result-stats {
  display: flex;
  gap: 20px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 24px;
  width: 100%;
  justify-content: center;
}

.stat { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stat-val { font-size: 1.8rem; font-weight: 900; }
.stat-lbl { font-size: 0.75rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  margin-top: 8px;
}

/* ── Modal ── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: flex-end;
  z-index: 100;
  backdrop-filter: blur(4px);
  transition: opacity 0.25s;
}

.modal.hidden { display: none; }

.modal-box {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 32px 24px 40px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: slide-up 0.3s cubic-bezier(0.34,1.2,0.64,1);
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-box h2 { font-size: 1.5rem; text-align: center; }

.rules-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.rules-list li {
  font-size: 1rem;
  line-height: 1.5;
  padding: 12px 16px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  color: var(--text);
  padding: 12px 24px;
  border-radius: 100px;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 200;
  pointer-events: none;
  transition: opacity 0.3s;
}

.toast.hidden { opacity: 0; display: none; }

/* ── Toggle switch (ASR setting) ── */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.setting-sub {
  font-size: 0.78rem;
  color: var(--accent);
  font-weight: 600;
  margin-top: 3px;
}

.toggle-wrap {
  position: relative;
  width: 54px;
  height: 30px;
  flex-shrink: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.toggle-wrap input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-track {
  position: absolute;
  inset: 0;
  border-radius: 15px;
  background: var(--surface2);
  transition: background 0.25s;
}

.toggle-track::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  top: 3px;
  left: 3px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: transform 0.25s, background 0.25s;
}

.toggle-wrap input:checked + .toggle-track {
  background: rgba(124, 106, 247, 0.35);
}

.toggle-wrap input:checked + .toggle-track::after {
  transform: translateX(24px);
  background: var(--accent);
}

/* ── Footer ── */
.app-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.65rem;
  color: rgba(144, 144, 176, 0.45);
  padding: 4px 0 max(env(safe-area-inset-bottom), 4px);
  pointer-events: none;
  z-index: 50;
  letter-spacing: 0.3px;
}
