/* ==========================================================
   ACADEMIC 12 - STYLES
   1. Theme variables   2. Base   3. Background   4. Screens
   5. Welcome           6. Buttons   7. Panels and forms
   8. Verification code 9. Pickers (subjects + themes)
   10. Copilot naming   11. Personalising screen
   12. Dashboard shell  13. Copilot chat
   14. Responsive and reduced motion
   ========================================================== */

/* ---------- 1. THEME VARIABLES ---------- */
:root,
[data-theme="default"] {
  --bg: #0f1020;
  --surface: #1a1b30;
  --text: #f5f6ff;
  --text-muted: #a9abc9;
  --border: rgba(255, 255, 255, 0.12);
  --primary: #7c5cff;
  --primary-contrast: #ffffff;
  --grad-1: #7c5cff;
  --grad-2: #ff5c9d;
  --grad-3: #38bdf8;
  --danger: #f87171;
}

[data-theme="green"] {
  --bg: #f3fbf6;
  --surface: #ffffff;
  --text: #10261a;
  --text-muted: #557262;
  --border: rgba(16, 38, 26, 0.12);
  --primary: #16a34a;
  --primary-contrast: #ffffff;
  --grad-1: #16a34a;
  --grad-2: #84cc16;
  --grad-3: #10b981;
  --danger: #dc2626;
}

[data-theme="red"] {
  --bg: #fff5f5;
  --surface: #ffffff;
  --text: #2a1212;
  --text-muted: #7a5555;
  --border: rgba(42, 18, 18, 0.12);
  --primary: #dc2626;
  --primary-contrast: #ffffff;
  --grad-1: #dc2626;
  --grad-2: #f97316;
  --grad-3: #f43f5e;
  --danger: #b91c1c;
}

[data-theme="pink"] {
  --bg: #fff5fa;
  --surface: #ffffff;
  --text: #2b1220;
  --text-muted: #7c5468;
  --border: rgba(43, 18, 32, 0.12);
  --primary: #ec4899;
  --primary-contrast: #ffffff;
  --grad-1: #ec4899;
  --grad-2: #f472b6;
  --grad-3: #c084fc;
  --danger: #dc2626;
}

[data-theme="blue"] {
  --bg: #f3f8ff;
  --surface: #ffffff;
  --text: #0f1e33;
  --text-muted: #506585;
  --border: rgba(15, 30, 51, 0.12);
  --primary: #2563eb;
  --primary-contrast: #ffffff;
  --grad-1: #2563eb;
  --grad-2: #38bdf8;
  --grad-3: #6366f1;
  --danger: #dc2626;
}

[data-theme="white"] {
  --bg: #ffffff;
  --surface: #f5f6f8;
  --text: #15171c;
  --text-muted: #626873;
  --border: rgba(21, 23, 28, 0.12);
  --primary: #15171c;
  --primary-contrast: #ffffff;
  --grad-1: #15171c;
  --grad-2: #6b7280;
  --grad-3: #9ca3af;
  --danger: #dc2626;
}

[data-theme="dark"] {
  --bg: #000000;
  --surface: #111111;
  --text: #f2f2f2;
  --text-muted: #9a9a9a;
  --border: rgba(255, 255, 255, 0.14);
  --primary: #ffffff;
  --primary-contrast: #000000;
  --grad-1: #ffffff;
  --grad-2: #a3a3a3;
  --grad-3: #6b6b6b;
  --danger: #f87171;
}

/* ---------- 2. BASE ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: hidden;
  transition: background-color 0.4s ease, color 0.4s ease;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Smooth theme switching: added briefly by JavaScript when the theme changes */
html.theme-switching *,
html.theme-switching *::before,
html.theme-switching *::after {
  transition: background-color 0.45s ease, color 0.45s ease,
              border-color 0.45s ease, box-shadow 0.45s ease !important;
}

/* ---------- 3. BACKGROUND ---------- */
.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.bg__blob {
  position: absolute;
  width: 55vmax;
  height: 55vmax;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.35;
  animation: drift 22s ease-in-out infinite alternate;
  transition: background 0.6s ease;
}

.bg__blob--1 { background: var(--grad-1); top: -20vmax; left: -15vmax; }
.bg__blob--2 { background: var(--grad-2); bottom: -25vmax; right: -15vmax; animation-delay: -7s; }
.bg__blob--3 { background: var(--grad-3); top: 30%; left: 40%; width: 35vmax; height: 35vmax; opacity: 0.2; animation-delay: -13s; }

@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(6vmax, 4vmax, 0) scale(1.12); }
}

/* ---------- 4. SCREENS ---------- */
#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
}

.screen {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
}

.screen--top {
  align-items: flex-start;
  padding-top: 3rem;
}

/* The dashboard fills the whole screen with no padding or centring */
.screen--app {
  align-items: stretch;
  justify-content: flex-start;
  padding: 0;
}

/* "backwards" means the entrance animation never leaves a transform behind.
   This matters for the dashboard: a leftover transform would break the
   fixed bottom navigation bar on mobile. */
.screen.is-active {
  display: flex;
  animation: screen-in 0.55s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.screen.is-leaving {
  display: flex;
  animation: screen-out 0.25s ease-in both;
}

@keyframes screen-in {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes screen-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-12px); }
}

/* Staggered entrance for screen content */
.screen.is-active .welcome > *,
.screen.is-active .panel > *,
.screen.is-active .picker > * {
  animation: rise 0.7s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}
.screen.is-active .welcome > *:nth-child(1),
.screen.is-active .panel > *:nth-child(1),
.screen.is-active .picker > *:nth-child(1) { animation-delay: 0.05s; }
.screen.is-active .welcome > *:nth-child(2),
.screen.is-active .panel > *:nth-child(2),
.screen.is-active .picker > *:nth-child(2) { animation-delay: 0.13s; }
.screen.is-active .welcome > *:nth-child(3),
.screen.is-active .panel > *:nth-child(3),
.screen.is-active .picker > *:nth-child(3) { animation-delay: 0.21s; }
.screen.is-active .welcome > *:nth-child(4),
.screen.is-active .panel > *:nth-child(4),
.screen.is-active .picker > *:nth-child(4) { animation-delay: 0.29s; }
.screen.is-active .panel > *:nth-child(5) { animation-delay: 0.37s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(22px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- 5. WELCOME ---------- */
.welcome {
  width: 100%;
  max-width: 44rem;
  text-align: center;
}

.welcome__eyebrow {
  margin: 0 0 1.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.welcome__title {
  margin: 0 0 1.25rem;
  font-size: clamp(2.6rem, 8vw, 5.2rem);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.welcome__title--small {
  font-size: clamp(2rem, 6vw, 3.2rem);
}

.welcome__sub {
  margin: 0 auto 2.5rem;
  max-width: 32rem;
  font-size: clamp(1rem, 2.4vw, 1.2rem);
  color: var(--text-muted);
}

.welcome__sub strong {
  color: var(--text);
}

.gradient-text {
  background: linear-gradient(100deg, var(--grad-1), var(--grad-2), var(--grad-3), var(--grad-1));
  background-size: 250% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  animation: shimmer 8s linear infinite;
}

@keyframes shimmer {
  to { background-position: 250% 0; }
}

/* ---------- 6. BUTTONS ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.95rem 2rem;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.3s ease, opacity 0.2s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--primary {
  background: linear-gradient(100deg, var(--grad-1), var(--grad-2));
  color: var(--primary-contrast);
  box-shadow: 0 10px 30px -10px var(--grad-1);
}

.btn--primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 16px 36px -10px var(--grad-1);
}

.btn--ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn--ghost:hover {
  background: var(--surface);
}

.btn--text {
  background: transparent;
  color: var(--text-muted);
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  font-weight: 500;
}

.btn--text:hover:not(:disabled) {
  color: var(--text);
}

.btn--block {
  width: 100%;
}

.btn__arrow {
  transition: transform 0.2s ease;
}

.btn:hover:not(:disabled) .btn__arrow {
  transform: translateX(4px);
}

.btn.is-busy .btn__label::after {
  content: "";
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  margin-left: 0.6rem;
  vertical-align: -0.1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- 7. PANELS AND FORMS ---------- */
.panel {
  width: 100%;
  max-width: 28rem;
  padding: 2.25rem 2rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.5rem;
  box-shadow: 0 30px 60px -30px rgba(0, 0, 0, 0.35);
  text-align: center;
  transition: background-color 0.4s ease, border-color 0.4s ease;
}

.step-label {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.panel__title {
  margin: 0 0 0.5rem;
  font-size: clamp(1.6rem, 5vw, 2.1rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.panel__sub {
  margin: 0 0 1.75rem;
  color: var(--text-muted);
  font-size: 0.98rem;
}

.field {
  margin-bottom: 1.25rem;
  text-align: left;
}

.field label {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.92rem;
  font-weight: 600;
}

.field input,
.input {
  width: 100%;
  padding: 0.9rem 1rem;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 0.85rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.4s ease;
}

.field input::placeholder,
.input::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

.field input:focus,
.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 22%, transparent);
}

.field input[aria-invalid="true"] {
  border-color: var(--danger);
  animation: shake 0.35s ease;
}

.field__error {
  min-height: 1.3rem;
  margin: 0.4rem 0 0;
  font-size: 0.85rem;
  color: var(--danger);
}

.field__error--center {
  text-align: center;
  margin: 0.6rem 0 0.9rem;
}

@keyframes shake {
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

.notice {
  margin: 0 0 1.5rem;
  padding: 0.85rem 1rem;
  font-size: 0.85rem;
  text-align: left;
  color: var(--text);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  border: 1px dashed color-mix(in srgb, var(--primary) 55%, transparent);
  border-radius: 0.85rem;
}

.verify-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem;
  margin-top: 0.75rem;
}

/* ---------- 8. VERIFICATION CODE ---------- */
.code {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
}

.code__digit {
  width: 3rem;
  height: 3.6rem;
  padding: 0;
  font-family: inherit;
  font-size: 1.5rem;
  font-weight: 600;
  text-align: center;
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 0.85rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}

.code__digit:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 22%, transparent);
  transform: translateY(-2px);
}

.code__digit.is-filled {
  border-color: var(--primary);
}

.code.has-error .code__digit {
  border-color: var(--danger);
  animation: shake 0.35s ease;
}

/* ---------- 9. PICKERS (subjects + themes) ---------- */
.picker {
  width: 100%;
  max-width: 60rem;
}

.picker--narrow {
  max-width: 46rem;
}

.picker__head {
  margin-bottom: 1.75rem;
  text-align: center;
}

.picker__head .panel__sub {
  margin-bottom: 1.25rem;
}

.picker__search {
  max-width: 26rem;
  margin: 0 auto;
}

.picker__empty {
  margin: 2rem 0;
  text-align: center;
  color: var(--text-muted);
}

/* --- Subject groups and cards --- */
.group {
  margin-bottom: 1.75rem;
}

.group__title {
  margin: 0 0 0.75rem 0.25rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.group__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
  gap: 0.75rem;
}

.subject-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.35;
  text-align: left;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 0.9rem;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, background-color 0.25s ease, box-shadow 0.2s ease;
}

.screen.is-active .subject-card {
  animation: rise 0.5s cubic-bezier(0.22, 1, 0.36, 1) backwards;
  animation-delay: calc(min(var(--i, 0), 20) * 25ms);
}

.subject-card:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--primary) 55%, var(--border));
}

.subject-card:active {
  transform: scale(0.98);
}

.subject-card[aria-pressed="true"] {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 14%, var(--surface));
  box-shadow: 0 8px 22px -12px var(--primary);
}

.subject-card__tick {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 1.4rem;
  height: 1.4rem;
  font-size: 0.8rem;
  font-weight: 800;
  color: transparent;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.subject-card[aria-pressed="true"] .subject-card__tick {
  color: var(--primary-contrast);
  background: var(--primary);
  border-color: var(--primary);
  transform: scale(1.1);
}

/* --- Sticky bottom bar --- */
.picker__bar {
  position: sticky;
  bottom: 1rem;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 2rem;
  padding: 0.9rem 1.25rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 1.1rem;
  box-shadow: 0 20px 40px -20px rgba(0, 0, 0, 0.4);
}

.picker__bar-text {
  display: flex;
  flex-direction: column;
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.picker__bar-text strong {
  font-size: 1rem;
  color: var(--text);
}

.picker__actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 2rem;
}

/* --- Theme cards --- */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  gap: 1rem;
}

.theme-card {
  display: block;
  cursor: pointer;
}

.theme-card__inner {
  display: block;
  padding: 0.6rem 0.6rem 0.8rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 1.1rem;
  text-align: center;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.theme-card:hover .theme-card__inner {
  transform: translateY(-3px);
}

.theme-card input:checked ~ .theme-card__inner {
  border-color: var(--primary);
  box-shadow: 0 12px 28px -14px var(--primary);
}

.theme-card input:focus-visible ~ .theme-card__inner {
  outline: 3px solid var(--primary);
  outline-offset: 3px;
}

.theme-card__name {
  display: block;
  margin-top: 0.65rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.theme-card input:checked ~ .theme-card__inner .theme-card__name::after {
  content: " ✓";
  color: var(--primary);
}

/* The preview carries its own data-theme, so it shows that theme's colours
   even while a different theme is active on the page. */
.theme-preview {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 0.4rem;
  height: 5.5rem;
  padding: 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.7rem;
}

.tp-bar {
  width: 60%;
  height: 0.5rem;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--grad-1), var(--grad-2));
}

.tp-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.4rem;
}

.tp-pill {
  width: 40%;
  height: 0.55rem;
  border-radius: 999px;
  background: var(--primary);
}

/* ---------- 10. COPILOT NAMING ---------- */
.chips-label {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.chip {
  padding: 0.4rem 0.95rem;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.15s ease;
}

.chip:hover {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 10%, transparent);
}

.chip:active {
  transform: scale(0.95);
}

.copilot-preview {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 1.5rem;
  padding: 0.5rem 1.1rem;
  font-size: 0.92rem;
  color: var(--text-muted);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  border-radius: 999px;
}

.copilot-preview strong {
  color: var(--text);
  overflow-wrap: anywhere;
}

/* ---------- 11. PERSONALISING SCREEN ---------- */
.personalising {
  display: grid;
  justify-items: center;
  gap: 1.25rem;
  width: 100%;
  max-width: 28rem;
  text-align: center;
}

.orb {
  position: relative;
  width: 8rem;
  height: 8rem;
  margin-bottom: 1rem;
}

.orb__ring {
  position: absolute;
  inset: 0;
  border: 3px solid transparent;
  border-top-color: var(--grad-1);
  border-right-color: var(--grad-2);
  border-radius: 50%;
  animation: spin 1.6s linear infinite;
}

.orb__ring--2 {
  inset: 0.9rem;
  border-top-color: var(--grad-2);
  border-right-color: var(--grad-3);
  animation-duration: 2.2s;
  animation-direction: reverse;
}

.orb__ring--3 {
  inset: 1.8rem;
  border-top-color: var(--grad-3);
  border-right-color: var(--grad-1);
  animation-duration: 3s;
}

.orb__core {
  position: absolute;
  inset: 3rem;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--grad-2), var(--grad-1));
  box-shadow: 0 0 40px -6px var(--grad-1);
  animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(0.85); }
  50%      { transform: scale(1.1); }
}

.personalising__title {
  margin: 0;
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.personalising__msg {
  min-height: 1.6rem;
  margin: 0;
  color: var(--text-muted);
}

.personalising__msg.is-in {
  animation: rise 0.4s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.progress {
  width: 100%;
  max-width: 20rem;
  height: 0.4rem;
  overflow: hidden;
  background: var(--border);
  border-radius: 999px;
}

.progress__bar {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--grad-1), var(--grad-2), var(--grad-3));
}

.progress.is-running .progress__bar {
  animation: fill 5s linear forwards;
}

@keyframes fill {
  to { width: 100%; }
}

/* ---------- 12. DASHBOARD SHELL ---------- */
.app {
  display: grid;
  grid-template-columns: 16.5rem minmax(0, 1fr);
  width: 100%;
  min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 1.5rem 1rem;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-right: 1px solid var(--border);
}

.sidebar__brand,
.app-top {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.sidebar__brand {
  padding: 0.25rem 0.75rem 1.75rem;
}

.brand-mark {
  flex: none;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 0.55rem;
  background: linear-gradient(135deg, var(--grad-1), var(--grad-2));
}

.nav {
  display: grid;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  padding: 0.8rem 0.9rem;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-align: left;
  text-transform: uppercase;
  color: var(--text-muted);
  background: transparent;
  border: 0;
  border-radius: 0.85rem;
  cursor: pointer;
  transition: color 0.2s ease, background-color 0.2s ease;
}

.nav__item svg {
  flex: none;
  width: 1.35rem;
  height: 1.35rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav__label {
  min-width: 0;
  overflow-wrap: anywhere;
}

.nav__item:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--primary) 8%, transparent);
}

.nav__item[aria-current="page"] {
  color: var(--text);
  background: color-mix(in srgb, var(--primary) 14%, transparent);
}

.nav__item[aria-current="page"] svg {
  color: var(--primary);
}

.nav__item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 25%;
  bottom: 25%;
  width: 3px;
  border-radius: 3px;
  background: linear-gradient(var(--grad-1), var(--grad-2));
}

.sidebar__user {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-top: auto;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
}

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  font-weight: 800;
  color: var(--primary-contrast);
  background: linear-gradient(135deg, var(--grad-1), var(--grad-2));
  border-radius: 50%;
}

.sidebar__user-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.sidebar__user-name {
  font-size: 0.92rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.sidebar__user-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* --- Main area and views --- */
.app__main {
  min-width: 0;
  padding: 2.5rem clamp(1.25rem, 4vw, 3.5rem) 3rem;
}

.app-top {
  display: none;
  margin-bottom: 1.5rem;
}

.view {
  display: none;
  max-width: 56rem;
}

.view.is-active {
  display: block;
  animation: rise 0.45s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.view__head {
  margin-bottom: 1.75rem;
}

.view__title {
  margin: 0 0 0.35rem;
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.view__title:focus {
  outline: none;
}

.view__sub {
  margin: 0;
  color: var(--text-muted);
}

/* --- Cards --- */
.card {
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  transition: background-color 0.4s ease, border-color 0.4s ease;
}

.card + .card {
  margin-top: 1.25rem;
}

.card__title {
  margin: 0 0 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.card__text {
  margin: 0 0 1.25rem;
  color: var(--text-muted);
}

.badge {
  display: inline-block;
  padding: 0.3rem 0.85rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text);
  background: color-mix(in srgb, var(--primary) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--primary) 35%, transparent);
  border-radius: 999px;
}

/* --- Empty states --- */
.empty-state {
  padding: 3rem 1.5rem;
  text-align: center;
}

.empty-state__icon {
  display: inline-grid;
  place-items: center;
  width: 3.6rem;
  height: 3.6rem;
  margin-bottom: 1rem;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  border-radius: 50%;
}

.empty-state__icon svg {
  width: 1.7rem;
  height: 1.7rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty-state__title {
  margin: 0 0 0.4rem;
  font-size: 1.25rem;
  font-weight: 700;
}

.empty-state__text {
  max-width: 26rem;
  margin: 0 auto 1.25rem;
  color: var(--text-muted);
}

/* --- Account details and settings --- */
.details {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.9rem 1.75rem;
  margin: 0;
}

.details dt {
  font-size: 0.88rem;
  color: var(--text-muted);
}

.details dd {
  margin: 0;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tag {
  padding: 0.25rem 0.7rem;
  font-size: 0.82rem;
  font-weight: 500;
  background: color-mix(in srgb, var(--primary) 8%, transparent);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.setting-row__title {
  margin: 0;
  font-weight: 600;
}

.setting-row__desc {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.switch {
  position: relative;
  flex: none;
  width: 3.2rem;
  height: 1.85rem;
  padding: 0;
  background: color-mix(in srgb, var(--text-muted) 45%, transparent);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.25s ease;
}

.switch[aria-checked="true"] {
  background: linear-gradient(100deg, var(--grad-1), var(--grad-2));
}

.switch__thumb {
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  width: 1.45rem;
  height: 1.45rem;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.switch[aria-checked="true"] .switch__thumb {
  transform: translateX(1.35rem);
}

/* ---------- 13. COPILOT CHAT ---------- */
.view--chat .notice {
  margin-bottom: 1rem;
  font-size: 0.82rem;
}

.chat {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 17.5rem);
  min-height: 26rem;
  max-height: 50rem;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  transition: background-color 0.4s ease, border-color 0.4s ease;
}

@supports (height: 100dvh) {
  .chat {
    height: calc(100dvh - 17.5rem);
  }
}

.chat__bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}

.chat__bar-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.chat__bar-text strong {
  overflow-wrap: anywhere;
}

.chat__bar-text span {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.chat__clear {
  flex: none;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}

.chat__messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat__empty {
  max-width: 30rem;
  margin: auto;
  padding: 1rem;
  text-align: center;
}

.chat__empty-title {
  margin: 0 0 0.4rem;
  font-size: 1.3rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.chat__empty-text {
  margin: 0 0 1.25rem;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.chat__empty .chips {
  margin-bottom: 0;
}

/* --- Messages --- */
.msg {
  display: flex;
  gap: 0.6rem;
  max-width: 85%;
  animation: rise 0.35s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.msg--assistant {
  align-self: flex-start;
}

.msg--user {
  align-self: flex-end;
}

.msg__avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  font-size: 0.9rem;
  color: var(--primary-contrast);
  background: linear-gradient(135deg, var(--grad-1), var(--grad-2));
  border-radius: 50%;
}

.msg__avatar--lg {
  width: 3.4rem;
  height: 3.4rem;
  margin-bottom: 0.75rem;
  font-size: 1.4rem;
}

.msg__body {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.msg__bubble {
  padding: 0.7rem 1rem;
  font-size: 0.95rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border-radius: 1.1rem;
}

.msg--assistant .msg__bubble {
  background: color-mix(in srgb, var(--primary) 8%, var(--bg));
  border: 1px solid var(--border);
  border-top-left-radius: 0.35rem;
}

.msg--user .msg__bubble {
  color: var(--primary-contrast);
  background: linear-gradient(100deg, var(--grad-1), var(--grad-2));
  border-top-right-radius: 0.35rem;
}

.msg__meta {
  padding-left: 0.25rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Typing indicator */
.msg--typing .msg__bubble {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.95rem 1rem;
}

.dot {
  width: 0.45rem;
  height: 0.45rem;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.1s ease-in-out infinite;
}

.dot:nth-child(3) { animation-delay: 0.15s; }
.dot:nth-child(4) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%           { transform: translateY(-0.3rem); opacity: 1; }
}

/* --- Voice note + composer --- */
.voice-note {
  margin: 0 1rem 0.5rem;
  padding: 0.6rem 0.9rem;
  font-size: 0.82rem;
  color: var(--text);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  border: 1px dashed color-mix(in srgb, var(--primary) 55%, transparent);
  border-radius: 0.8rem;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
}

.composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 2.75rem;
  max-height: 10rem;
  padding: 0.7rem 1rem;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 1.2rem;
  resize: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.4s ease;
}

.composer textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

.composer textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 22%, transparent);
}

.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, transform 0.15s ease, opacity 0.2s ease;
}

.icon-btn svg {
  width: 1.3rem;
  height: 1.3rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--primary);
}

.icon-btn:active:not(:disabled) {
  transform: scale(0.94);
}

.icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.icon-btn--send {
  color: var(--primary-contrast);
  background: linear-gradient(135deg, var(--grad-1), var(--grad-2));
  border: 0;
}

.icon-btn--send:hover:not(:disabled) {
  color: var(--primary-contrast);
  transform: scale(1.06);
}

/* ---------- 14. RESPONSIVE AND REDUCED MOTION ---------- */

/* Tablet and phone: the sidebar becomes a bottom tab bar */
@media (max-width: 860px) {
  .app {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 20;
    flex-direction: row;
    height: auto;
    padding: 0.4rem 0.5rem calc(0.4rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
    border-right: 0;
  }

  .sidebar__brand,
  .sidebar__user {
    display: none;
  }

  .sidebar nav {
    width: 100%;
  }

  .nav {
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 0.25rem;
  }

  .nav__item {
    flex-direction: column;
    justify-content: center;
    gap: 0.2rem;
    padding: 0.55rem 0.25rem;
    font-size: 0.62rem;
    letter-spacing: 0.06em;
    text-align: center;
  }

  .nav__label {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .nav__item[aria-current="page"]::before {
    top: 0;
    right: 25%;
    bottom: auto;
    left: 25%;
    width: auto;
    height: 3px;
  }

  .app__main {
    padding-top: 1.5rem;
    padding-bottom: 7rem;
  }

  .app-top {
    display: flex;
  }

  .chat {
    height: calc(100vh - 26rem);
    min-height: 24rem;
  }

  @supports (height: 100dvh) {
    .chat {
      height: calc(100dvh - 26rem);
    }
  }
}

@media (max-width: 480px) {
  .btn:not(.btn--text) {
    width: 100%;
  }

  .panel {
    padding: 1.75rem 1.25rem 1.25rem;
  }

  .code {
    gap: 0.4rem;
  }

  .code__digit {
    width: 2.6rem;
    height: 3.2rem;
    font-size: 1.3rem;
  }

  .screen--top {
    padding-top: 2rem;
  }

  .group__grid {
    grid-template-columns: 1fr;
  }

  .theme-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  .picker__bar {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }

  .details {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }

  .details dd {
    margin-bottom: 0.75rem;
  }

  .msg {
    max-width: 92%;
  }

  .chat__messages {
    padding: 1rem 0.85rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}