:root {
  --portal-bg-a: #f6fbff;
  --portal-bg-b: #fff5eb;
}

body.portal-page {
  min-height: 100vh;
  background:
    radial-gradient(900px 500px at -10% -20%, #d7efff 0%, transparent 65%),
    radial-gradient(900px 600px at 120% 0%, #ffe5cf 0%, transparent 60%),
    linear-gradient(140deg, var(--portal-bg-a), var(--portal-bg-b));
  color: #162635;
}

.portal-shell {
  max-width: 1200px;
}

.api-input {
  max-width: 320px;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(0, 0, 0, 0.08);
  font-size: 0.86rem;
}

.profile-menu-slot {
  display: inline-flex;
  justify-content: flex-end;
  position: relative;
}

.profile-menu {
  position: relative;
}

.profile-menu-trigger {
  width: 2.8rem;
  height: 2.8rem;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
  overflow: hidden;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease,
    border-color 0.15s ease;
}

.profile-menu-trigger:hover,
.profile-menu-trigger:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(37, 99, 235, 0.35);
  box-shadow: 0 14px 28px rgba(37, 99, 235, 0.14);
}

.profile-avatar-image,
.profile-avatar-fallback {
  width: 100%;
  height: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.profile-avatar-image {
  object-fit: cover;
}

.profile-avatar-fallback {
  background: linear-gradient(145deg, #dbeafe, #fde7d6);
  color: #1e3a5f;
  font-weight: 700;
  font-size: 1.05rem;
}

.profile-menu-panel {
  position: absolute;
  top: calc(100% + 0.75rem);
  right: 0;
  left: auto;
  width: min(320px, calc(100vw - 24px));
  min-width: 270px;
  max-width: calc(100vw - 24px);
  padding: 0.85rem;
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(15, 23, 42, 0.09);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.16);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease,
    visibility 0.18s ease;
  z-index: 60;
}

.profile-menu.is-open .profile-menu-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.profile-menu-summary {
  display: grid;
  grid-template-columns: 3.1rem minmax(0, 1fr);
  gap: 0.8rem;
  align-items: center;
  padding-bottom: 0.8rem;
  margin-bottom: 0.8rem;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
}

.profile-menu-summary-avatar {
  width: 3.1rem;
  height: 3.1rem;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(15, 23, 42, 0.08);
}

.profile-menu-name {
  font-weight: 700;
  line-height: 1.2;
}

.profile-menu-email {
  font-size: 0.86rem;
  color: #64748b;
  overflow-wrap: anywhere;
}

.profile-menu-role {
  margin-top: 0.18rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: #31577b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.profile-menu-actions {
  display: grid;
  gap: 0.35rem;
}

.profile-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0.7rem 0.8rem;
  border: 0;
  border-radius: 0.8rem;
  background: transparent;
  color: #162635;
  text-decoration: none;
  font-weight: 600;
}

.profile-menu-item:hover,
.profile-menu-item:focus-visible {
  background: #eff6ff;
  color: #0f3b70;
}

.profile-menu-item-danger:hover,
.profile-menu-item-danger:focus-visible {
  background: #fff1f2;
  color: #be123c;
}

.account-summary {
  display: grid;
  grid-template-columns: 4.75rem minmax(0, 1fr);
  gap: 1rem;
  align-items: center;
}

.account-avatar {
  width: 4.75rem;
  height: 4.75rem;
  border-radius: 999px;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #dbeafe, #fde7d6);
  color: #1e3a5f;
  font-weight: 700;
  font-size: 1.65rem;
  border: 1px solid rgba(15, 23, 42, 0.08);
}

.account-avatar-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hero-copy {
  max-width: 68ch;
}

.panel-card {
  border: 0;
  box-shadow: 0 8px 28px rgba(15, 35, 52, 0.08);
}

.exam-list,
.question-list,
.attempt-area {
  display: grid;
  gap: 0.75rem;
}

.exam-card {
  border: 1px solid rgba(0, 0, 0, 0.09);
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.92);
  padding: 0.8rem;
  display: grid;
  gap: 0.45rem;
}

.exam-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.exam-meta {
  color: #5f6d7a;
  font-size: 0.9rem;
}

.exam-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.attempt-question {
  border: 1px solid rgba(0, 0, 0, 0.09);
  border-radius: 0.7rem;
  background: rgba(255, 255, 255, 0.94);
  padding: 0.75rem;
}

.attempt-question-title {
  margin-bottom: 0.2rem;
}

.attempt-options {
  margin-top: 0.45rem;
  display: grid;
  gap: 0.35rem;
}

.attempt-option-row {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  color: #334155;
  line-height: 1.35;
}

.attempt-option-row input[type="checkbox"] {
  margin-top: 0.2rem;
  flex: 0 0 auto;
}

.attempt-option-prefix {
  min-width: 1.6rem;
  font-weight: 700;
  padding-top: 0.02rem;
  color: #334155;
}

.attempt-option-text {
  flex: 1;
  min-width: 0;
}

.prompt-rich {
  display: block;
  width: 100%;
}

.prompt-text-segment {
  white-space: pre-wrap;
}

.prompt-bold {
  font-weight: 700;
  white-space: pre-wrap;
}

.prompt-inline-code {
  display: inline;
  border-radius: 0.35rem;
  background: #ecf0ff;
  color: #2d3e7c;
  border: 1px solid #cdd6ff;
  padding: 0.04rem 0.32rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.86em;
}

.prompt-code-block {
  margin: 0.35rem 0;
  border: 1px solid #1d3448;
  border-radius: 0.55rem;
  background: #0f1f2f;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.84rem;
}

.prompt-code-lang {
  display: inline-block;
  margin: 0.35rem 0.45rem 0.2rem;
  padding: 0.08rem 0.4rem;
  border-radius: 999px;
  background: rgba(110, 231, 255, 0.12);
  color: #8be9fd;
  border: 1px solid rgba(139, 233, 253, 0.35);
  font-size: 0.68rem;
  text-transform: lowercase;
}

.prompt-code-line {
  display: grid;
  grid-template-columns: 2.25rem minmax(0, 1fr);
}

.prompt-code-ln {
  text-align: right;
  padding: 0.25rem 0.45rem;
  color: #89a6c5;
  border-right: 1px solid rgba(138, 166, 197, 0.35);
  background: rgba(5, 14, 23, 0.45);
  user-select: none;
}

.prompt-code-content {
  color: #dbeafe;
  padding: 0.25rem 0.55rem;
  white-space: pre;
}

.prompt-rich .katex-display {
  margin: 0.55rem 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 0.15rem;
}

.prompt-rich .katex {
  max-width: 100%;
}

.asymptote-preview {
  display: block;
  width: 100%;
  overflow: auto;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 0.55rem;
  padding: 0.45rem;
  background: #ffffff;
}

.asymptote-preview svg {
  display: block;
  max-width: 100%;
  height: auto;
}

.stat-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.stat-card {
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.9);
  padding: 0.7rem;
  display: grid;
  gap: 0.2rem;
}

.stat-card strong {
  font-size: 1.35rem;
}

.table-wrap {
  overflow-x: auto;
}

.app-log {
  min-height: 110px;
  max-height: 260px;
  overflow: auto;
  border-radius: 0.65rem;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #132634;
  color: #d8ecff;
  padding: 0.75rem;
  font-size: 0.84rem;
  margin-bottom: 0;
}

.pending-status {
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 0.7rem;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.92);
}

@media (max-width: 575px) {
  .profile-menu-panel {
    min-width: min(270px, calc(100vw - 24px));
  }

  .account-summary {
    grid-template-columns: 1fr;
    justify-items: start;
  }
}
