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

:root {
  --bg-dark: #0a0e1a;
  --bg-card: #151a2e;
  --bg-card-hover: #1c2240;
  --text: #e8eaf0;
  --text-dim: #8a8fa8;
  --accent: #fbbf24;
  --accent-glow: rgba(251, 191, 36, 0.3);
  --green: #34d399;
  --red: #f87171;
  --blue: #60a5fa;
  --purple: #a78bfa;
  --radius: 16px;
  --radius-sm: 10px;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100%;
  position: relative;
}

/* --- Screens --- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.screen.active {
  display: flex;
}

/* --- Top Bar --- */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(10, 14, 26, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.game-title {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.1);
  background: var(--bg-card);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.icon-btn:hover {
  background: var(--bg-card-hover);
}

.streak-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 6px 14px;
  font-weight: 600;
  font-size: 16px;
}

.streak-flame {
  font-size: 18px;
}

.streak-count {
  color: var(--accent);
}

/* --- World Select Grid --- */
.world-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  padding: 20px;
  flex: 1;
}

.world-card {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 3 / 2;
  transition: transform 0.2s, box-shadow 0.2s;
}

.world-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.world-card:active {
  transform: translateY(-1px);
}

.world-card-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-color: var(--bg-card);
  filter: brightness(0.6);
  transition: filter 0.2s;
}

.world-card:hover .world-card-bg {
  filter: brightness(0.75);
}

.world-card-content {
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 16px;
}

.world-card-char {
  position: absolute;
  right: 12px;
  bottom: 50px;
  width: 80px;
  height: 80px;
  object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.5));
  animation: idle-bob 3s ease-in-out infinite;
  z-index: 3;
}

.world-card-char.locked {
  filter: brightness(0) drop-shadow(0 2px 8px rgba(0,0,0,0.5));
  opacity: 0.4;
  animation: none;
}

@keyframes idle-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.world-card-name {
  font-size: 18px;
  font-weight: 700;
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
}

.world-card-table {
  font-size: 13px;
  color: rgba(255,255,255,0.7);
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
  margin-top: 2px;
}

.world-card-progress {
  margin-top: 8px;
  height: 4px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  overflow: hidden;
}

.world-card-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}

.world-card-complete-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--green);
  color: #000;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 12px;
  z-index: 3;
}

/* --- Back Button --- */
.back-btn {
  background: rgba(255,255,255,0.1);
  border: none;
  color: var(--text);
  font-size: 15px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.back-btn:hover {
  background: rgba(255,255,255,0.18);
}

/* --- World Detail --- */
.world-detail-bg {
  position: fixed;
  inset: 0;
  background-size: cover;
  background-position: center;
  filter: brightness(0.35) blur(2px);
  z-index: 0;
}

.world-detail-content {
  position: relative;
  z-index: 1;
  padding: 20px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

.world-detail-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: 24px 0 32px;
}

.world-detail-char {
  width: 100px;
  height: 100px;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.5));
  animation: idle-bob 3s ease-in-out infinite;
}

.world-detail-title {
  font-size: 28px;
  font-weight: 700;
}

.world-detail-table {
  font-size: 15px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* --- Gauntlet Stages --- */
.gauntlet-stages {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stage-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: rgba(21, 26, 46, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.stage-card:hover {
  background: rgba(28, 34, 64, 0.9);
  border-color: rgba(255,255,255,0.15);
}

.stage-card.locked {
  opacity: 0.4;
  cursor: not-allowed;
}

.stage-card.completed {
  border-color: var(--green);
  border-left: 4px solid var(--green);
}

.stage-card.current {
  border-color: var(--accent);
  border-left: 4px solid var(--accent);
}

.stage-icon {
  font-size: 28px;
  width: 44px;
  text-align: center;
}

.stage-info {
  flex: 1;
}

.stage-name {
  font-size: 16px;
  font-weight: 600;
}

.stage-desc {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 2px;
}

.stage-check {
  font-size: 20px;
  color: var(--green);
}

/* --- Practice Screen --- */
.practice-bg {
  position: fixed;
  inset: 0;
  background-size: cover;
  background-position: center;
  filter: brightness(0.3);
  z-index: 0;
}

.practice-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  padding: 16px;
}

.practice-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 500px;
  margin-bottom: 16px;
}

.practice-stage-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
}

.practice-progress {
  font-size: 14px;
  color: var(--text-dim);
}

.practice-character {
  margin: 8px 0 16px;
}

.practice-character img {
  width: 120px;
  height: 120px;
  object-fit: contain;
  filter: drop-shadow(0 4px 16px rgba(0,0,0,0.5));
  animation: idle-bob 3s ease-in-out infinite;
  transition: transform 0.2s;
}

.practice-character img.correct-bounce {
  animation: squash-stretch 0.5s ease;
}

.practice-character img.wrong-shake {
  animation: shake 0.4s ease;
}

@keyframes squash-stretch {
  0% { transform: scale(1, 1); }
  30% { transform: scale(1.15, 0.85); }
  50% { transform: scale(0.9, 1.1); }
  70% { transform: scale(1.05, 0.95); }
  100% { transform: scale(1, 1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

.practice-card {
  background: rgba(21, 26, 46, 0.9);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.practice-question {
  font-size: 48px;
  font-weight: 700;
  margin-bottom: 24px;
  letter-spacing: 2px;
}

.practice-input-row {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.practice-input {
  width: 120px;
  padding: 12px 16px;
  font-size: 32px;
  font-weight: 600;
  text-align: center;
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
  -moz-appearance: textfield;
}

.practice-input::-webkit-outer-spin-button,
.practice-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

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

.practice-input.correct {
  border-color: var(--green);
  background: rgba(52, 211, 153, 0.1);
}

.practice-input.wrong {
  border-color: var(--red);
  background: rgba(248, 113, 113, 0.1);
}

.practice-submit {
  padding: 12px 24px;
  font-size: 20px;
  font-weight: 700;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.practice-submit:hover {
  background: #f59e0b;
}

.practice-submit:active {
  transform: scale(0.95);
}

.practice-feedback {
  margin-top: 16px;
  font-size: 18px;
  font-weight: 600;
  min-height: 28px;
}

.practice-feedback.correct {
  color: var(--green);
}

.practice-feedback.wrong {
  color: var(--red);
}

/* --- Timer --- */
.practice-timer {
  width: 100%;
  max-width: 400px;
  margin-top: 16px;
}

.timer-bar {
  height: 6px;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.1s linear;
}

/* --- Flash Cards --- */
.flashcard {
  background: rgba(21, 26, 46, 0.9);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 40px 32px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.flashcard-front {
  font-size: 48px;
  font-weight: 700;
  margin-bottom: 24px;
}

.flashcard-answer {
  font-size: 56px;
  font-weight: 700;
  color: var(--accent);
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-reveal, .btn-next-card {
  margin-top: 20px;
  padding: 12px 32px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-reveal {
  background: var(--blue);
  color: #fff;
}

.btn-reveal:hover {
  background: #3b82f6;
}

.btn-next-card {
  background: var(--accent);
  color: #000;
}

.btn-next-card:hover {
  background: #f59e0b;
}

/* --- Mastery Grid --- */
.mastery-container {
  padding: 20px;
  overflow: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.mastery-title {
  font-size: 20px;
  font-weight: 700;
}

.mastery-table {
  border-collapse: collapse;
  margin: 16px 0;
}

.mastery-table th,
.mastery-table td {
  width: 40px;
  height: 40px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid rgba(255,255,255,0.06);
}

.mastery-table th {
  color: var(--text-dim);
  background: rgba(255,255,255,0.03);
}

.mastery-table td {
  border-radius: 4px;
  cursor: default;
  transition: background 0.2s;
}

.mastery-table td.new       { background: rgba(255,255,255,0.04); color: var(--text-dim); }
.mastery-table td.learning  { background: rgba(251, 191, 36, 0.2); color: var(--accent); }
.mastery-table td.known     { background: rgba(96, 165, 250, 0.25); color: var(--blue); }
.mastery-table td.mastered  { background: rgba(52, 211, 153, 0.25); color: var(--green); }

.mastery-legend {
  display: flex;
  gap: 20px;
  margin-top: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
}

.legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 4px;
}

.legend-dot.new      { background: rgba(255,255,255,0.08); }
.legend-dot.learning { background: rgba(251, 191, 36, 0.35); }
.legend-dot.known    { background: rgba(96, 165, 250, 0.35); }
.legend-dot.mastered { background: rgba(52, 211, 153, 0.35); }

/* --- Overlay --- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.overlay-card {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 40px;
  max-width: 420px;
  width: 100%;
  text-align: center;
}

.overlay-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.overlay-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.overlay-subtitle {
  font-size: 15px;
  color: var(--text-dim);
  margin-bottom: 20px;
}

.overlay-stats {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 24px;
}

.btn-primary {
  padding: 14px 36px;
  font-size: 16px;
  font-weight: 700;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-primary:hover {
  background: #f59e0b;
}

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

/* --- Responsive --- */
@media (max-width: 600px) {
  .world-grid {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 12px;
  }

  .game-title { font-size: 17px; }
  .practice-question { font-size: 36px; }
  .practice-input { width: 100px; font-size: 28px; }

  .world-detail-header { margin: 16px 0 24px; }
  .world-detail-title { font-size: 22px; }
  .world-detail-char { width: 80px; height: 80px; }

  .mastery-table th,
  .mastery-table td {
    width: 30px;
    height: 30px;
    font-size: 11px;
  }
}
