:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #152033;
  --muted: #667085;
  --line: #e4e7ec;
  --primary: #253b80;
  --primary-dark: #172554;
  --green: #18864b;
  --green-soft: #e8f7ef;
  --amber: #b56a00;
  --amber-soft: #fff4db;
  --red: #c53535;
  --red-soft: #fdecec;
  --shadow: 0 10px 30px rgba(20, 30, 55, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { font-size: .75rem; font-weight: 800; letter-spacing: .12em; color: var(--primary); }
h1, h2, h3, p { margin-top: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1.2rem clamp(1rem, 3vw, 2.5rem); background: white; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { margin: .2rem 0 0; font-size: clamp(1.3rem, 3vw, 2rem); }
.status-pill, .count-badge, .score-pill {
  display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px;
  padding: .45rem .7rem; background: #fff; font-weight: 700; font-size: .85rem;
}
.host-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(320px, 420px);
  gap: 1rem;
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.25rem;
}
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 1.2rem; box-shadow: var(--shadow); min-width: 0; }
.question-panel { grid-column: 1; }
.join-panel { grid-column: 1; }
.player-panel { grid-column: 2; grid-row: 1; }
.leaderboard-panel { grid-column: 2; grid-row: 2 / span 3; align-self: start; }
.explain-panel, .results-panel { grid-column: 1; }
.panel-title-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.join-layout { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.qr { width: 132px; height: 132px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.room-code { font-size: clamp(2.2rem, 7vw, 4.2rem); font-weight: 900; letter-spacing: .12em; line-height: 1; margin: .25rem 0 .5rem; }
.join-url { color: var(--muted); overflow-wrap: anywhere; font-size: .9rem; }
.settings-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem; }
label { display: grid; gap: .4rem; font-weight: 700; min-width: 0; }
select, input { width: 100%; min-width: 0; border: 1px solid #cfd5df; border-radius: 10px; padding: .75rem .8rem; background: #fff; color: var(--ink); }
.player-chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.player-chip { border: 1px solid var(--line); border-radius: 999px; padding: .42rem .7rem; background: #f9fafb; font-weight: 700; }
.player-chip.offline { opacity: .45; }
.question-meta, .player-status-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; color: var(--muted); font-weight: 800; font-size: .9rem; }
.question-panel h2 { font-size: clamp(1.5rem, 3vw, 2.4rem); line-height: 1.2; min-height: 3.2em; display: flex; align-items: center; }
.timer-track { width: 100%; height: 8px; border-radius: 999px; background: #edf0f5; overflow: hidden; margin: .65rem 0 1rem; }
.timer-fill { width: 0; height: 100%; background: var(--primary); transition: width .2s linear; }
.controls { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: 1rem; }
.button { border: 0; border-radius: 11px; padding: .78rem 1rem; font-weight: 800; }
.button.primary { background: var(--primary); color: #fff; }
.button.primary:hover { background: var(--primary-dark); }
.button.secondary { background: #eef2ff; color: var(--primary-dark); border: 1px solid #d7def5; }
.button:disabled { opacity: .4; cursor: not-allowed; }
.button.large { padding: 1rem 1.25rem; font-size: 1.05rem; }
.button.full { width: 100%; }
.link-button { background: transparent; border: 0; color: var(--primary); font-weight: 800; padding: .35rem; }
.response-status { margin: .8rem 0 0; color: var(--muted); font-weight: 700; }
.distribution { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin: 1rem 0; }
.dist { border-radius: 12px; padding: .8rem; display: flex; align-items: center; justify-content: space-between; font-weight: 900; }
.dist strong { font-size: 1.6rem; }
.dist.green { background: var(--green-soft); color: var(--green); }
.dist.amber { background: var(--amber-soft); color: var(--amber); }
.dist.red { background: var(--red-soft); color: var(--red); }
.reveal-box { border: 1px solid var(--line); border-radius: 14px; padding: 1rem; background: #fbfcfe; margin-top: 1rem; }
.correct-answer { font-size: 1.25rem; font-weight: 900; }
.correct-answer.GREEN { color: var(--green); }
.correct-answer.AMBER { color: var(--amber); }
.correct-answer.RED { color: var(--red); }
.scripture { color: var(--primary); font-weight: 800; }
.explainer-name { margin-top: 1rem; font-size: 1.6rem; font-weight: 900; color: var(--primary); }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .7rem .55rem; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
.answer-tag { display: inline-block; border-radius: 999px; padding: .25rem .55rem; font-weight: 900; font-size: .8rem; }
.answer-tag.GREEN { background: var(--green-soft); color: var(--green); }
.answer-tag.AMBER { background: var(--amber-soft); color: var(--amber); }
.answer-tag.RED { background: var(--red-soft); color: var(--red); }
.leaderboard { margin: .5rem 0 0; padding-left: 1.5rem; }
.leaderboard li { padding: .55rem .2rem; border-bottom: 1px solid var(--line); }
.leaderboard li strong { float: right; }
.leaderboard.compact li { padding: .4rem .2rem; }
.toast { position: fixed; z-index: 50; left: 50%; top: 1rem; transform: translateX(-50%); background: #111827; color: #fff; padding: .8rem 1rem; border-radius: 10px; box-shadow: var(--shadow); max-width: min(90vw, 520px); font-weight: 700; }

/* Landing */
.landing { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.landing-card { width: min(620px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 24px; padding: clamp(1.5rem, 5vw, 3.5rem); box-shadow: var(--shadow); text-align: center; }
.landing-card h1 { font-size: clamp(2.1rem, 7vw, 4rem); margin: .35rem 0 .8rem; }
.lead { color: var(--muted); font-size: 1.08rem; }
.landing-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin: 1.6rem 0; }
a.button { text-decoration: none; text-align: center; }
.privacy-note { color: var(--muted); font-size: .82rem; margin-bottom: 0; }

/* Player */
.player-body { min-height: 100vh; background: #eef2f8; }
.phone-shell { width: min(580px, 100%); margin: 0 auto; padding: 1rem; }
.phone-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .2rem .2rem 1rem; }
.phone-header h1 { font-size: 1.45rem; margin: .15rem 0 0; }
.connection-dot { width: 12px; height: 12px; border-radius: 50%; background: #9ca3af; box-shadow: 0 0 0 4px rgba(156,163,175,.15); }
.connection-dot.online { background: var(--green); box-shadow: 0 0 0 4px rgba(24,134,75,.15); }
.phone-card { background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.phone-card label { margin-bottom: .8rem; }
.phone-card input { font-size: 1rem; }
.player-name { font-weight: 900; }
.waiting-box { text-align: center; padding: 2.5rem 1rem; }
.pulse-dot { width: 18px; height: 18px; border-radius: 50%; background: var(--primary); margin: 0 auto 1rem; animation: pulse 1.3s infinite; }
@keyframes pulse { 0%,100% { transform: scale(.85); opacity: .5; } 50% { transform: scale(1.2); opacity: 1; } }
.phone-scenario { font-size: clamp(1.25rem, 5.5vw, 1.75rem); line-height: 1.25; }
.answer-buttons { display: grid; gap: .7rem; margin-top: 1rem; }
.answer-button { position: relative; border: 2px solid transparent; border-radius: 16px; padding: 1rem; display: grid; grid-template-columns: auto 1fr; column-gap: .75rem; text-align: left; align-items: center; font-weight: 900; font-size: 1.15rem; }
.answer-button small { grid-column: 2; font-size: .75rem; font-weight: 700; opacity: .8; }
.answer-dot { width: 19px; height: 19px; border-radius: 50%; grid-row: 1 / span 2; }
.answer-button.green { background: var(--green-soft); color: var(--green); }
.answer-button.green .answer-dot { background: var(--green); }
.answer-button.amber { background: var(--amber-soft); color: var(--amber); }
.answer-button.amber .answer-dot { background: var(--amber); }
.answer-button.red { background: var(--red-soft); color: var(--red); }
.answer-button.red .answer-dot { background: var(--red); }
.answer-button:disabled { opacity: .5; cursor: not-allowed; }
.answer-button.selected { border-color: currentColor; opacity: 1; transform: scale(1.01); }
.answer-status { min-height: 1.2rem; text-align: center; color: var(--muted); font-weight: 800; margin: .7rem 0 0; }
.round-points { margin-top: .8rem; font-size: 1.1rem; font-weight: 900; }
.explain-prompt { margin-top: 1rem; padding: 1rem; border-radius: 14px; background: #eef2ff; color: var(--primary-dark); font-weight: 900; text-align: center; }

@media (max-width: 850px) {
  .host-grid { grid-template-columns: 1fr; }
  .join-panel, .player-panel, .question-panel, .leaderboard-panel, .explain-panel, .results-panel { grid-column: 1; grid-row: auto; }
  .settings-row { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .join-layout { align-items: flex-start; }
  .qr { width: 104px; height: 104px; }
  .room-code { font-size: 2.4rem; }
  .landing-actions { grid-template-columns: 1fr; }
  .distribution { grid-template-columns: 1fr; }
}

/* RCCG HMS reusable classroom additions */
.topbar-subtitle { color: #d7def5; font-weight: 700; margin-top: .2rem; }
.phone-topic { color: var(--muted); font-size: .86rem; font-weight: 700; margin-top: .1rem; }
.topic-description { color: var(--muted); margin: .8rem 0 0; }
.settings-row.three { grid-template-columns: minmax(250px, 1.45fr) minmax(180px, 1fr) minmax(180px, 1fr); align-items: end; }
.answer-button { background: var(--choice-soft, #eef2ff); color: var(--choice-color, #3157A4); }
.answer-button .answer-dot { background: var(--choice-color, #3157A4); }
.answer-button.selected { border-color: var(--choice-color, #3157A4); opacity: 1; transform: scale(1.01); }
.answer-tag { background: #eef2ff; color: #3157A4; }


@media (max-width: 1200px) {
  .host-grid { grid-template-columns: minmax(0, 1fr) minmax(300px, 360px); }
  .settings-row.three { grid-template-columns: 1fr 1fr; }
  .settings-row.three label:first-child { grid-column: 1 / -1; }
}

@media (max-width: 980px) {
  .settings-row.three { grid-template-columns: 1fr; }
}

/* Teacher access */
.teacher-login-card { max-width: 520px; }
.teacher-login-form { display: grid; gap: .85rem; margin-top: 1.4rem; text-align: left; }
.teacher-login-form input { font-size: 1.05rem; }
.login-alert { margin: 1.2rem 0; padding: 1rem; border-radius: 12px; text-align: left; }
.login-alert.error { background: #fdecec; color: #8f2727; border: 1px solid #f2c5c5; }
.login-links { display: flex; justify-content: center; gap: 1rem; margin-top: 1.25rem; font-size: .92rem; }
.login-links a { color: var(--primary); font-weight: 800; text-decoration: none; }
.host-actions-top { display: flex; align-items: center; gap: .8rem; }
.host-actions-top .link-button { text-decoration: none; }
code { background: #f2f4f7; padding: .12rem .32rem; border-radius: 5px; }

/* ===== RCCG HMS teacher dashboard + mobile host update ===== */
textarea {
  width: 100%; min-width: 0; border: 1px solid #cfd5df; border-radius: 10px;
  padding: .75rem .8rem; background: #fff; color: var(--ink); font: inherit; resize: vertical;
}
.topbar-subtitle { color: var(--muted); }
.button.small { padding: .5rem .7rem; font-size: .85rem; }
.danger-link { color: #b42318 !important; }
.flash { max-width: 1100px; margin: 0 auto 1rem; padding: .85rem 1rem; border-radius: 12px; font-weight: 700; }
.flash.success { background: #e8f7ef; color: #12683a; border: 1px solid #c5ead5; }
.flash.error { background: #fdecec; color: #8f2727; border: 1px solid #f2c5c5; }

.teacher-page { max-width: 1180px; margin: 0 auto; padding: 1.25rem; }
.narrow-page { max-width: 820px; }
.teacher-topbar { position: static; }
.dashboard-actions { display: flex; flex-wrap: wrap; gap: .7rem; margin-bottom: 1.1rem; }
.teacher-section { margin: 1.5rem 0; }
.teacher-section > .panel-title-row { margin-bottom: .8rem; }
.teacher-section h2 { margin-bottom: .2rem; }
.lesson-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 1rem; }
.lesson-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 1rem; box-shadow: var(--shadow); min-width: 0; }
.lesson-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .7rem; }
.lesson-card h3 { margin: .2rem 0 .6rem; }
.lesson-type { color: var(--primary); text-transform: uppercase; letter-spacing: .05em; font-size: .72rem; font-weight: 900; }
.lesson-meta { color: var(--muted); font-size: .85rem; margin: .8rem 0; }
.status-pill.published { border-color: #b7e2ca; background: #e8f7ef; color: #12683a; }
.status-pill.draft { background: #fff6dd; color: #8d5b00; border-color: #f2d99a; }
.card-actions, .card-subactions, .template-buttons, .teacher-row-actions { display: flex; gap: .55rem; flex-wrap: wrap; align-items: center; }
.card-actions form, .card-subactions form, .teacher-row-actions form { margin: 0; }
.card-subactions { margin-top: .7rem; border-top: 1px solid var(--line); padding-top: .55rem; }
.clamp2 { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.empty-state { border: 1px dashed #cfd5df; border-radius: 14px; padding: 1rem; color: var(--muted); background: #fbfcfe; }
.transfer-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .5rem; margin-top: .8rem; }

.form-grid { display: grid; gap: 1rem; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.editor-meta { display: grid; gap: 1rem; }
.toggle-stack { display: grid; gap: .65rem; align-content: end; }
.check-label { display: flex; align-items: center; gap: .55rem; font-weight: 700; }
.check-label input { width: auto; min-width: auto; }
.question-editor { display: grid; gap: 1rem; }
.question-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 1rem; box-shadow: var(--shadow); display: grid; gap: .85rem; }
.question-card-head { display: flex; justify-content: space-between; align-items: center; gap: .7rem; }
.question-card-head h3 { margin: 0; }
.question-card-head .link-button:disabled { opacity: .25; cursor: not-allowed; }
.option-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; }
.traffic-choice-preview { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.traffic { text-align: center; border-radius: 12px; padding: .7rem; font-weight: 900; }
.traffic.green { color: var(--green); background: var(--green-soft); }
.traffic.amber { color: var(--amber); background: var(--amber-soft); }
.traffic.red { color: var(--red); background: var(--red-soft); }
.sticky-save { position: sticky; bottom: .7rem; display: flex; justify-content: flex-end; gap: .7rem; margin-top: 1rem; padding: .75rem; background: rgba(245,247,251,.94); backdrop-filter: blur(8px); border: 1px solid var(--line); border-radius: 14px; z-index: 4; }

.preview-list { display: grid; gap: 1rem; }
.preview-question { border-top: 1px solid var(--line); padding-top: 1rem; }
.preview-question:first-child { border-top: 0; }
.preview-choices { display: grid; gap: .45rem; margin: .7rem 0; }
.preview-choice { padding: .65rem .8rem; border-radius: 10px; background: var(--choice-soft); color: var(--choice-color); display: flex; gap: .6rem; align-items: center; }
.preview-choice span { margin-left: auto; font-weight: 900; }
.preview-choice.correct { outline: 2px solid var(--choice-color); }

.admin-grid { display: grid; grid-template-columns: minmax(280px, .8fr) minmax(0, 1.5fr); gap: 1rem; }
.teacher-list { display: grid; gap: .6rem; }
.teacher-row { display: flex; justify-content: space-between; align-items: center; gap: .8rem; padding: .75rem 0; border-bottom: 1px solid var(--line); }
.credential-box { background: #eef2ff; border: 2px solid #cfd8ff; border-radius: 16px; padding: 1rem; margin-bottom: 1rem; }
.credential-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.credential-grid > div { background: #fff; border-radius: 10px; padding: .8rem; }
.credential-grid span { display: block; color: var(--muted); font-size: .8rem; }
.credential-grid strong { display: block; font-size: 1.1rem; margin-top: .2rem; word-break: break-all; }

/* Mobile host-screen improvement patch */
@media (max-width: 700px) {
  .topbar { flex-direction: column; align-items: flex-start; padding: 1rem; position: static; }
  .host-actions-top { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  .host-grid { padding: .8rem; gap: .85rem; }
  .panel { padding: 1rem; border-radius: 16px; }
  .panel-title-row { flex-wrap: wrap; align-items: flex-start; }
  .join-layout { flex-direction: column; align-items: flex-start; }
  .join-layout > div { width: 100%; }
  .qr { width: 112px; height: 112px; }
  .room-code { font-size: clamp(2rem, 14vw, 3.4rem); letter-spacing: .08em; word-break: break-word; }
  .settings-row, .settings-row.three { grid-template-columns: 1fr !important; }
  .question-meta { flex-wrap: wrap; align-items: flex-start; gap: .35rem; }
  .question-panel h2 { min-height: 0; font-size: clamp(1.2rem, 7vw, 1.7rem); }
  .controls { flex-direction: column; }
  .controls .button { width: 100%; text-align: center; }
  .distribution { grid-template-columns: 1fr !important; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  th, td { padding: .55rem .45rem; font-size: .9rem; }
  .leaderboard { padding-left: 1.1rem; }
  .teacher-page { padding: .8rem; }
  .lesson-grid { grid-template-columns: 1fr; }
  .form-grid.two, .option-grid, .traffic-choice-preview, .admin-grid, .credential-grid { grid-template-columns: 1fr; }
  .sticky-save { flex-direction: column; }
  .sticky-save .button { width: 100%; }
  .teacher-row { align-items: flex-start; flex-direction: column; }
  .teacher-row-actions { width: 100%; }
  .teacher-row-actions form { flex: 1; }
  .teacher-row-actions .button { width: 100%; }
  .transfer-form { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .topbar h1 { font-size: 1.2rem; }
  .eyebrow { font-size: .68rem; }
  .room-code { font-size: 1.85rem; }
  .status-pill, .count-badge, .score-pill { font-size: .78rem; padding: .38rem .58rem; }
  .button { padding: .72rem .9rem; }
}

/* HMS website integration */
.game-logo { width: 112px; height: 112px; object-fit: contain; margin: 0 auto 18px; display: block; }
.home-link { display: inline-block; margin-top: 24px; color: inherit; opacity: .75; text-decoration: none; }
.home-link:hover { opacity: 1; text-decoration: underline; }
