:root {
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-alt: #f7f9fd;
  --text: #0f172a;
  --muted: #64748b;

  --primary: #0f3f7f;
  --primary-strong: #082e5f;
  --primary-soft: #d8e7fb;

  --accent: #0f766e;
  --accent-soft: #d6f3ef;

  --danger: #b91c1c;
  --danger-soft: #fee2e2;

  --success: #15803d;
  --success-soft: #dcfce7;

  --warning: #a16207;
  --warning-soft: #fef3c7;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  --shadow-sm: 0 3px 12px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 12px 24px rgba(15, 23, 42, 0.12);
  --shadow-lg: 0 22px 40px rgba(15, 23, 42, 0.2);

  --border: 1px solid #e2e8f0;
  --trans: 180ms ease;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  font-family: "Segoe UI", Tahoma, Verdana, sans-serif;
  background:
    radial-gradient(circle at 20% 0%, #dbeafe 0%, transparent 35%),
    radial-gradient(circle at 100% 100%, #cffafe 0%, transparent 30%), var(--bg);
  color: var(--text);
  overflow: hidden;
}

button,
select,
input {
  font: inherit;
}

.hidden {
  display: none !important;
}

.quiz-container {
  width: 100%;
  height: 100dvh;
  position: relative;
  overflow: hidden;
}

#home-screen,
#quiz-menu,
#profile-screen,
#study-setup,
#exam-setup,
#topic-library,
#topic-viewer,
#quiz-area,
#review-screen,
#dashboard,
#study-result-screen {
  display: none;
  width: 100%;
  height: 100%;
}

.screen-active {
  display: flex !important;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(15, 23, 42, 0.58);
  display: grid;
  place-items: center;
  padding: 20px;
  overflow-y: auto;
}

.modal-card {
  width: min(94vw, 420px);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: var(--border);
  padding: 24px;
  animation: rise 220ms ease;
}

.modal-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--primary-strong);
  margin-bottom: 8px;
}

.modal-text {
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 18px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--trans);
}

.modal-btn.secondary {
  background: #e2e8f0;
  color: #0f172a;
}

.modal-btn.secondary:hover {
  background: #cbd5e1;
}

.modal-btn.primary {
  background: var(--danger);
  color: #fff;
}

.modal-btn.primary:hover {
  filter: brightness(0.95);
}

.auth-modal-card {
  width: min(94vw, 460px);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.auth-tab-btn {
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  background: #f8fafc;
  color: #1e293b;
  font-weight: 700;
  padding: 9px 10px;
  cursor: pointer;
}

.auth-tab-btn.active {
  border-color: #0f3f7f;
  background: #dbeafe;
  color: #0b2d59;
}

.auth-form {
  display: grid;
  gap: 10px;
}

.auth-field {
  display: grid;
  gap: 6px;
}

.auth-field span {
  font-size: 12px;
  font-weight: 700;
  color: #334155;
}

.auth-field input {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font-size: 14px;
  color: #0f172a;
  background: #fff;
}

.auth-field select,
.auth-field input[type="file"] {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font-size: 14px;
  color: #0f172a;
  background: #fff;
}

.auth-field input:focus,
.auth-field select:focus {
  outline: 2px solid #93c5fd;
  outline-offset: 0;
  border-color: #60a5fa;
}

.auth-phone-grid {
  display: grid;
  grid-template-columns: minmax(120px, 180px) 1fr;
  gap: 8px;
}

.auth-field.field-invalid input,
.auth-field.field-invalid select {
  border-color: #dc2626;
  background: #fff7f7;
}

.auth-field.field-invalid input:focus,
.auth-field.field-invalid select:focus {
  outline-color: #fca5a5;
  border-color: #dc2626;
}

.field-error-text {
  margin-top: 5px;
  font-size: 12px;
  font-weight: 700;
  color: #b91c1c;
}

.auth-password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.auth-password-wrap input {
  padding-right: 42px;
}

.auth-password-toggle {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  cursor: pointer;
  width: auto;
  min-width: 28px;
  min-height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #0f3f7f;
  opacity: 0.8;
  transition: opacity 0.2s ease;
}

.auth-password-toggle:hover {
  opacity: 0.55;
}

.auth-password-toggle svg {
  width: 18px;
  height: 18px;
  display: block;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.auth-inline-options {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.auth-inline-options label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #334155;
}

.auth-link-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.auth-link-btn {
  border: none;
  background: transparent;
  color: #0f3f7f;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  padding: 2px 0;
}

.auth-link-btn:hover {
  text-decoration: underline;
}

.auth-error {
  font-size: 13px;
  font-weight: 600;
  color: #b91c1c;
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.auth-info {
  font-size: 13px;
  font-weight: 600;
  color: #0f3f7f;
  background: #dbeafe;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.profile-collapsible {
  display: grid;
  gap: 10px;
}

.profile-toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  width: min(680px, calc(100vw - 22px));
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.28);
}

/* Home */
#home-screen {
  align-items: center;
  justify-content: center;
  padding: 26px;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(140deg, rgba(8, 46, 95, 0.92), rgba(15, 118, 110, 0.86)),
    linear-gradient(180deg, #0f172a, #1e293b);
}

.portal-wrapper {
  width: min(94vw, 760px);
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  text-align: center;
  padding: 40px 34px;
  display: grid;
  gap: 24px;
  animation: rise 260ms ease;
}

.portal-top {
  display: grid;
  justify-items: center;
  gap: 16px;
}

.portal-authority {
  font-size: 12px;
  letter-spacing: 2px;
  font-weight: 700;
  color: #475569;
}

.portal-emblem {
  display: grid;
  place-items: center;
}

.emblem-shield {
  width: 82px;
  height: 102px;
  background: linear-gradient(180deg, #0f3f7f, #0c2f60);
  border-radius: 40px 40px 14px 14px;
  position: relative;
  box-shadow: 0 12px 20px rgba(15, 63, 127, 0.25);
}

.emblem-cross {
  width: 14px;
  height: 60px;
  background: #fff;
  position: absolute;
  left: 50%;
  top: 20px;
  transform: translateX(-50%);
}

.emblem-cross::after {
  content: "";
  position: absolute;
  width: 46px;
  height: 14px;
  left: -16px;
  top: 22px;
  background: #fff;
}

.portal-title {
  font-size: clamp(1.6rem, 2.6vw, 2rem);
  color: #0b2d59;
  margin-bottom: 10px;
}

.portal-description {
  color: #475569;
  line-height: 1.65;
  max-width: 560px;
  margin: 0 auto;
}

.portal-button {
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 26px;
  font-weight: 800;
  letter-spacing: 0.4px;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(160deg, var(--primary), var(--accent));
  box-shadow: var(--shadow-sm);
  transition:
    transform var(--trans),
    box-shadow var(--trans),
    filter var(--trans);
}

.portal-button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  filter: brightness(1.03);
}

.portal-signature {
  position: absolute;
  right: 24px;
  bottom: 16px;
  color: rgba(255, 255, 255, 0.7);
  letter-spacing: 3px;
  font-size: 11px;
}

/* Menu */
#quiz-menu {
  flex-direction: column;
  background: linear-gradient(180deg, #f7fbff 0%, #eef4ff 55%, #f2f8f3 100%);
  overflow-x: hidden;
}

.menu-fixed-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: linear-gradient(
    180deg,
    rgba(248, 251, 255, 0.97),
    rgba(248, 251, 255, 0.9)
  );
  backdrop-filter: blur(4px);
  border-bottom: var(--border);
}

.exam-identity-bar,
.study-identity-bar {
  text-align: center;
  padding: 10px 14px;
  font-size: 12px;
  letter-spacing: 1px;
  font-weight: 700;
  color: #e2e8f0;
  background: linear-gradient(160deg, #0f3f7f, #0f766e);
}

.menu-header,
.study-main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px clamp(16px, 4vw, 30px);
}

.menu-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "left profile"
    "actions actions";
  align-items: start;
  gap: 6px 10px;
}

.menu-header-left {
  grid-area: left;
  min-width: 0;
}

.menu-profile-stack {
  grid-area: profile;
  display: grid;
  justify-items: center;
  gap: 2px;
  width: 96px;
  justify-self: end;
}

.menu-header-actions {
  grid-area: actions;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 10px;
  flex-wrap: nowrap;
}

.menu-auth-user {
  font-size: 10px;
  font-weight: 600;
  color: #334155;
  opacity: 0.5;
  max-width: 150px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  text-align: right;
}

.profile-card {
  display: grid;
  gap: 16px;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.profile-avatar-row {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 14px;
  align-items: start;
}

.profile-avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 1px solid #cbd5e1;
  object-fit: cover;
  background: linear-gradient(135deg, #e2e8f0, #f8fafc);
}

.profile-avatar-controls {
  display: grid;
  gap: 10px;
}

.profile-photo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.profile-photo-actions .modal-btn {
  width: auto;
  min-height: 38px;
  padding: 8px 12px;
}

.profile-divider {
  height: 1px;
  background: #e2e8f0;
  margin: 4px 0;
}

.profile-danger-actions {
  justify-content: flex-start;
}

.menu-logout-btn {
  border: none;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-weight: 700;
  color: #fff;
  background: #b91c1c;
  cursor: pointer;
  transition: var(--trans);
}

.menu-logout-btn:hover {
  background: #991b1b;
}

.menu-profile-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  max-width: 36px;
  max-height: 36px;
  aspect-ratio: 1 / 1;
  flex: 0 0 36px;
  border: none;
  border-radius: 9999px !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #ffffff;
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.32), transparent 44%),
    linear-gradient(145deg, #2f6dc5, #1d4f99);
  box-shadow: 0 6px 14px rgba(15, 63, 127, 0.34);
  transition: transform var(--trans), box-shadow var(--trans), filter var(--trans);
  overflow: hidden;
  padding: 0;
  line-height: 0;
}

.menu-profile-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(15, 63, 127, 0.4);
  filter: saturate(1.05);
}

.menu-profile-btn.has-avatar {
  background: #dbeafe;
  border: 1px solid rgba(15, 63, 127, 0.2);
}

.menu-profile-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.menu-profile-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.menu-title,
.setup-page-title {
  color: #0b2d59;
  font-size: clamp(1.2rem, 2vw, 1.5rem);
  margin-bottom: 4px;
}

.menu-subtitle {
  color: #64748b;
  font-size: 0.94rem;
}

.menu-portal-btn,
.study-menu-btn {
  border: none;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-weight: 700;
  color: #0b2d59;
  background: #dbeafe;
  cursor: pointer;
  transition: var(--trans);
}

.menu-portal-btn:hover,
.study-menu-btn:hover {
  background: #bfdbfe;
}

#back-home-btn.menu-portal-btn {
  min-width: 96px;
  text-align: center;
}

.menu-scroll-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding: 26px;
  display: grid;
  place-items: center;
}

.study-scroll-content {
  overflow: auto;
  min-height: 0;
  padding: 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#profile-screen .study-scroll-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  align-items: center;
}

.menu-grid-single {
  width: min(760px, 100%);
  margin: 0 auto;
}

.menu-card {
  width: min(640px, 100%);
  margin: 0 auto;
  background: var(--surface);
  border: var(--border);
  border-top: 5px solid #0f3f7f;
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-lg);
  padding: clamp(16px, 2.5vw, 24px);
  overflow: visible;
}

.setup-card {
  width: min(720px, 100%);
  margin: 0 auto;
  background: var(--surface);
  border: var(--border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-lg);
  padding: clamp(16px, 2.5vw, 24px);
}

#study-setup .setup-card {
  border-top: 5px solid #0f766e;
  margin-top: auto;
  margin-bottom: auto;
}

#exam-setup .setup-card {
  border-top: 5px solid #1d4ed8;
  margin-top: auto;
  margin-bottom: auto;
}

.menu-section-title {
  color: #0f3f7f;
  font-size: 1.05rem;
  margin-bottom: 12px;
}

.analytics-heading {
  margin-top: 8px;
}

.menu-divider {
  margin: 16px 0;
  border-top: 1px dashed #cbd5e1;
}

.menu-tile {
  position: relative;
  z-index: 0;
  border: var(--border);
  background: #f8fbff;
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 10px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  transition:
    transform var(--trans),
    background var(--trans),
    border-color var(--trans),
    box-shadow var(--trans);
}

.menu-tile.study-mode {
  border-left: 6px solid #0f766e;
  background: linear-gradient(160deg, #f6fbf9, #eef8f4);
}

.menu-tile.exam-mode {
  border-left: 6px solid #1d4ed8;
  background: linear-gradient(160deg, #f6f9ff, #eef4ff);
}

.menu-tile.dashboard-mode {
  border-left: 6px solid #b45309;
  background: linear-gradient(160deg, #fffaf3, #fff5e7);
}

.menu-tile.topic-library-btn {
  width: 100%;
  text-decoration: none;
  text-align: left;
  color: inherit;
  border-left: 6px solid #7c2d12;
  background: linear-gradient(160deg, #fff8f1, #ffefd9);
}

.menu-tile.topic-library-btn:hover {
  background: #fff3e6;
  border-color: #f3cda6;
}

.menu-tile:hover {
  z-index: 20;
  transform: translateY(-1px);
  background: #eef6ff;
  border-color: #bfdbfe;
  box-shadow: var(--shadow-sm);
}

.tile-title {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 1rem;
  font-weight: 700;
}

.tile-icon {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: linear-gradient(145deg, #e8eef8, #dce6f5);
  border: 1px solid #c7d5eb;
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
}

.tile-arrow {
  color: #334155;
  font-size: 1.2rem;
  font-weight: 900;
}

.menu-tile::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 12px;
  right: auto;
  top: calc(100% + 8px);
  z-index: 30;
  background: rgba(15, 23, 42, 0.72);
  color: #e2e8f0;
  border: 1px solid rgba(148, 163, 184, 0.34);
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 18px rgba(15, 23, 42, 0.18);
  padding: 9px 11px;
  border-radius: 10px;
  font-size: 12px;
  width: min(250px, calc(100vw - 72px));
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: var(--trans);
}

.menu-tile:hover::after {
  opacity: 1;
  transform: translateY(0);
}
/* Setup */
.setup-page {
  flex-direction: column;
  background: linear-gradient(180deg, #f8fbff, #edf3fb);
}

.topic-screen-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.topic-library-card {
  border-top: 5px solid #7c2d12;
}

.topic-library-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.topic-library-count {
  margin-top: 6px;
  color: #475569;
  font-size: 0.9rem;
  font-weight: 700;
}

.topic-library-list {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.topic-library-item {
  width: 100%;
  border: var(--border);
  background: #ffffff;
  border-radius: var(--radius-md);
  padding: 11px 13px;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  transition: var(--trans);
}

.topic-library-item:hover {
  border-color: #d7dee8;
  background: #f8fafc;
}

.topic-library-item-title {
  font-size: 0.99rem;
  font-weight: 700;
  color: #0f172a;
  min-width: 0;
}

.topic-library-item-meta {
  margin-left: auto;
  color: #475569;
  font-size: 0.67rem;
  font-weight: 600;
  opacity: 0.48;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  max-width: 42%;
}

.topic-viewer-scroll {
  padding: 14px;
}

.topic-viewer-frame-wrap {
  width: min(1100px, 100%);
  margin: 0 auto;
}

#topic-viewer-frame {
  width: 100%;
  height: calc(100dvh - 145px);
  min-height: 520px;
  border: var(--border);
  border-radius: var(--radius-md);
  background: #fff;
}

.study-fixed-header {
  position: sticky;
  top: 0;
  z-index: 6;
  border-bottom: var(--border);
  background: #f8fbff;
}

.streak-badge-wrapper {
  display: flex;
  justify-content: center;
  margin-bottom: 18px;
}

.streak-badge {
  min-width: 170px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 999px;
  font-weight: 800;
  border: 1px solid transparent;
  box-shadow: var(--shadow-sm);
}

.streak-text {
  font-size: 0.9rem;
  opacity: 0.92;
}

.streak-number {
  background: rgba(255, 255, 255, 0.75);
  min-width: 36px;
  text-align: center;
  padding: 4px 10px;
  border-radius: 999px;
}

.study-control-row,
.exam-control-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.study-control-block {
  margin-bottom: 14px;
}

.study-control-block label {
  display: inline-block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: #334155;
  font-weight: 700;
}

.setup-select,
.setup-input {
  width: 100%;
  border: var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: #0f172a;
  padding: 11px 12px;
  outline: none;
  transition:
    border-color var(--trans),
    box-shadow var(--trans),
    background var(--trans);
}

.setup-select:focus,
.setup-input:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 4px rgba(147, 197, 253, 0.28);
  background: #fff;
}

.setup-card h3 {
  margin: 12px 0 8px;
  color: #0b2d59;
  font-size: 1rem;
}

.start-btn-wrapper {
  margin-top: 8px;
}

.start-btn {
  border: none;
  border-radius: var(--radius-md);
  padding: 11px 18px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(160deg, var(--primary), var(--accent));
  cursor: pointer;
  transition: var(--trans);
}

.start-btn:hover {
  filter: brightness(1.04);
  transform: translateY(-1px);
}

.start-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.study-footer {
  width: min(940px, 100%);
  margin: 16px auto 0;
  position: relative;
  z-index: 3;
}

.history-dropdown {
  position: relative;
  width: fit-content;
  max-width: 100%;
}

.history-toggle {
  cursor: pointer;
  padding: 12px 14px;
  font-weight: 800;
  color: #0f3f7f;
  background: linear-gradient(180deg, #edf5ff, #dbeafe);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-lg);
  box-shadow: 0 6px 14px rgba(59, 130, 246, 0.14);
}

.history-toggle.open {
  border-color: #93c5fd;
}

.history-content {
  position: absolute;
  left: 0;
  right: auto;
  bottom: calc(100% + 10px);
  width: min(360px, calc(100vw - 48px));
  max-height: 240px;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 8px 14px 12px;
  background: linear-gradient(180deg, #f6f9ff, #eaf2ff);
  border: 1px solid #c7ddff;
  border-radius: var(--radius-md);
  box-shadow: 0 12px 24px rgba(30, 64, 175, 0.14);
  z-index: 30;
}

/* Quiz Area */
#quiz-area {
  flex-direction: column;
  background: linear-gradient(180deg, #f8fbff, #edf3fb);
}

.quiz-layout {
  min-height: 100%;
}

.app-header {
  background: rgba(255, 255, 255, 0.92);
  border-bottom: var(--border);
  backdrop-filter: blur(4px);
  padding: 12px clamp(14px, 3vw, 24px);
  box-shadow: var(--shadow-sm);
}

.header-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
}

#mode-indicator {
  font-weight: 800;
  color: #0f3f7f;
}

.header-center-stats {
  justify-self: center;
}

.stats-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: #f1f5f9;
  border-radius: 999px;
  border: 1px solid #dbe2ea;
}

.score-inline,
.streak-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
}

.inline-label {
  color: #475569;
  font-size: 0.84rem;
}

.inline-value {
  color: #0b2d59;
  min-width: 20px;
}

.divider {
  width: 1px;
  height: 18px;
  background: #cbd5e1;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-btn {
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 1.02rem;
  font-weight: 900;
  color: #0f3f7f;
  background: #dbeafe;
  cursor: pointer;
  transition: var(--trans);
}

.header-btn:hover {
  background: #bfdbfe;
}

.header-btn.danger {
  color: #fff;
  background: #dc2626;
}

.header-btn.danger:hover {
  background: #b91c1c;
}

#quiz-area.mode-exam #back-btn-quiz,
#quiz-area.mode-smart #back-btn-quiz {
  background: #dc2626;
  color: transparent;
  font-size: 0;
}

#quiz-area.mode-exam #back-btn-quiz::before,
#quiz-area.mode-smart #back-btn-quiz::before {
  content: "✕";
  color: #fff;
  font-size: 1.02rem;
  font-weight: 900;
  line-height: 1;
}

#quiz-area.mode-exam #back-btn-quiz:hover,
#quiz-area.mode-smart #back-btn-quiz:hover {
  background: #b91c1c;
}

.header-meta {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #475569;
  font-size: 0.94rem;
  font-weight: 700;
}

#timer {
  padding: 6px 10px;
  border-radius: 999px;
  background: #e2e8f0;
}

#quiz-area.mode-exam .header-meta,
#quiz-area.mode-smart .header-meta {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

#quiz-area.mode-exam #progress,
#quiz-area.mode-smart #progress {
  justify-self: start;
}

#quiz-area.mode-exam #timer,
#quiz-area.mode-smart #timer {
  justify-self: center;
  min-width: 132px;
  padding: 9px 14px;
  font-size: 1.02rem;
  font-weight: 700;
  text-align: center;
}

.timer-safe {
  background: var(--success-soft) !important;
  color: var(--success);
}

.timer-warning {
  background: var(--warning-soft) !important;
  color: var(--warning);
}

.timer-danger {
  background: var(--danger-soft) !important;
  color: var(--danger);
  animation: pulse 0.85s ease-in-out infinite alternate;
}

.quiz-content {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: clamp(16px, 3vw, 26px);
}

.question-card-modern {
  width: min(940px, 100%);
  margin: 0 auto;
  background: var(--surface);
  border: var(--border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-lg);
  padding: clamp(14px, 2.3vw, 24px);
}

#question {
  color: #0b2d59;
  font-size: clamp(1.05rem, 2vw, 1.3rem);
  line-height: 1.45;
  margin-bottom: 14px;
}

#combo-block {
  background: #f8fafc;
  border: var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-bottom: 14px;
  display: grid;
  gap: 8px;
  color: #334155;
}

.answers-grid-modern {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

#answers button {
  text-align: left;
  border: var(--border);
  background: #f8fafc;
  color: #0f172a;
  border-radius: var(--radius-md);
  padding: 12px 13px;
  font-weight: 650;
  cursor: pointer;
  transition: var(--trans);
}

#answers button:hover:not(:disabled) {
  border-color: #93c5fd;
  background: #eff6ff;
}

#answers button:disabled {
  cursor: default;
}

#answers button.correct {
  border-color: #86efac;
  background: #f0fdf4;
  color: #14532d;
}

#answers button.wrong {
  border-color: #fecaca;
  background: #fef2f2;
  color: #7f1d1d;
}

.no-options-fallback {
  border: 1px solid #f59e0b;
  background: #fff7ed;
  color: #9a3412;
  border-radius: var(--radius-md);
  padding: 12px;
  font-weight: 700;
}

.explanation-modern {
  margin-top: 14px;
  border-radius: var(--radius-md);
  border-left: 4px solid #0f766e;
  background: #ecfeff;
  color: #155e75;
  padding: 11px 12px;
  line-height: 1.5;
}

.question-topic-link-wrap {
  margin-top: 10px;
}

.ai-explain-wrap {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.ai-explain-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ai-explain-meta {
  font-size: 12px;
  font-weight: 700;
  color: #475569;
}

.ai-explain-wrap .topic-link-btn {
  justify-self: start;
}

.ai-explain-close-btn {
  border-color: #fed7aa;
  background: #fff7ed;
  color: #9a3412;
}

.ai-explain-close-btn:hover {
  background: #ffedd5;
}

.ai-explain-wrap .topic-link-btn[disabled] {
  opacity: 0.65;
  cursor: not-allowed;
}

.topic-link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid #c7d2fe;
  background: #eef2ff;
  color: #3730a3;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
}

.topic-link-btn:hover {
  background: #e0e7ff;
}

.bottom-navigation {
  border-top: var(--border);
  background: rgba(255, 255, 255, 0.95);
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 10px;
}

.bottom-navigation button {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-weight: 750;
  cursor: pointer;
  background: #dbeafe;
  color: #0f3f7f;
  transition: var(--trans);
}

.bottom-navigation button:hover {
  background: #bfdbfe;
}

#next-btn {
  background: linear-gradient(160deg, var(--primary), var(--accent));
  color: #fff;
}

#next-btn:hover {
  filter: brightness(1.04);
}

#back-review-btn {
  background: #0f766e;
  color: #fff;
}

/* Review */
#review-screen {
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: linear-gradient(180deg, #f8fbff, #edf3fb);
}

.review-card {
  width: min(980px, 100%);
  max-height: 100%;
  overflow: auto;
  border-radius: var(--radius-lg);
  border: var(--border);
  box-shadow: var(--shadow-md);
  background: var(--surface);
  padding: clamp(14px, 2.5vw, 22px);
}

.review-title {
  color: #0b2d59;
  font-size: 1.35rem;
  font-weight: 900;
}

.review-timer {
  margin-top: 8px;
  font-weight: 800;
  color: #0f766e;
}

.review-legend {
  margin-top: 14px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  color: #334155;
}

.review-legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.review-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.review-grid,
#result-review-content.review-palette-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 8px;
  align-content: start;
  max-height: min(52dvh, 420px);
  overflow-y: auto;
  padding-right: 4px;
}

#result-review-content.analysis-list {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-content: start;
  max-height: min(52dvh, 420px);
  overflow-y: auto;
  padding-right: 4px;
}

.review-btn {
  border: none;
  border-radius: 10px;
  padding: 10px 0;
  font-weight: 800;
  cursor: pointer;
  color: #fff;
  background: #475569;
  transition: var(--trans);
}

.review-btn:hover {
  filter: brightness(1.05);
}

.review-answered,
.review-correct {
  background: #16a34a;
}

.review-unanswered,
.review-wrong,
.review-skipped {
  background: #dc2626;
}

/* Dashboard */
#dashboard {
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(180deg, #f8fbff, #edf3fb);
}

.dashboard-wrapper {
  width: min(1040px, 100%);
  max-height: 100%;
}

.dashboard-card {
  max-height: min(90dvh, 860px);
  overflow: hidden;
  background: var(--surface);
  border: var(--border);
  border-top: 5px solid #b45309;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.dashboard-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fbff;
  border-bottom: var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px;
}

.dashboard-title {
  color: #0b2d59;
  font-size: 1.25rem;
  font-weight: 900;
}

.dashboard-subtitle {
  color: #64748b;
  margin-top: 4px;
}

.dashboard-close-btn {
  border: none;
  border-radius: 10px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-weight: 900;
  color: #0f3f7f;
  background: #dbeafe;
}

.dashboard-close-btn:hover {
  background: #bfdbfe;
}

.dashboard-body {
  padding: 16px;
  overflow-y: auto;
  max-height: calc(min(90dvh, 860px) - 78px);
}

.dashboard-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.metric-tile {
  border: var(--border);
  border-radius: var(--radius-md);
  background: #f8fafc;
  padding: 12px;
}

.metric-label {
  color: #64748b;
  font-size: 0.84rem;
  font-weight: 700;
}

.metric-value {
  margin-top: 8px;
  font-size: 1.45rem;
  color: #0b2d59;
  font-weight: 900;
}

.dashboard-metrics .metric-tile:nth-child(1) {
  background: #f4f9ff;
  border-color: #d7e7ff;
}

.dashboard-metrics .metric-tile:nth-child(1) .metric-value {
  color: #1d4ed8;
}

.dashboard-metrics .metric-tile:nth-child(2) {
  background: #f3fcf6;
  border-color: #cfead8;
}

.dashboard-metrics .metric-tile:nth-child(2) .metric-value {
  color: #15803d;
}

.dashboard-metrics .metric-tile:nth-child(3) {
  background: #fff7f7;
  border-color: #f3d3d3;
}

.dashboard-metrics .metric-tile:nth-child(3) .metric-value {
  color: #b91c1c;
}

.dashboard-section-title {
  margin-top: 18px;
  margin-bottom: 12px;
  color: #0b2d59;
  font-weight: 900;
}

.dashboard-category-list {
  display: grid;
  gap: 10px;
}

.category-row {
  display: grid;
  grid-template-columns: minmax(140px, 1.2fr) minmax(120px, 3fr) auto;
  align-items: center;
  gap: 10px;
  border: var(--border);
  background: #f8fafc;
  border-radius: 12px;
  padding: 10px;
}

.category-name {
  font-weight: 800;
  color: #0f172a;
}

.category-meta {
  margin-top: 4px;
  font-size: 0.8rem;
  color: #64748b;
}

.category-bar {
  height: 10px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.category-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0f766e, #16a34a);
}

.category-percent {
  font-weight: 800;
  color: #0b2d59;
}

.no-data {
  border: var(--border);
  border-radius: var(--radius-md);
  background: #f8fafc;
  padding: 12px;
  color: #64748b;
}

/* Result Screen */
#study-result-screen {
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: linear-gradient(180deg, #f8fbff, #edf3fb);
}

.result-wrapper {
  width: min(940px, 100%);
  max-height: 100%;
}

.result-card {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: clamp(16px, 3vw, 24px);
  max-height: 100%;
  overflow: auto;
}

.result-title {
  font-size: 1.45rem;
  color: #0b2d59;
  font-weight: 900;
}

.result-body {
  margin-top: 14px;
}

.result-score-block {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 12px;
}

.result-percentage {
  font-size: 2rem;
  font-weight: 900;
  color: #0f766e;
}

.result-score {
  color: #334155;
  font-weight: 700;
}

.result-feedback {
  margin-top: 10px;
  color: #475569;
  font-weight: 700;
}

.review-section-title {
  margin-top: 16px;
  margin-bottom: 10px;
  color: #0f3f7f;
  font-weight: 900;
}

.analysis-card {
  border-radius: 12px;
  border: var(--border);
  padding: 12px;
  margin-bottom: 10px;
}

.analysis-card.analysis-clickable {
  cursor: pointer;
  transition: transform var(--trans), box-shadow var(--trans);
}

.analysis-card.analysis-clickable:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.analysis-correct {
  background: #f0fdf4;
  border-color: #86efac;
}

.analysis-wrong {
  background: #fef2f2;
  border-color: #fecaca;
}

.analysis-header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 800;
  margin-bottom: 8px;
}

.analysis-question {
  color: #1e293b;
  margin-bottom: 6px;
  line-height: 1.45;
}

.analysis-answer {
  color: #334155;
  margin-bottom: 4px;
}

.result-actions {
  margin-top: 16px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.result-btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-weight: 800;
  cursor: pointer;
}

.primary-btn {
  background: linear-gradient(160deg, var(--primary), var(--accent));
  color: #fff;
}

.secondary-btn {
  background: #e2e8f0;
  color: #0f172a;
}

.primary-btn:hover,
.secondary-btn:hover {
  filter: brightness(1.03);
}

/* Tier colors */
.tier-basic {
  background: #e2e8f0;
  color: #334155;
}

.tier-blue {
  background: #dbeafe;
  color: #1e40af;
}

.tier-green {
  background: #dcfce7;
  color: #166534;
}

.tier-gold {
  background: #fef3c7;
  color: #92400e;
}

.tier-fire {
  background: #fee2e2;
  color: #b91c1c;
}

.tier-legend {
  background: linear-gradient(130deg, #dbeafe, #fef3c7, #dcfce7);
  color: #0b2d59;
  border-color: #93c5fd;
}

.streak-animate {
  animation: pop 220ms ease;
}

/* Responsive */
@media (max-width: 980px) {
  .dashboard-metrics {
    grid-template-columns: 1fr;
  }

  .category-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .category-percent {
    justify-self: start;
  }
}

@media (max-width: 760px) {
  #study-setup .study-scroll-content,
  #exam-setup .study-scroll-content {
    flex: 1;
    min-height: 0;
  }

  #study-setup .setup-card,
  #exam-setup .setup-card {
    margin-top: auto;
    margin-bottom: auto;
  }

  .exam-identity-bar,
  .study-identity-bar {
    padding: 8px 12px;
    font-size: 11px;
  }

  .menu-header {
    align-items: start;
    gap: 6px 10px;
    padding: 10px 12px;
  }

  .menu-profile-stack {
    width: 96px;
    justify-self: end;
  }

  .menu-auth-user {
    text-align: right;
    max-width: 100%;
  }

  .menu-header-actions {
    width: 100%;
    justify-content: space-between;
    flex-wrap: nowrap;
  }

  .profile-avatar-row {
    grid-template-columns: 1fr;
  }

  .profile-photo-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .profile-photo-actions .modal-btn {
    width: 100%;
  }

  .auth-phone-grid {
    grid-template-columns: 1fr;
  }

  .profile-toast {
    top: 10px;
    width: min(96vw, 640px);
  }

  .menu-title {
    font-size: 1.1rem;
    line-height: 1.2;
    margin-bottom: 2px;
  }

  .menu-subtitle {
    font-size: 0.84rem;
  }

  #back-home-btn.menu-portal-btn {
    margin-left: auto;
    padding: 10px 14px;
    font-size: 1rem;
    border-radius: var(--radius-md);
  }

  .menu-card {
    width: min(560px, 100%);
    padding: 18px;
    border-radius: 20px;
  }

  .menu-scroll-content,
  .study-scroll-content,
  .quiz-content,
  #dashboard,
  #review-screen,
  #study-result-screen {
    padding: 14px;
  }

  .header-top {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "left right"
      "center center";
    align-items: start;
    gap: 8px 10px;
  }

  .header-left {
    grid-area: left;
    min-width: 0;
  }

  .header-center-stats {
    grid-area: center;
    justify-self: start;
  }

  .header-right {
    grid-area: right;
    justify-self: end;
    width: auto;
    justify-content: flex-end;
  }

  .header-meta {
    font-size: 0.64rem;
    gap: 4px;
    flex-wrap: nowrap;
    min-width: 0;
    margin-top: 8px;
    justify-content: flex-start;
  }

  #progress,
  #timer {
    font-size: 0.64rem;
    white-space: nowrap;
    line-height: 1.1;
  }

  #progress {
    flex: 1 1 auto;
    min-width: 0;
    letter-spacing: -0.1px;
  }

  #timer {
    flex: 0 0 auto;
    padding: 3px 6px;
  }

  #quiz-area.mode-exam .header-meta,
  #quiz-area.mode-smart .header-meta {
    grid-template-columns: 1fr auto 1fr;
    gap: 4px;
  }

  #quiz-area.mode-exam #progress,
  #quiz-area.mode-smart #progress {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #quiz-area.mode-exam #timer,
  #quiz-area.mode-smart #timer {
    min-width: 112px;
    font-size: 0.84rem;
    padding: 6px 10px;
  }

  .study-control-row,
  .exam-control-row {
    grid-template-columns: 1fr;
  }

  .topic-library-controls {
    grid-template-columns: 1fr;
  }

  .bottom-navigation {
    flex-wrap: wrap;
  }

  .bottom-navigation button {
    flex: 1 1 120px;
  }
}

@media (max-width: 520px) {
  .menu-title {
    font-size: 1rem;
  }

  .menu-subtitle {
    font-size: 0.8rem;
  }

  .portal-wrapper {
    padding: 24px 18px;
  }

  .result-actions {
    flex-direction: column;
  }

  .result-btn,
  .start-btn,
  .portal-button:not(.menu-portal-btn),
  .modal-btn {
    width: 100%;
  }

  #back-home-btn.menu-portal-btn {
    width: auto;
    max-width: 100%;
  }

  .modal-actions {
    flex-direction: column;
  }
}

@media (max-width: 760px) {
  /* Enforce readable text size and touch targets on mobile devices. */
  input,
  select,
  textarea,
  button,
  label {
    font-size: 16px !important;
  }

  input,
  select,
  textarea,
  button {
    min-height: 44px;
  }

  .menu-profile-btn {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    max-width: 36px !important;
    max-height: 36px !important;
    padding: 0 !important;
  }

  .portal-authority,
  .menu-subtitle,
  .header-meta,
  #progress,
  #timer {
    font-size: 16px !important;
    line-height: 1.3;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  from {
    transform: scale(1);
  }

  to {
    transform: scale(1.02);
  }
}

@keyframes pop {
  0% {
    transform: scale(0.96);
  }

  60% {
    transform: scale(1.05);
  }

  100% {
    transform: scale(1);
  }
}
