:root {
  --bg: #0e1726;
  --panel: #16213a;
  --accent: #2f6df6;
  --accent2: #14b8a6;
  --text: #eaf0fb;
  --muted: #8ea0c0;
  --bar-bg: #223052;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: "Segoe UI", Arial, sans-serif; }
.hidden { display: none !important; }

/* ============ PRESENTER ============ */
body.present {
  background: #000;
  color: var(--text);
  overflow: hidden;
}
#stage {
  position: absolute; inset: 0 0 56px 0;
  display: flex; align-items: center; justify-content: center;
}
#slide-image { max-width: 100%; max-height: 100%; object-fit: contain; }

#slide-interactive {
  width: 100%; height: 100%;
  background: radial-gradient(circle at 50% 0%, #1b2b4d 0%, var(--bg) 70%);
  display: flex; flex-direction: column;
  padding: 4vh 6vw; gap: 3vh;
}
.q-prompt {
  font-size: 3.4vw; font-weight: 800; line-height: 1.15;
  text-align: center; padding-top: 1vh;
}
.q-results { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.q-count { text-align: center; color: var(--muted); font-size: 1.4vw; }

/* poll bars */
.bar-row { display: flex; align-items: center; gap: 1.2vw; margin: 1.1vh 0; }
.bar-label { width: 26%; font-size: 1.7vw; font-weight: 600; text-align: left; }
.bar-track { flex: 1; background: var(--bar-bg); border-radius: 10px; height: 5.2vh; position: relative; overflow: hidden; }
.bar-fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 10px; transition: width .5s cubic-bezier(.2,.8,.2,1);
}
.bar-val { position: absolute; inset: 0; display: flex; align-items: center;
  padding: 0 14px; font-weight: 800; font-size: 1.7vw; }

/* scale histogram */
.scale-wrap { display: flex; align-items: flex-end; justify-content: center; gap: 2vw; height: 46vh; }
.scale-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.scale-bar {
  width: 8vw; background: linear-gradient(180deg, var(--accent), var(--accent2));
  border-radius: 12px 12px 0 0; transition: height .5s cubic-bezier(.2,.8,.2,1);
  display: flex; align-items: flex-start; justify-content: center; color: #fff;
  font-weight: 800; font-size: 1.8vw; padding-top: 6px; min-height: 4px;
}
.scale-num { font-size: 2.4vw; font-weight: 800; margin-top: .6vh; }
.scale-avg { text-align: center; font-size: 2vw; margin-top: 2vh; }
.scale-avg b { color: var(--accent2); font-size: 3vw; }
.scale-labels { display: flex; justify-content: space-between; color: var(--muted);
  font-size: 1.4vw; margin-top: 1vh; padding: 0 3vw; }

/* word cloud */
.cloud { display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: .4em 1em; padding: 2vh; }
.cloud span { font-weight: 800; line-height: 1; transition: font-size .4s ease, color .4s ease; }

/* quiz bar states */
.bar-row.correct .bar-fill { background: linear-gradient(90deg, #29c07a, #14b8a6); }
.bar-row.correct .bar-label { color: #29c07a; }
.bar-row.dim { opacity: .45; }

/* timer (presenter) */
.q-timer {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  background: rgba(22,33,58,.9); border: 1px solid #2b3d64; border-radius: 999px;
  padding: 6px 22px; font-size: 2vw; font-weight: 800; z-index: 6;
}
.q-timer.urgent { color: #fff; background: #e0564a; border-color: #e0564a; }

/* leaderboard (presenter) */
.lb-board { display: flex; flex-direction: column; gap: 1.4vh; padding: 0 4vw; }
.lb-item { display: flex; align-items: center; gap: 1.4vw; }
.lb-medal { width: 3vw; font-size: 2.4vw; text-align: center; }
.lb-track { flex: 1; position: relative; height: 6vh; background: var(--bar-bg);
  border-radius: 10px; overflow: hidden; display: flex; align-items: center; }
.lb-fill { position: absolute; inset: 0 auto 0 0;
  background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 10px; transition: width .5s; }
.lb-name { position: relative; padding: 0 16px; font-size: 2vw; font-weight: 800; }
.lb-pts { position: relative; margin-right: auto; padding: 0 16px; font-size: 2vw; font-weight: 800; }
.lb-empty { text-align: center; color: var(--muted); font-size: 2vw; }

/* join panel */
#join-panel {
  position: absolute; bottom: 68px; left: 18px; z-index: 5;
  background: rgba(22,33,58,.92); border: 1px solid #2b3d64;
  border-radius: 14px; padding: 12px; text-align: center; backdrop-filter: blur(4px);
}
.join-title { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
#join-qr { width: 120px; height: 120px; background: #fff; border-radius: 8px; padding: 6px; }
.join-url { font-size: 13px; margin-top: 6px; direction: ltr; color: var(--accent2); font-weight: 700; }

/* lobby (pre-start) */
#lobby {
  position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2.2vh; text-align: center;
  background: radial-gradient(circle at 50% 0%, #1b2b4d 0%, var(--bg) 70%);
}
#lobby h1 { font-size: 4vw; margin: 0; }
.lobby-sub { color: var(--muted); font-size: 1.8vw; margin: 0; }
#lobby-qr { width: 34vh; height: 34vh; background: #fff; border-radius: 18px; padding: 14px; }
#lobby .join-url { font-size: 1.6vw; }
#btn-start {
  margin-top: 1vh; padding: 16px 42px; font-size: 1.8vw; font-weight: 800; cursor: pointer;
  color: #fff; border: none; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
}
#btn-start:hover { filter: brightness(1.08); }
.lobby-back { margin-top: .5vh; color: var(--muted); text-decoration: none; font-size: 1.2vw; }
.lobby-back:hover { color: var(--text); }

/* admin picker */
.admin-page { background: var(--bg); color: var(--text); min-height: 100vh; }
#admin { max-width: 1000px; margin: 0 auto; padding: 6vh 24px; }
.admin-head { text-align: center; margin-bottom: 4vh; }
.admin-head h1 { font-size: 2.6rem; margin: 0 0 6px; }
.admin-sub { color: var(--muted); margin: 0; }
.deck-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
.deck-card {
  display: block; text-decoration: none; color: var(--text);
  background: var(--panel); border: 1px solid #2b3d64; border-radius: 16px;
  padding: 22px; transition: transform .12s, border-color .12s, box-shadow .12s;
}
.deck-card:hover { transform: translateY(-3px); border-color: var(--accent2);
  box-shadow: 0 8px 26px rgba(0,0,0,.35); }
.deck-card.live { border-color: var(--accent2); }
.deck-num { color: var(--accent2); font-weight: 800; font-size: .95rem; }
.deck-title { font-size: 1.35rem; font-weight: 800; margin: 8px 0 10px; line-height: 1.25; }
.deck-meta { color: var(--muted); font-size: .9rem; }
.deck-badge { color: var(--accent2); font-weight: 700; font-size: .85rem; margin-top: 8px; }
.deck-go { margin-top: 16px; display: inline-block; font-weight: 700; color: var(--accent);
  background: rgba(47,109,246,.14); padding: 8px 16px; border-radius: 999px; }
.admin-empty { text-align: center; color: var(--text); margin-top: 8vh; }
.admin-empty code { background: var(--panel); padding: 2px 8px; border-radius: 6px; direction: ltr; display: inline-block; }

/* controls */
#controls {
  position: absolute; bottom: 0; left: 0; right: 0; height: 56px;
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: rgba(10,16,30,.9); border-top: 1px solid #223052;
}
#controls button {
  background: var(--panel); color: var(--text); border: 1px solid #2b3d64;
  border-radius: 8px; padding: 8px 14px; font-size: 15px; cursor: pointer;
}
#controls button:hover { background: #1e2c4d; }
#slide-pos { color: var(--muted); font-variant-numeric: tabular-nums; direction: ltr; }
.spacer { flex: 1; }
.conn { color: #e0564a; font-size: 20px; }
.conn.ok { color: #29c07a; }

/* ============ STUDENT ============ */
body.student {
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column; min-height: 100vh;
}
#s-header {
  background: var(--panel); padding: 14px 16px; font-weight: 700;
  border-bottom: 1px solid #223052; display: flex; align-items: center; gap: 10px;
}
#s-main { flex: 1; display: flex; flex-direction: column; justify-content: center;
  padding: 22px; gap: 20px; }
#s-waiting { text-align: center; color: var(--muted); }
.s-spinner {
  width: 46px; height: 46px; margin: 0 auto 18px; border-radius: 50%;
  border: 5px solid #223052; border-top-color: var(--accent); animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#s-prompt { font-size: 24px; line-height: 1.3; text-align: center; margin: 0 0 8px; }

#s-input { display: flex; flex-direction: column; gap: 12px; }
.opt-btn {
  background: var(--panel); color: var(--text); border: 2px solid #2b3d64;
  border-radius: 14px; padding: 18px; font-size: 20px; cursor: pointer; text-align: center;
}
.opt-btn:active { transform: scale(.98); }
.opt-btn.chosen { border-color: var(--accent2); background: #17324a; }

.scale-btns { display: flex; gap: 10px; justify-content: center; }
.scale-btns button {
  flex: 1; aspect-ratio: 1; font-size: 26px; font-weight: 800;
  border-radius: 14px; border: 2px solid #2b3d64; background: var(--panel); color: var(--text);
}
.scale-btns button.chosen { border-color: var(--accent2); background: #17324a; }
.scale-ends { display: flex; justify-content: space-between; color: var(--muted);
  font-size: 14px; margin-top: 8px; }

.wc-form { display: flex; flex-direction: column; gap: 12px; }
.wc-form input {
  padding: 16px; font-size: 20px; border-radius: 14px; border: 2px solid #2b3d64;
  background: var(--panel); color: var(--text); text-align: center;
}
.wc-form button, .send-btn {
  padding: 16px; font-size: 20px; font-weight: 700; border: none; border-radius: 14px;
  background: var(--accent); color: #fff; cursor: pointer;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip { background: #17324a; border: 1px solid var(--accent2); border-radius: 999px;
  padding: 6px 14px; font-size: 16px; }
.s-status { text-align: center; color: var(--accent2); font-size: 17px; min-height: 22px; }

/* name gate */
#s-namegate { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; }
.gate-box { text-align: center; width: 100%; max-width: 340px; }
.gate-box h1 { font-size: 26px; margin: 0 0 6px; }
.gate-box p { color: var(--muted); margin: 0 0 18px; }
.gate-box input {
  width: 100%; padding: 16px; font-size: 20px; text-align: center;
  border-radius: 14px; border: 2px solid #2b3d64; background: var(--panel); color: var(--text);
}
.gate-box button {
  width: 100%; margin-top: 12px; padding: 16px; font-size: 20px; font-weight: 700;
  border: none; border-radius: 14px; background: var(--accent); color: #fff;
}
#s-me { font-weight: 700; }

/* slide-follow image */
#s-image { flex: 1; display: flex; align-items: center; justify-content: center; padding: 8px; }
#s-slide-img { max-width: 100%; max-height: 100%; border-radius: 10px; }

/* student timer */
.s-timer { text-align: center; font-size: 30px; font-weight: 800; margin-bottom: 10px; color: var(--accent2); }
.s-timer.urgent { color: #e0564a; }

/* quiz feedback on phone */
.opt-btn.correct { border-color: #29c07a; background: #12331f; }
.opt-btn.wrong { border-color: #e0564a; background: #331717; }
.opt-btn:disabled { opacity: .8; }

/* student leaderboard */
#s-leaderboard { padding: 6px 4px; }
#s-leaderboard h1 { text-align: center; font-size: 24px; margin: 6px 0 12px; }
.lb-me { text-align: center; font-size: 18px; font-weight: 800; color: var(--accent2);
  background: #17324a; border-radius: 12px; padding: 10px; margin-bottom: 14px; }
.lb-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.lb-row { display: flex; align-items: center; gap: 12px; background: var(--panel);
  border: 1px solid #223052; border-radius: 12px; padding: 12px 14px; }
.lb-row.me { border-color: var(--accent2); background: #17324a; }
.lb-rank { width: 30px; text-align: center; font-weight: 800; font-size: 18px; }
.lb-name { flex: 1; font-weight: 700; }
.lb-score { font-weight: 800; color: var(--accent2); }
