:root {
  --bg-gradient: linear-gradient(135deg, #e0f2fe 0%, #f3e8ff 100%);
  --font-main: 'Fredoka', 'Nunito', system-ui, sans-serif;
  --text-dark: #1e293b;
  --text-muted: #64748b;
  
  --red-a: #ff4757;
  --red-b: #ff6b81;
  --yellow-a: #ffa502;
  --yellow-b: #eccc68;
  --blue-a: #1e90ff;
  --blue-b: #70a1ff;

  --card-shadow: 0 12px 30px rgba(30, 41, 59, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg-gradient);
  color: var(--text-dark);
  font-family: var(--font-main);
  min-height: 100vh;
}

.hidden { display: none !important; }

header {
  height: 70px;
  background: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 6%;
  box-shadow: 0 4px 15px rgba(0,0,0,0.05);
  position: sticky;
  top: 0;
  z-index: 10;
}
.logo { font-size: 22px; font-weight: 700; color: #3b82f6; }
.badge {
  font-size: 13px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 99px;
  color: white;
  background: #94a3b8;
}

.screen { display: none; padding: 30px 5%; }
.screen.active { display: block; animation: fadeIn 0.3s ease-out; }

.hero { text-align: center; max-width: 900px; margin: 5vh auto; }
.hero h1 { font-size: clamp(32px, 5vw, 54px); color: #0f172a; margin: 15px 0; }
.hero p { font-size: 20px; color: var(--text-muted); margin-bottom: 35px; }

.pill-tag {
  background: #e0e7ff;
  color: #4338ca;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 16px;
  border-radius: 99px;
  letter-spacing: 0.05em;
  display: inline-block;
}

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }
.card-btn {
  background: white;
  border: 4px solid #f1f5f9;
  border-radius: 28px;
  padding: 30px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: var(--card-shadow);
}
.card-btn:hover { transform: translateY(-8px) scale(1.02); }
.teacher-btn:hover { border-color: #3b82f6; }
.student-btn:hover { border-color: #2ed573; }
.individual-btn:hover { border-color: #ffa502; }

.card-icon { font-size: 48px; }
.card-btn strong { font-size: 22px; color: var(--text-dark); }
.card-btn small { color: var(--text-muted); font-size: 14px; }

.wrap { max-width: 1100px; margin: auto; }
.narrow { max-width: 580px; margin-left: auto; margin-right: auto; }
.head { display: flex; justify-content: space-between; align-items: center; gap: 15px; margin-bottom: 20px; }
.head h2 { margin: 5px 0; font-size: 32px; }

.panel {
  background: white;
  border-radius: 24px;
  padding: 25px;
  margin-bottom: 20px;
  box-shadow: var(--card-shadow);
  border: 3px solid #f8fafc;
}
.highlight-panel { border: 3px solid #60a5fa; background: #eff6ff; }
.center { text-align: center; }
.code { font-size: 56px; font-weight: 800; letter-spacing: 0.15em; color: #2563eb; margin: 10px 0; }
.sub-text { color: var(--text-muted); font-size: 15px; }

/* Buttons */
.btn {
  border: none;
  border-radius: 16px;
  padding: 12px 22px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 4px 0 rgba(0,0,0,0.15);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.15); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none!important; box-shadow: none; }
.btn-primary { background: #3b82f6; color: white; }
.btn-success { background: #2ed573; color: white; }
.btn-danger { background: #ff4757; color: white; }
.btn-full { width: 100%; margin-top: 15px; padding: 16px; font-size: 18px; }
.back-btn { background: #e2e8f0; color: #334155; }
.btn-lg { font-size: 20px; padding: 16px 28px; }

/* Form inputs */
label { display: block; font-weight: 700; margin: 15px 0 6px; color: var(--text-dark); }
input, select, textarea {
  width: 100%;
  border: 3px solid #cbd5e1;
  border-radius: 16px;
  padding: 14px;
  font-family: inherit;
  font-size: 16px;
  background: #f8fafc;
  outline: none;
  transition: border-color 0.2s;
}
input:focus, select:focus, textarea:focus { border-color: #3b82f6; background: white; }

/* Host Grid Layout */
.count-tag { background: #3b82f6; color: white; padding: 4px 12px; border-radius: 99px; font-size: 14px; }
.teams-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.team-card {
  border-radius: 20px;
  padding: 18px;
  background: #f8fafc;
  border: 4px solid #cbd5e1;
  position: relative;
  transition: transform 0.2s;
}
.team-card.has-players { background: white; }
.team-card.team-Red-A { border-color: var(--red-a); }
.team-card.team-Red-B { border-color: var(--red-b); }
.team-card.team-Yellow-A { border-color: var(--yellow-a); }
.team-card.team-Yellow-B { border-color: var(--yellow-b); }
.team-card.team-Blue-A { border-color: var(--blue-a); }
.team-card.team-Blue-B { border-color: var(--blue-b); }

.team-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.team-name { font-size: 20px; font-weight: 800; }
.team-score { font-size: 24px; font-weight: 800; color: #0f172a; background: #f1f5f9; padding: 4px 12px; border-radius: 12px; }
.team-players { font-size: 14px; color: var(--text-muted); min-height: 40px; display: flex; flex-wrap: wrap; gap: 6px; }
.player-pill { background: #e2e8f0; padding: 3px 10px; border-radius: 99px; font-weight: 700; color: #1e293b; }

/* Live Leaderboard Modal Items */
.leaderboard-modal-list { display: flex; flex-direction: column; gap: 10px; margin-top: 15px; }
.lb-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-radius: 16px;
  background: #f8fafc;
  border: 2px solid #e2e8f0;
}
.lb-row.my-own-team { border-color: #3b82f6; background: #eff6ff; font-weight: bold; }
.lb-rank { font-size: 20px; font-weight: 800; width: 40px; }
.lb-info { flex-grow: 1; }
.lb-score { font-size: 22px; font-weight: 800; color: #2563eb; }

/* Game progress bar */
.team-badge { background: #3b82f6; color: white; font-weight: 800; padding: 6px 16px; border-radius: 99px; }
.score-badge { background: #0f172a; color: white; padding: 8px 18px; border-radius: 16px; font-size: 14px; }
.score-badge b { font-size: 26px; color: #facc15; margin-left: 6px; }
.bar-container { height: 16px; background: #e2e8f0; border-radius: 99px; overflow: hidden; margin-bottom: 25px; }
.bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, #3b82f6, #2ed573); transition: width 0.3s ease; }

/* MCQ */
.question h3 { font-size: 24px; color: #0f172a; }
.options-grid { display: grid; gap: 12px; margin-top: 20px; }
.opt-btn {
  background: white;
  border: 3px solid #e2e8f0;
  padding: 16px 20px;
  border-radius: 18px;
  font-size: 18px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s;
}
.opt-btn:hover { border-color: #3b82f6; background: #eff6ff; }
.timer-box { font-size: 32px; font-weight: 800; color: #ef4444; text-align: center; margin-bottom: 10px; }

/* Drag & Drop Sequence */
.seq-list { display: flex; flex-direction: column; gap: 12px; margin: 20px 0; }
.seq-item {
  background: white;
  border: 3px solid #cbd5e1;
  padding: 16px 20px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 18px;
  font-weight: 700;
  cursor: grab;
  user-select: none;
  transition: transform 0.15s, border-color 0.15s;
}
.seq-item.dragging { opacity: 0.4; border-color: #3b82f6; background: #eff6ff; }
.seq-item.success-flash { border-color: #2ed573; background: #dcfce7; animation: bounce 0.4s; }
.drag-handle { color: #94a3b8; font-size: 20px; margin-right: 12px; }

/* Robot Game Layout Fix */
.robotLayout { display: grid; grid-template-columns: 1fr 320px; gap: 24px; align-items: start; }
.robotGrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; background: #cbd5e1; padding: 12px; border-radius: 20px; max-width: 500px; margin: 0 auto; }
.cell { aspect-ratio: 1; background: white; border-radius: 12px; display: grid; place-items: center; font-size: 28px; }
.cell.wall { background: #475569; }
.cell.goal { background: #bbf7d0; border: 3px solid #22c55e; }
.cell.robot { background: #fef08a; border: 3px solid #f59e0b; }

.command-box {
  background: #f8fafc;
  border: 2px dashed #cbd5e1;
  padding: 12px;
  border-radius: 16px;
  min-height: 80px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-content: flex-start;
  margin: 10px 0;
}
.cmd-chip {
  background: #3b82f6;
  color: white;
  padding: 6px 12px;
  border-radius: 12px;
  font-weight: 800;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: grab;
  user-select: none;
}
.cmd-chip.dragging { opacity: 0.4; }
.cmd-del-btn {
  background: rgba(255,255,255,0.25);
  border: none;
  color: white;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
}
.cmd-del-btn:hover { background: #ef4444; }

.control-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 15px 0; }
.control-pad button:first-child { grid-column: 2; }

/* Certificate */
.certificate {
  background: white;
  border: 12px solid #3b82f6;
  border-radius: 36px;
  padding: 50px 30px;
  text-align: center;
  box-shadow: var(--card-shadow);
}
.cert-star { font-size: 48px; }
.certificate h1 { font-size: 42px; color: #1e3a8a; margin: 10px 0; }
.certificate h2 { font-size: 48px; color: #2563eb; text-decoration: underline; margin: 20px 0; }
.cert-p { font-size: 18px; color: var(--text-muted); }
.finalScore { background: #fef3c7; border: 3px solid #f59e0b; padding: 15px; border-radius: 20px; display: inline-block; font-weight: 800; margin: 20px 0; font-size: 18px; }
.finalScore b { font-size: 46px; color: #d97706; }
.cert-actions { margin-top: 30px; display: flex; justify-content: center; gap: 15px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.7); display: grid; place-items: center; z-index: 100; }
.winnerCard { background: white; border-radius: 32px; padding: 40px; text-align: center; max-width: 500px; width: 90%; }
.big-emoji { font-size: 80px; }
.feedback-msg { text-align: center; font-size: 20px; font-weight: 800; margin-top: 15px; min-height: 30px; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes bounce { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.03); } }

@media(max-width: 850px) {
  .robotLayout { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr; }
}
@media print {
  header, .cert-actions { display: none!important; }
  .screen { padding: 0; }
  .certificate { border-width: 6px; }
}
