:root {
  --bg-dark: #090d16;
  --bg-card: #131b2e;
  --bg-surface: #1e293b;
  --primary: #06b6d4;
  --primary-hover: #0891b2;
  --accent: #38bdf8;
  --gold: #f59e0b;
  --gold-glow: rgba(245, 158, 11, 0.4);
  --success: #10b981;
  --error: #ef4444;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #334155;
  --radius-lg: 16px;
  --radius-md: 10px;
  --font-main: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font-main);
  background: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(6, 182, 212, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(245, 158, 11, 0.08) 0%, transparent 40%);
}

/* Header & Controls */
header {
  padding: 1rem 1.5rem;
  background: rgba(19, 27, 46, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  font-size: 1.8rem;
}

.logo-text h1 {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: 0.5px;
}

.logo-text p {
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.btn-icon {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: var(--border-color);
  color: var(--accent);
}

/* Main Container */
main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* Screen Transitions */
.screen {
  display: none;
  animation: fadeIn 0.35s ease forwards;
}

.screen.active {
  display: block;
}

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

/* Screen 1: Welcome & Cadet Registration */
.welcome-card {
  max-width: 680px;
  margin: 0 auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  text-align: center;
}

.welcome-badge {
  display: inline-block;
  padding: 0.35rem 1rem;
  background: rgba(6, 182, 212, 0.15);
  border: 1px solid var(--primary);
  border-radius: 20px;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.welcome-card h2 {
  font-size: 2.2rem;
  font-weight: 800;
  margin-bottom: 0.75rem;
  color: var(--text-main);
}

.welcome-card p.lead {
  font-size: 1.05rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
  line-height: 1.5;
}

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

.form-group label {
  display: block;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  width: 100%;
  padding: 0.85rem 1.25rem;
  background: var(--bg-surface);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 1.1rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s ease;
}

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

.palette-selector {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}

.palette-btn {
  background: var(--bg-surface);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.5rem;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.palette-btn:hover {
  border-color: var(--primary);
}

.palette-btn.selected {
  border-color: var(--gold);
  background: rgba(245, 158, 11, 0.12);
  box-shadow: 0 0 12px var(--gold-glow);
}

.palette-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid #ffffff;
}

.palette-name {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-main);
}

.btn-primary {
  width: 100%;
  padding: 1rem 2rem;
  background: linear-gradient(135deg, var(--primary) 0%, #0284c7 100%);
  border: none;
  border-radius: var(--radius-md);
  color: #ffffff;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(6, 182, 212, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(6, 182, 212, 0.45);
}

.btn-primary:active {
  transform: translateY(0);
}

/* Screen 2: Robo-Assembly Lab */
.game-layout {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 2rem;
  align-items: start;
}

/* Left: Robot Stage Viewport */
.stage-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
}

.stage-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.stage-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.part-counter {
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--bg-surface);
  padding: 0.25rem 0.75rem;
  border-radius: 12px;
  font-weight: 600;
}

.stage-canvas-wrapper {
  width: 100%;
  max-width: 380px;
  height: 380px;
  background: radial-gradient(circle, #1e293b 0%, #0f172a 100%);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.robot-svg {
  width: 90%;
  height: 90%;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.5));
}

.part-just-added {
  animation: partSnap 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes partSnap {
  0% { transform: scale(1.35); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.latest-part-badge {
  margin-top: 1rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--gold);
  background: rgba(245, 158, 11, 0.1);
  padding: 0.5rem 1.25rem;
  border-radius: 20px;
  border: 1px solid var(--gold);
  text-align: center;
  width: 100%;
}

/* Right: Challenge Panel */
.challenge-panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.progress-bar-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  font-weight: 700;
}

.progress-track {
  width: 100%;
  height: 10px;
  background: var(--bg-surface);
  border-radius: 5px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--gold));
  border-radius: 5px;
  transition: width 0.4s ease;
}

.question-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
}

.question-meta {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 0.75rem;
}

.question-prompt {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.35;
  margin-bottom: 1.75rem;
}

.options-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.option-btn {
  background: var(--bg-surface);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.15rem 1rem;
  color: var(--text-main);
  font-size: 1.25rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: rgba(6, 182, 212, 0.1);
  transform: translateY(-2px);
}

.option-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.option-btn.wrong-shake {
  animation: shake 0.4s ease;
  border-color: var(--error);
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
}

.option-btn.correct-pop {
  border-color: var(--success);
  background: rgba(16, 185, 129, 0.2);
  color: #86efac;
  transform: scale(1.02);
}

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

/* Hint Drawer */
.hint-drawer {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid var(--gold);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: none;
  animation: fadeIn 0.3s ease forwards;
}

.hint-drawer.active {
  display: block;
}

.hint-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--gold);
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}

.hint-text {
  font-size: 0.95rem;
  color: #fde68a;
  line-height: 1.5;
}

.helper-action {
  margin-top: 1rem;
}

.btn-secondary {
  padding: 0.75rem 1.25rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-secondary:hover {
  background: var(--border-color);
  color: var(--accent);
}

/* Screen 3: Certificate Showcase */
.certificate-view {
  max-width: 1000px;
  margin: 0 auto;
  text-align: center;
}

.certificate-header-badge {
  font-size: 1rem;
  font-weight: 700;
  color: var(--gold);
  background: rgba(245, 158, 11, 0.15);
  padding: 0.4rem 1.25rem;
  border-radius: 20px;
  border: 1px solid var(--gold);
  display: inline-block;
  margin-bottom: 0.75rem;
}

.certificate-view h2 {
  font-size: 2.2rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
}

.certificate-view p.lead {
  font-size: 1.1rem;
  color: var(--text-muted);
  margin-bottom: 1.75rem;
}

.canvas-container {
  width: 100%;
  margin: 0 auto 2rem auto;
  background: #020617;
  border-radius: var(--radius-lg);
  padding: 1rem;
  border: 2px solid var(--gold);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6), 0 0 25px var(--gold-glow);
  display: flex;
  justify-content: center;
}

#certificate-canvas {
  width: 100%;
  max-width: 900px;
  height: auto;
  display: block;
  border-radius: 8px;
}

.certificate-actions {
  display: flex;
  justify-content: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.btn-cert {
  padding: 1rem 1.75rem;
  border-radius: var(--radius-md);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  transition: all 0.2s ease;
  border: none;
}

.btn-cert-download {
  background: linear-gradient(135deg, var(--gold) 0%, #d97706 100%);
  color: #0f172a;
  box-shadow: 0 8px 20px rgba(245, 158, 11, 0.35);
}

.btn-cert-download:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 26px rgba(245, 158, 11, 0.45);
}

.btn-cert-print {
  background: var(--bg-surface);
  border: 2px solid var(--primary);
  color: var(--accent);
}

.btn-cert-print:hover {
  background: rgba(6, 182, 212, 0.15);
  transform: translateY(-2px);
}

.btn-cert-restart {
  background: var(--bg-surface);
  border: 2px solid var(--border-color);
  color: var(--text-muted);
}

.btn-cert-restart:hover {
  color: var(--text-main);
  border-color: var(--text-main);
}

/* Print Media Stylesheet */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }

  header, .certificate-actions, .certificate-header-badge, .certificate-view h2, .certificate-view p.lead {
    display: none !important;
  }

  main {
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
  }

  .canvas-container {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
  }

  #certificate-canvas {
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* Responsive adjustments */
@media (max-width: 860px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .stage-canvas-wrapper {
    height: 300px;
  }

  .options-grid {
    grid-template-columns: 1fr;
  }
}
