:root {
  color-scheme: light;
  --ink: #111827;
  --muted: #667085;
  --line: #e5e7eb;
  --panel: #ffffff;
  --bg: #f6f7fb;
  --brand: #2f6fed;
  --brand-dark: #174bb8;
  --bubble-prof: #f1f4f9;
  --bubble-student: #2f6fed;
  --green: #22a566;
  --green-soft: #e9f8ef;
  --red: #e5484d;
  --red-soft: #fdecec;
  --shadow: 0 18px 45px rgba(15, 23, 42, .12);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 15% 10%, rgba(47, 111, 237, .12), transparent 24rem),
    radial-gradient(circle at 85% 0%, rgba(34, 165, 102, .12), transparent 20rem),
    var(--bg);
  color: var(--ink);
}

button { font: inherit; }

.is-hidden { display: none !important; }

.loading-screen,
.error-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 5px solid #dbeafe;
  border-top-color: var(--brand);
  border-radius: 999px;
  animation: spin .85s linear infinite;
}

.error-icon { font-size: 44px; }

.error-screen button {
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
}

.chat-shell {
  width: min(100%, 560px);
  min-height: 100vh;
  margin: 0 auto;
  background: rgba(255, 255, 255, .82);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.prof-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 32px 48px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(229, 231, 235, .9);
}

.back-home {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: #eef2f7;
  color: #344054;
  font-size: 22px;
  line-height: 1;
  text-decoration: none;
}

.prof-avatar {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: linear-gradient(135deg, #dbeafe, #c7f3d4);
  font-size: 24px;
  border: 2px solid #fff;
  box-shadow: 0 4px 10px rgba(15, 23, 42, .08);
}

.prof-info { line-height: 1.15; min-width: 0; }

.prof-name {
  font-weight: 950;
  font-size: 15px;
}

.prof-status {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.prof-status .dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(34, 165, 102, .18);
}

.area-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid #d9e2ef;
  border-radius: 999px;
  padding: 6px 10px;
  background: #fff;
  color: #344054;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.area-chip .caret { font-size: 10px; }

.meta-row {
  position: sticky;
  top: 68px;
  z-index: 9;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 14px 8px;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(229, 231, 235, .7);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 5px 10px;
  border: 1px solid #d9e2ef;
  border-radius: 999px;
  background: #f8fafc;
  color: #344054;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.chip.hot {
  border-color: #fed7aa;
  background: #fff7ed;
  color: #c2410c;
}

.chip.score {
  border-color: #f0d777;
  background: #fff8d9;
  color: #9a6b00;
}

.chip.muted { color: #64748b; }

.emoji {
  display: inline-grid;
  place-items: center;
  min-width: 1.35em;
  font-size: 1.35em;
  line-height: 1;
}

.feed {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 14px 200px;
  overflow-y: auto;
}

.day-marker {
  align-self: center;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .8);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.bubble {
  max-width: 86%;
  padding: 12px 14px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  animation: bubbleIn .26s cubic-bezier(.2, .8, .2, 1) both;
  box-shadow: 0 4px 14px rgba(15, 23, 42, .05);
}

.bubble.prof {
  align-self: flex-start;
  background: var(--bubble-prof);
  color: var(--ink);
  border-bottom-left-radius: 6px;
}

.bubble.student {
  align-self: flex-end;
  background: var(--bubble-student);
  color: #fff;
  border-bottom-right-radius: 6px;
  font-weight: 700;
}

.bubble.hint {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #174bb8;
}

.bubble.feedback-correct {
  background: var(--green-soft);
  border: 1px solid #bbf7d0;
}

.bubble.feedback-wrong {
  background: var(--red-soft);
  border: 1px solid #fecaca;
}

.bubble .kicker {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.bubble .kicker.ok { color: #166534; }
.bubble .kicker.bad { color: #991b1b; }

.bubble.question .question-body {
  margin-top: 4px;
}

.bubble .img-warn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 8px;
  padding: 4px 8px;
  border-radius: 6px;
  background: #fef3c7;
  color: #92400e;
  font-size: 11px;
  font-weight: 800;
}

.typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 14px 16px;
  background: var(--bubble-prof);
  border-radius: 16px;
  border-bottom-left-radius: 6px;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #94a3b8;
  animation: typingDot 1.1s infinite ease-in-out;
}

.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }

.composer {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 8;
  width: min(100%, 560px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(229, 231, 235, .9);
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(14px);
}

.hint-btn {
  align-self: flex-start;
  border: 1px solid #d9e2ef;
  border-radius: 999px;
  padding: 7px 12px;
  background: #fff;
  color: #344054;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.hint-btn:disabled { opacity: .55; cursor: not-allowed; }

.answer-chips {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: 8px;
}

.answer {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 8px;
  align-items: start;
  min-height: 52px;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fff;
  text-align: left;
  cursor: pointer;
  transition: transform .14s ease, border-color .14s ease, background .14s ease;
}

.answer:hover { transform: translateY(-1px); border-color: var(--brand); }
.answer:active { transform: scale(.985); }

.answer .letter {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: #eef2f7;
  color: #344054;
  font-weight: 950;
  font-size: 13px;
}

.answer .text {
  padding-top: 3px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--ink);
}

.end-banner {
  margin: 12px 14px 200px;
  padding: 22px;
  border: 1px solid #bbf7d0;
  background: var(--green-soft);
  border-radius: 16px;
  text-align: center;
}

.end-emoji { font-size: 40px; }

.end-banner h2 {
  margin: 6px 0;
  font-size: 18px;
}

.end-banner p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
}

.primary-btn {
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  background: var(--brand);
  color: #fff;
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
}

.primary-btn:hover { background: var(--brand-dark); }

.ghost-btn {
  width: 100%;
  border: 1px solid #d9e2ef;
  border-radius: 12px;
  padding: 12px;
  background: #fff;
  color: #344054;
  font-weight: 800;
  cursor: pointer;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(15, 23, 42, .42);
  backdrop-filter: blur(2px);
}

.sheet-card {
  width: min(100%, 560px);
  background: #fff;
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: sheetUp .22s ease both;
}

.sheet-card h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 900;
}

.sheet-help {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
}

.sheet-options {
  display: grid;
  gap: 8px;
}

.area-option {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
  font-weight: 800;
  cursor: pointer;
  text-align: left;
}

.area-option.active {
  border-color: var(--brand);
  background: #eef5ff;
  color: var(--brand-dark);
}

.area-option .count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

@media (min-width: 800px) {
  .chat-shell {
    margin-top: 24px;
    margin-bottom: 24px;
    min-height: calc(100vh - 48px);
    border-radius: 18px;
    overflow: clip;
  }

  .composer {
    bottom: 24px;
    border-radius: 0 0 18px 18px;
  }
}

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(8px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: .6; }
  30% { transform: translateY(-4px); opacity: 1; }
}

@keyframes sheetUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
