:root {
  color-scheme: light;
  --ink: #172126;
  --muted: #63727a;
  --line: #dce5e7;
  --paper: #fbfdfc;
  --mint: #24b47e;
  --teal: #0f766e;
  --coral: #f9735b;
  --gold: #f4b942;
  --blue: #2f6df6;
  --soft: #eef8f4;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.share-logo {
  position: absolute;
  left: -1000px;
  top: 0;
  width: 300px;
  height: 300px;
  opacity: 0.01;
  pointer-events: none;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(36, 180, 126, 0.14), transparent 32rem),
    linear-gradient(135deg, #f8fbf9 0%, #eef6f8 48%, #fff6ef 100%);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.stage {
  min-height: calc(100vh - 36px);
  border: 1px solid rgba(23, 33, 38, 0.08);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(18px);
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 22px 60px rgba(25, 69, 76, 0.12);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 22px clamp(18px, 4vw, 38px);
}

.brand-head {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-logo {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
}

.eyebrow,
.session-label {
  margin: 0 0 5px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(26px, 4vw, 44px);
  line-height: 1.05;
}

.role-switch,
.tabs,
.filters {
  display: flex;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
}

.role-switch {
  display: none;
}

.role-btn,
.tab,
.filter {
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 9px 14px;
  white-space: nowrap;
}

.role-btn.is-active,
.tab.is-active,
.filter.is-active {
  color: #fff;
  background: var(--ink);
}

.hero-band {
  display: none;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: center;
  padding: clamp(20px, 4vw, 42px);
  background: linear-gradient(120deg, rgba(15, 118, 110, 0.98), rgba(36, 180, 126, 0.9));
  background-size: cover;
  background-position: center;
  color: #fff;
}

.hero-band.is-open {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  place-content: center;
  place-items: center;
  min-height: 100vh;
  max-height: 100vh;
  overflow: auto;
  padding: clamp(24px, 6vw, 64px);
}

.qr-close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-size: 28px;
  line-height: 1;
}

.session-code {
  font-size: clamp(40px, 8vw, 86px);
  font-weight: 900;
  line-height: 1;
}

.session-text {
  max-width: 620px;
  margin-top: 12px;
  font-size: clamp(15px, 2.2vw, 20px);
  line-height: 1.7;
}

.qr-panel {
  display: grid;
  gap: 10px;
  justify-items: center;
  align-self: center;
  justify-self: center;
  padding: 14px;
  border-radius: 18px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 18px 38px rgba(8, 41, 39, 0.22);
  font-weight: 800;
}

.view {
  display: none;
  padding: clamp(18px, 4vw, 34px);
}

.view.is-visible {
  display: block;
}

/* Role-based safety: never force-show the other role's view */
html[data-entry-role="student"] #teacherView,
html[data-entry-role="teacher"] #studentView {
  display: none !important;
}

/* Hide teacher-only controls on student entry even if layout glitches */
html[data-entry-role="student"] .teacher-toolbar,
html[data-entry-role="student"] .teacher-grid {
  display: none !important;
}

.composer {
  display: grid;
  gap: 14px;
  max-width: 760px;
  margin: 0 auto 26px;
}

textarea,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  outline: 0;
}

textarea {
  resize: vertical;
  min-height: 110px;
  padding: 16px;
  line-height: 1.6;
}

input {
  height: 44px;
  padding: 0 13px;
}

textarea:focus,
input:focus {
  border-color: var(--mint);
  box-shadow: 0 0 0 4px rgba(36, 180, 126, 0.14);
}

.composer-actions {
  display: grid;
  grid-template-columns: minmax(100px, 160px) 1fr;
  gap: 10px;
}

#sendBtn,
.comment-form button {
  border: 0;
  border-radius: 14px;
  color: #fff;
  background: var(--mint);
  font-weight: 800;
}

#sendBtn {
  min-height: 55px;
  font-size: 16px;
}

.feed-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}

.feed,
.priority-list,
.feeling-wall {
  display: grid;
  gap: 12px;
}

.post {
  display: block;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.badge {
  border-radius: 999px;
  padding: 3px 8px;
  color: #fff;
  background: var(--blue);
  font-size: 12px;
  font-weight: 800;
}

.badge.feeling {
  background: var(--coral);
}

.content {
  margin-top: 9px;
  line-height: 1.65;
  word-break: break-word;
}

.post-actions {
  display: flex;
  gap: 22px;
  align-items: center;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid #eef3f3;
}

.icon-btn {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  min-width: 54px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #8a9a9f;
  font-weight: 800;
}

.like-btn.is-liked {
  color: var(--coral);
  background: #fff2ef;
}

.like-icon,
.comment-icon {
  font-size: 20px;
  line-height: 1;
}

.comments {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}

.comment {
  padding: 8px 10px;
  border-radius: 8px;
  background: #f4f8f8;
  color: #38484e;
  font-size: 14px;
  line-height: 1.5;
}

.comment-sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
}

.comment-sheet.is-open {
  display: block;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  border: 0;
  background: rgba(23, 33, 38, 0.36);
}

.sheet-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  gap: 12px;
  padding: 18px;
  border-radius: 24px 24px 0 0;
  background: #fff;
  box-shadow: 0 -18px 40px rgba(23, 33, 38, 0.18);
}

.sheet-head,
.sheet-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.sheet-head button {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 999px;
  background: #f2f6f6;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}

.sheet-panel textarea {
  min-height: 140px;
  border: 0;
  border-radius: 0;
  padding: 4px 0;
  box-shadow: none;
}

.sheet-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
}

.sheet-actions button {
  height: 44px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: #9db8ff;
  font-weight: 900;
}

.teacher-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  gap: 18px;
}

.teacher-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 18px;
}

.teacher-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.teacher-actions button,
.teacher-actions a,
.teacher-actions select,
.history-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  padding: 0 14px;
  font-weight: 800;
  text-decoration: none;
}

.teacher-actions select {
  min-width: 116px;
  appearance: none;
}

#nextSessionBtn,
#statsBtn,
#showQrBtn,
#exportQuestionsBtn {
  color: #fff;
  border-color: var(--ink);
  background: var(--ink);
}

.lower-grid {
  margin-top: 18px;
}

.screen-card {
  min-height: 380px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
}

.section-title p {
  font-size: 22px;
  font-weight: 900;
}

.section-title span {
  color: var(--muted);
}

.priority .post:first-child {
  border-color: rgba(244, 185, 66, 0.72);
  background: #fffaf0;
}

.empty {
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.history-list,
.stats-charts {
  display: grid;
  gap: 12px;
}

.history-session {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.history-toggle {
  display: flex;
  justify-content: space-between;
  width: 100%;
  height: auto;
  min-height: 44px;
  border: 0;
  border-radius: 0;
  text-align: left;
}

.history-questions {
  display: none;
  gap: 8px;
  padding: 0 12px 12px;
}

.history-session.is-open .history-questions {
  display: grid;
}

.history-question {
  padding: 10px;
  border-radius: 8px;
  background: #f6f9f9;
  line-height: 1.5;
}

.stat-group {
  display: grid;
  gap: 8px;
}

.stat-title {
  font-weight: 900;
}

.stat-row {
  display: grid;
  grid-template-columns: minmax(92px, 150px) minmax(0, 1fr) 36px;
  gap: 8px;
  align-items: center;
  color: var(--muted);
}

.stat-bar {
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--mint), var(--gold));
}

@media (max-width: 780px) {
  .app-shell {
    padding: 0;
  }

  .stage {
    min-height: 100vh;
    border-radius: 0;
  }

  .topbar,
  .feed-head {
    align-items: stretch;
    flex-direction: column;
  }

  .hero-band.is-open {
    grid-template-columns: 1fr;
    gap: 18px;
    align-content: center;
    padding: 76px 22px 28px;
    text-align: center;
  }

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

  .teacher-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .qr-panel {
    justify-self: center;
  }

  .qr-panel canvas {
    width: min(68vw, 220px);
    height: min(68vw, 220px);
  }

  .session-text {
    margin-right: auto;
    margin-left: auto;
  }

  .composer-actions {
    grid-template-columns: 1fr;
  }
}

.pass-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(12, 18, 22, 0.55);
  z-index: 50;
}
.pass-modal.is-open { display: flex; }
.pass-panel {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  width: min(320px, 86vw);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.pass-panel input { padding: 10px 12px; border: 1px solid #cfd8dc; border-radius: 10px; }
.pass-panel button { padding: 10px 12px; border: none; border-radius: 10px; background: #172126; color: #fff; cursor: pointer; }
.pass-error { color: #c0392b; font-size: 13px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  background: rgba(23, 33, 38, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 60;
}
.toast[hidden] { display: none; }
