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

:root {
  --accent: #ff6f00;
  --accent2: #ff9800;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #fff8e1;
  color: #3e2723;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 2rem 1rem;
}

#app { max-width: 700px; width: 100%; }

.hidden { display: none !important; }

/* Login / Signup */
.login-card {
  background: #fff3cd;
  border: 1px solid #ffe082;
  border-radius: 16px;
  padding: 2rem;
  max-width: 380px;
  margin: 0 auto;
}

.form-group {
  margin-bottom: 1.2rem;
  text-align: left;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: #795548;
  margin-bottom: 0.4rem;
}

.form-group input {
  width: 100%;
  padding: 0.8rem 1rem;
  background: #fffde7;
  border: 1px solid #ffe082;
  border-radius: 10px;
  color: #3e2723;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--accent);
}

.login-card button {
  width: 100%;
  padding: 0.85rem;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 0.5rem;
  transition: opacity 0.2s;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
}

.login-card button:hover { opacity: 0.9; }

.secondary-btn {
  background: transparent !important;
  border: 1px solid #ffe082 !important;
  color: #795548 !important;
}

.secondary-btn:hover {
  border-color: #ffb300 !important;
  color: #3e2723 !important;
}

.error-text {
  color: #c62828;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  text-align: center;
}

/* User bar */
.user-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.user-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

#user-greeting {
  font-weight: 600;
  font-size: 1rem;
}

.user-stats {
  font-size: 0.8rem;
  color: #795548;
}

.logout-btn {
  background: transparent;
  border: 1px solid #ffe082;
  color: #795548;
  padding: 0.4rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.logout-btn:hover {
  border-color: #c62828;
  color: #c62828;
}

/* Abort button */
.abort-btn {
  background: transparent;
  border: 1px solid #ef9a9a;
  color: #c62828;
  padding: 0.3rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  transition: all 0.2s;
}

.abort-btn:hover {
  background: #ffcdd2;
  border-color: #c62828;
}

.earned-text {
  color: #2e7d32;
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

/* Home Screen */
#home-screen { text-align: center; }
#login-screen, #signup-screen { text-align: center; }

h1 {
  font-size: 2.8rem;
  background: linear-gradient(135deg, #ff6f00, #ff9800);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.3rem;
}

.subtitle { color: #795548; font-size: 1.1rem; margin-bottom: 1.5rem; }

/* Language toggle - top right */
.lang-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 100;
  width: 172px;
}

.lang-trigger {
  width: 100%;
  padding: 0.8rem 1rem;
  border-radius: 10px;
  border: 1px solid #ffe082;
  background: #fffde7;
  color: #3e2723;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  outline: none;
  position: relative;
  box-shadow: 0 10px 24px rgba(121, 85, 72, 0.12);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.lang-trigger::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 1rem;
  width: 10px;
  height: 10px;
  border-right: 2px solid #795548;
  border-bottom: 2px solid #795548;
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

.lang-trigger:focus,
.lang-trigger[aria-expanded="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.lang-menu {
  margin-top: 0.45rem;
  width: 100%;
  background: #fffde7;
  border: 1px solid #ffe082;
  border-radius: 10px;
  box-shadow: 0 14px 28px rgba(121, 85, 72, 0.16);
  overflow: hidden;
}

.lang-option {
  width: 100%;
  padding: 0.8rem 1rem;
  background: #fffde7;
  border: none;
  border-bottom: 1px solid #ffe082;
  color: #3e2723;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.lang-option:last-child {
  border-bottom: none;
}

.lang-option:hover {
  background: #fff3cd;
}

.lang-option.active {
  background: color-mix(in srgb, var(--accent) 10%, #fffde7);
  color: #7a3e00;
}

.lang-option.active::before {
  content: "✓";
  margin-right: 0.55rem;
  font-weight: 700;
}

.lang-option:focus-visible {
  position: relative;
  z-index: 1;
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.lang-toggle .hidden {
  display: none !important;
}

#topics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}

.topic-card {
  background: #fff3cd;
  border: 1px solid #ffe082;
  border-radius: 16px;
  padding: 2rem 1rem;
  cursor: pointer;
  transition: all 0.25s ease;
  text-align: center;
}

.topic-card:hover {
  transform: translateY(-4px);
  border-color: var(--card-color, #ff9800);
  box-shadow: 0 8px 30px color-mix(in srgb, var(--card-color, #ff9800) 25%, transparent);
}

.topic-icon {
  width: 56px;
  height: 56px;
  object-fit: contain;
  margin-bottom: 0.6rem;
}
.topic-card .name { font-size: 1.1rem; font-weight: 600; }

.topic-level {
  font-size: 0.75rem;
  font-weight: 700;
  margin-top: 0.5rem;
  letter-spacing: 0.03em;
}

/* Leaderboard */
#leaderboard {
  margin-top: 2rem;
  text-align: left;
}

.leaderboard-title {
  font-size: 1.2rem;
  margin-bottom: 0.8rem;
  text-align: center;
  background: none;
  -webkit-text-fill-color: #3e2723;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.7rem 1rem;
  background: #fff3cd;
  border: 1px solid #ffe082;
  border-radius: 10px;
  margin-bottom: 0.5rem;
}

.lb-row.lb-highlight {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, #fff3cd);
}

.lb-medal { font-size: 1.3rem; }
.lb-name { flex: 1; font-weight: 600; }
.lb-score { color: #795548; font-size: 0.9rem; }

/* Quiz Screen */
.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.8rem;
  gap: 0.5rem;
}

#topic-label {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
  padding: 0.3rem 1rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
}

#progress { color: #795548; font-size: 0.9rem; }

.progress-bar {
  height: 6px;
  background: #ffe082;
  border-radius: 3px;
  margin-bottom: 2rem;
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 3px;
  transition: width 0.4s ease;
  width: 0%;
}

/* Timer */
.timer-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.timer-ring {
  position: relative;
  width: 56px;
  height: 56px;
  flex-shrink: 0;
}

.timer-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }

.timer-bg { fill: none; stroke: #ffe082; stroke-width: 5; }

.timer-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 163.36;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear, stroke 0.3s;
}

.timer-fill.urgent { stroke: #c62828; }

#timer-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.1rem;
  font-weight: 700;
}

#points-flash {
  font-size: 1.4rem;
  font-weight: 700;
  color: #2e7d32;
  animation: flashUp 0.6s ease forwards;
}

#points-flash.wrong-flash { color: #c62828; }

@keyframes flashUp {
  0% { opacity: 0; transform: translateY(8px); }
  30% { opacity: 1; transform: translateY(-4px); }
  100% { opacity: 1; transform: translateY(0); }
}

#question-card {
  background: #fff3cd;
  border: 1px solid #ffe082;
  border-radius: 16px;
  padding: 2rem;
}

#question-text {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

#options { display: flex; flex-direction: column; gap: 0.75rem; }

.option-btn {
  background: #fffde7;
  border: 1px solid #ffe082;
  border-radius: 12px;
  padding: 1rem 1.2rem;
  color: #3e2723;
  font-size: 1rem;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
}

.option-btn:hover:not(.disabled) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, #fffde7);
}

.option-btn.correct {
  border-color: #2e7d32;
  background: #c8e6c9;
  color: #1b5e20;
}

.option-btn.wrong {
  border-color: #c62828;
  background: #ffcdd2;
  color: #b71c1c;
}

.option-btn.disabled { cursor: default; opacity: 0.6; }
.option-btn.correct.disabled, .option-btn.wrong.disabled { opacity: 1; }

#next-btn {
  margin-top: 1.5rem;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  border: none;
  border-radius: 12px;
  padding: 0.9rem 2rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  float: right;
  transition: opacity 0.2s;
}

#next-btn:hover { opacity: 0.9; }

/* Result Screen */
#result-screen { text-align: center; padding-top: 3rem; }

.result-card {
  background: #fff3cd;
  border: 1px solid #ffe082;
  border-radius: 20px;
  padding: 3rem 2rem;
}

.result-card h2 { font-size: 1.6rem; margin-bottom: 0.5rem; }
#result-emoji { font-size: 3rem; margin-bottom: 0.5rem; }
#score-text { color: #795548; font-size: 1.1rem; margin-bottom: 2rem; }

#score-ring {
  position: relative;
  width: 140px;
  height: 140px;
  margin: 0 auto 2rem;
}

#score-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }

.ring-bg { fill: none; stroke: #ffe082; stroke-width: 8; }

.ring-fill {
  fill: none;
  stroke: url(#grad);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 326.7;
  stroke-dashoffset: 326.7;
  transition: stroke-dashoffset 1s ease;
}

#score-percent {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2rem;
  font-weight: 700;
}

.result-card button {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  border: none;
  border-radius: 12px;
  padding: 0.9rem 2.5rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.result-card button:hover { opacity: 0.9; }

@media (max-width: 500px) {
  h1 { font-size: 2rem; }
  #topics-grid { grid-template-columns: repeat(2, 1fr); }
  #question-card { padding: 1.2rem; }
  .lang-toggle {
    top: 0.75rem;
    right: 0.75rem;
    width: 148px;
  }
  .lang-trigger,
  .lang-option {
    padding: 0.7rem 0.9rem;
    font-size: 0.85rem;
  }
}
