
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Trebuchet MS", Arial, sans-serif;
  color: #20334c;
  background: linear-gradient(135deg, #eaffef, #fffbe8, #f4efff);
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
  padding: 20px 5%;
  background: #ffffffd9;
  border-bottom: 1px solid #e4dcff;
}

.brand {
  color: #6046ed;
  font-size: 25px;
  font-weight: 900;
}

.subtitle {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 2px;
}

.game {
  max-width: 1600px;
  margin: auto;
  padding: 28px 3% 40px;
}

.question-box {
  text-align: center;
  background: white;
  border: 2px solid #e8d9ff;
  border-radius: 28px;
  padding: 18px 12px 25px;
  box-shadow: 0 12px 35px #293d5510;
}

.small-label {
  color: #7255ec;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 2px;
}

.question-box h1 {
  margin: 5px 0;
  font-size: clamp(44px, 7vw, 78px);
}

.question-box p {
  margin-bottom: 0;
  color: #68778a;
}

.play-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px minmax(0, 1fr);
  align-items: center;
  gap: 25px;
  margin-top: 48px;
}

.answer-card {
  min-height: 300px;
  border: 0;
  border-radius: 34px;
  color: white;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 18px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 15px 30px #1d2b401b;
}

.answer-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 20px 35px #1d2b4030;
}

.answer-card:focus-visible,
.controls button:focus-visible {
  outline: 4px solid #202f48;
  outline-offset: 4px;
}

.left-card {
  background: linear-gradient(145deg, #20b5e0, #258bd2);
}

.right-card {
  background: linear-gradient(145deg, #ff684e, #ff493e);
}

.arrow {
  font-size: 48px;
}

.answer-card strong {
  font-size: clamp(36px, 4vw, 58px);
}

.answer-card span:last-child {
  font-size: 16px;
  font-weight: 800;
  text-align: center;
}

.center-area {
  text-align: center;
  min-width: 0;
}

.camera-frame {
  width: 210px;
  height: 210px;
  margin: 0 auto 20px;
  border: 9px solid #5fbd75;
  border-radius: 50%;
  background: #dce9ed;
  overflow: hidden;
  position: relative;
  box-shadow: 0 10px 30px #315b3520;
}

#webcam {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

#cameraPlaceholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 45px;
  pointer-events: none;
}

.feedback {
  font-size: 23px;
  font-weight: 1000;
  color: #6449ed;
  text-align: center;
}

.feedback.good {
  color: #16984b;
}

.feedback.bad {
  color: #ef4d4d;
}

.feedback-image {
  display: none;
  width: min(32vw, 220px);
  max-width: 220px;
  height: auto;
  margin: 0 auto 12px;
  object-fit: contain;
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.18));
  transform: scale(0.7) rotate(-8deg);
  opacity: 0;
}

.feedback-image.visible {
  display: block;
  animation: feedbackPop 0.45s ease forwards;
}

@keyframes feedbackPop {
  0% {
    opacity: 0;
    transform: scale(0.55) rotate(-10deg);
  }
  70% {
    opacity: 1;
    transform: scale(1.08) rotate(3deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

#instruction {
  font-size: 14px;
  color: #596b82;
  font-weight: 700;
}

.status {
  color: #7c8795;
  font-size: 12px;
  font-weight: 900;
  margin: 12px 0;
}

.game-stats {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: #ffffff;
  border: 2px solid #e4dcff;
  border-radius: 20px;
  font-size: 15px;
  font-weight: 900;
  box-shadow: 0 4px 12px rgba(96, 70, 237, 0.08);
  transition: all 0.2s ease;
}

#score {
  color: #6046ed;
}

#timer {
  color: #ff5263;
}

#timer.warning {
  color: #d92027;
  border-color: #ff5263;
  background: #fff0f2;
  animation: timerWarning 0.6s infinite alternate ease-in-out;
}

@keyframes timerWarning {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.08);
  }
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 55px;
}

.controls button {
  border: 0;
  padding: 16px 25px;
  border-radius: 16px;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
}

.start-btn {
  background: #604cf1;
  color: white;
}

.stop-btn {
  background: #ff5263;
  color: white;
}

.restart-btn {
  background: white;
  color: #604cf1;
  border: 2px solid #604cf1 !important;
}

.tip {
  margin-top: 28px;
  text-align: center;
  color: #66758a;
  font-size: 13px;
  line-height: 1.7;
}

footer {
  text-align: center;
  padding: 20px;
  color: #758094;
  font-size: 13px;
}

@media (max-width: 850px) {
  .play-area {
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-top: 25px;
  }

  .center-area {
    grid-column: 1 / -1;
    grid-row: 1;
    margin-bottom: 15px;
  }

  .answer-card {
    min-height: 190px;
    border-radius: 24px;
    gap: 10px;
  }

  .camera-frame {
    width: 175px;
    height: 175px;
  }

  .subtitle {
    text-align: right;
    font-size: 10px;
  }
}

/* ====================================================
   TEACHER OPTIONS & QUESTION MANAGER (Down Side)
   ==================================================== */
.teacher-section {
  max-width: 860px;
  margin: 45px auto 20px;
  background: #ffffff;
  border: 2px solid #e4dcff;
  border-radius: 24px;
  padding: 24px 28px;
  box-shadow: 0 10px 30px rgba(96, 70, 237, 0.08);
}

.teacher-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.teacher-badge {
  display: inline-block;
  background: #f0ecff;
  color: #6046ed;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1.5px;
  padding: 4px 10px;
  border-radius: 12px;
  margin-bottom: 6px;
}

.teacher-info h2 {
  margin: 0 0 4px 0;
  font-size: 22px;
  color: #20334c;
}

.teacher-info p {
  margin: 0;
  color: #6b7c93;
  font-size: 14px;
}

.teacher-toggle-btn {
  padding: 12px 22px;
  border: 2px solid #6046ed;
  border-radius: 14px;
  background: #6046ed;
  color: white;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.teacher-toggle-btn:hover {
  background: #4f36db;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(96, 70, 237, 0.25);
}

.teacher-toggle-btn.open {
  background: white;
  color: #6046ed;
}

.question-panel {
  margin-top: 24px;
  padding-top: 22px;
  border-top: 2px dashed #ece7ff;
}

.question-panel[hidden] {
  display: none;
}

.teacher-mode-selector {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  background: #fbf9ff;
  padding: 12px 18px;
  border-radius: 14px;
  border: 1px solid #e7dfff;
  flex-wrap: wrap;
}

.teacher-mode-selector select {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1.5px solid #d4c8f5;
  font-size: 14px;
  font-weight: bold;
  color: #20334c;
  background: white;
}

.tab-buttons {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.tab-btn {
  flex: 1;
  min-width: 180px;
  padding: 11px 18px;
  background: #f4efff;
  color: #6046ed;
  border: 2px solid transparent;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

.tab-btn.active {
  background: #6046ed;
  color: white;
  border-color: #6046ed;
  box-shadow: 0 4px 12px rgba(96, 70, 237, 0.2);
}

.teacher-form {
  background: #fdfcff;
  border: 1.5px solid #eae5f8;
  border-radius: 16px;
  padding: 18px 20px;
  margin-bottom: 22px;
}

.teacher-form[hidden] {
  display: none;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 14px;
  align-items: end;
}

.form-row.full-width {
  grid-template-columns: 1fr;
  margin-bottom: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 800;
  color: #42526e;
}

.form-group input,
.form-group select {
  padding: 10px 14px;
  border: 1.5px solid #d4c8f5;
  border-radius: 10px;
  font-size: 15px;
  color: #20334c;
  outline: none;
  background: white;
  transition: border-color 0.2s ease;
}

.form-group input:focus,
.form-group select:focus {
  border-color: #6046ed;
  box-shadow: 0 0 0 3px rgba(96, 70, 237, 0.15);
}

.form-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

.btn-teacher-primary {
  padding: 11px 24px;
  background: #16984b;
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-teacher-primary:hover {
  background: #11783a;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(22, 152, 75, 0.25);
}

.btn-teacher-outline {
  padding: 8px 14px;
  background: transparent;
  color: #6046ed;
  border: 1.5px solid #6046ed;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-teacher-outline:hover {
  background: #f0ecff;
}

.question-message {
  min-height: 22px;
  margin: 10px 0 15px;
  font-size: 14px;
  font-weight: 800;
}

.question-message.success {
  color: #16984b;
}

.question-message.error {
  color: #ef4d4d;
}

.saved-questions-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 22px 0 12px;
  flex-wrap: wrap;
  gap: 10px;
}

.saved-questions-header h3 {
  margin: 0;
  font-size: 17px;
  color: #20334c;
}

.question-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 380px;
  overflow-y: auto;
}

.question-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: #fbf9ff;
  border: 1px solid #e7dfff;
  border-radius: 14px;
  transition: all 0.2s ease;
}

.question-item:hover {
  background: #f5f0ff;
  border-color: #d8cbff;
}

.question-item-text {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.question-item-title {
  font-size: 16px;
  font-weight: 900;
  color: #20334c;
}

.answer-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
}

.chip-correct {
  background: #e2f8ec;
  color: #12803e;
}

.chip-wrong {
  background: #ffebe9;
  color: #cc2f26;
}

.btn-delete-q {
  padding: 6px 12px;
  background: #fff;
  border: 1px solid #ffccd0;
  color: #e53945;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-delete-q:hover {
  background: #ffebeb;
  border-color: #e53945;
}

.empty-questions-notice {
  padding: 24px;
  text-align: center;
  color: #8391a5;
  font-style: italic;
  font-size: 14px;
  background: #faf9fd;
  border-radius: 12px;
}

@media (max-width: 420px) {
  .game {
    padding-inline: 12px;
  }

  .answer-card {
    min-height: 155px;
    padding: 10px;
  }

  .answer-card span:last-child {
    font-size: 12px;
  }

  .controls button {
    padding: 13px 16px;
    font-size: 14px;
  }

  .teacher-section {
    padding: 18px 14px;
  }

  .teacher-toggle-btn {
    width: 100%;
  }

  .form-actions {
    justify-content: stretch;
  }

  .btn-teacher-primary {
    width: 100%;
  }
}
