/* ==========================================================================
   Premium 3D layer — visual-only redesign. Loaded LAST; overrides styling
   only. No markup, behaviour, or data are changed. Delete the <link> tag to
   revert to the previous look.
   Direction: "Midnight Atelier" — deep ink-blue shell, warm ivory surfaces,
   saffron accent, layered depth (Emil Kowalski motion, Impeccable craft,
   Taste-skill restraint).
   ========================================================================== */
@import url("https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,500;12..96,650;12..96,750&family=Manrope:wght@400;500;600;700&family=IBM+Plex+Sans+Arabic:wght@400;500;600;700&display=swap");

:root {
  --p-ink: #141a2e;
  --p-ink-2: #1d2540;
  --p-ink-3: #2a3458;
  --p-ivory: #f6f3ec;
  --p-surface: #fffdf8;
  --p-text: #171b2b;
  --p-text-soft: #4a5068;
  --p-muted: #7a7f93;
  --p-line: rgba(20, 26, 46, .09);
  --p-line-strong: rgba(20, 26, 46, .16);
  --p-accent: #e8a33d;
  --p-accent-deep: #c9821c;
  --p-accent-soft: #fbefd9;
  --p-blue: #3f5bd9;
  --p-blue-soft: #e7ebfc;
  --p-green: #1f9d6c;
  --p-green-soft: #dff3ea;
  --p-red: #d4483b;
  --p-red-soft: #fbe5e2;
  --p-r-sm: 10px;
  --p-r: 16px;
  --p-r-lg: 22px;
  --p-shadow-1: 0 1px 0 rgba(255,255,255,.8) inset, 0 1px 2px rgba(20,26,46,.06), 0 2px 6px -2px rgba(20,26,46,.06);
  --p-shadow-2: 0 1px 0 rgba(255,255,255,.9) inset, 0 2px 4px rgba(20,26,46,.04), 0 12px 28px -12px rgba(20,26,46,.18);
  --p-shadow-3: 0 1px 0 rgba(255,255,255,.9) inset, 0 6px 12px -4px rgba(20,26,46,.08), 0 28px 50px -20px rgba(20,26,46,.28);
  --p-ease-out: cubic-bezier(.23, 1, .32, 1);
  --p-ease-io: cubic-bezier(.77, 0, .175, 1);
  --p-font: "Manrope", "IBM Plex Sans Arabic", system-ui, sans-serif;
  --p-display: "Bricolage Grotesque", "Manrope", "IBM Plex Sans Arabic", system-ui, sans-serif;

  /* re-map legacy tokens so every existing rule inherits the new palette */
  --ink: var(--p-text); --ink-soft: var(--p-text-soft); --muted: var(--p-muted);
  --paper: var(--p-ivory); --surface: var(--p-surface); --surface-raised: #fff;
  --surface-muted: #f3efe6; --surface-2: #f3efe6;
  --line: var(--p-line); --line-strong: var(--p-line-strong); --line-dark: var(--p-line-strong);
  --brand: var(--p-ink-2); --brand-hover: var(--p-ink); --brand-strong: var(--p-ink);
  --brand-deep: var(--p-ink); --brand-soft: var(--p-blue-soft);
  --accent: var(--p-accent); --accent-hover: var(--p-accent-deep); --accent-soft: var(--p-accent-soft);
  --teal: var(--p-blue); --teal-dark: var(--p-ink-2); --teal-soft: var(--p-blue-soft);
  --navy: var(--p-ink); --sidebar: var(--p-ink);
  --sidebar-text: #e6e8f2; --sidebar-muted: #9399b3; --sidebar-hover: rgba(255,255,255,.06);
}

:root[data-theme="dark"] {
  --p-ivory: #0e1222; --p-surface: #161b30; --p-text: #ecedf4; --p-text-soft: #c2c6d6;
  --p-muted: #8a90a8; --p-line: rgba(255,255,255,.08); --p-line-strong: rgba(255,255,255,.15);
  --p-accent-soft: rgba(232,163,61,.14); --p-blue-soft: rgba(63,91,217,.18);
  --p-green-soft: rgba(31,157,108,.16); --p-red-soft: rgba(212,72,59,.16);
  --p-shadow-1: 0 1px 0 rgba(255,255,255,.04) inset, 0 2px 6px rgba(0,0,0,.3);
  --p-shadow-2: 0 1px 0 rgba(255,255,255,.05) inset, 0 14px 30px -12px rgba(0,0,0,.6);
  --p-shadow-3: 0 1px 0 rgba(255,255,255,.06) inset, 0 30px 60px -20px rgba(0,0,0,.75);
  --surface-raised: #1b2138; --surface-muted: #1b2138; --surface-2: #1b2138;
}

/* ---------- Base ---------- */
html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
body {
  font-family: var(--p-font);
  color: var(--p-text);
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(63,91,217,.07), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(232,163,61,.08), transparent 60%),
    var(--p-ivory);
  background-attachment: fixed;
}
h1, h2, h3, .panel-head h3, .stat-card > strong, .auth-card h1, .auth-card h2 {
  font-family: var(--p-display); letter-spacing: -.02em; color: var(--p-text);
}
::selection { background: var(--p-accent); color: var(--p-ink); }
:focus-visible { outline: 2px solid var(--p-accent) !important; outline-offset: 2px; }

/* ---------- Sidebar ---------- */
.sidebar {
  background:
    radial-gradient(400px 260px at 0% 0%, rgba(232,163,61,.12), transparent 70%),
    linear-gradient(180deg, var(--p-ink-2), var(--p-ink) 60%);
  border-right: 1px solid rgba(255,255,255,.06);
  box-shadow: 12px 0 40px -20px rgba(10,14,30,.5);
}
.brand-mark, .auth-mark {
  background: linear-gradient(145deg, #f4bd62, var(--p-accent-deep)) !important;
  color: var(--p-ink) !important; font-family: var(--p-display); font-weight: 750;
  border-radius: 12px !important;
  box-shadow: 0 1px 0 rgba(255,255,255,.5) inset, 0 -2px 0 rgba(0,0,0,.15) inset, 0 8px 18px -6px rgba(232,163,61,.6);
  transform: perspective(300px) rotateX(8deg);
}
.brand-copy strong { font-family: var(--p-display); letter-spacing: -.01em; }
.profile-chip {
  background: linear-gradient(180deg, rgba(255,255,255,.07), rgba(255,255,255,.02));
  border: 1px solid rgba(255,255,255,.08); border-radius: var(--p-r);
  box-shadow: 0 1px 0 rgba(255,255,255,.06) inset, 0 10px 20px -12px rgba(0,0,0,.5);
}
.avatar { background: linear-gradient(145deg, var(--p-blue), #2a3c9e) !important; color: #fff !important; box-shadow: 0 4px 10px -4px rgba(63,91,217,.7); }
.online-dot { background: #3ddc97 !important; box-shadow: 0 0 0 3px rgba(61,220,151,.18); }
.nav-label { color: var(--sidebar-muted); letter-spacing: .12em; font-size: 10.5px; }
.main-nav a {
  position: relative; border-radius: 12px; color: var(--sidebar-text);
  transition: background-color .15s ease, color .15s ease, transform .16s var(--p-ease-out);
}
.main-nav a:hover { background: var(--sidebar-hover); }
.main-nav a:active { transform: scale(.98); }
.main-nav a.active {
  background: linear-gradient(180deg, rgba(255,255,255,.12), rgba(255,255,255,.05));
  color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,.1) inset, 0 8px 18px -10px rgba(0,0,0,.6);
}
.main-nav a.active::before {
  content: ""; position: absolute; inset-inline-start: -2px; top: 22%; bottom: 22%; width: 3px;
  border-radius: 3px; background: var(--p-accent); box-shadow: 0 0 12px var(--p-accent);
}
.main-nav a.active .nav-icon { color: var(--p-accent); }
.nav-count { background: var(--p-accent) !important; color: var(--p-ink) !important; font-weight: 700; }
.secure-note { background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.07); border-radius: var(--p-r); }

/* ---------- Topbar ---------- */
.topbar {
  background: color-mix(in srgb, var(--p-ivory) 78%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--p-line);
}
.topbar h1 { font-size: clamp(1.25rem, 1rem + 1vw, 1.65rem); font-weight: 750; }
.eyebrow { color: var(--p-accent-deep) !important; letter-spacing: .12em; font-weight: 700; }
.icon-button, .logout-button, .mobile-menu {
  background: var(--p-surface); border: 1px solid var(--p-line); border-radius: 12px;
  box-shadow: var(--p-shadow-1);
  transition: transform .14s var(--p-ease-out), box-shadow .2s ease, border-color .15s ease;
}
.icon-button i { background: var(--p-red) !important; box-shadow: 0 0 0 2px var(--p-surface); }

/* ---------- Surfaces: panels, cards, stats ---------- */
.panel, .stat-card, .course-card, .resource-card, .path-card, .exercise-card,
.submission-card, .today-card, .viewer-shell, .test-answer-panel, .auth-card, .confirm-modal form {
  background: linear-gradient(180deg, var(--p-surface), color-mix(in srgb, var(--p-surface) 92%, var(--p-ivory)));
  border: 1px solid var(--p-line) !important;
  border-radius: var(--p-r-lg) !important;
  box-shadow: var(--p-shadow-2);
}
.panel { overflow: hidden; }
.panel-head { border-bottom: 1px solid var(--p-line); }
.panel-head h3 { font-weight: 650; font-size: 1.05rem; }

.stat-card, .course-card, .resource-card, .path-card, .exercise-card, .submission-card {
  transform: perspective(900px) translateZ(0);
  transition: transform .35s var(--p-ease-out), box-shadow .35s var(--p-ease-out), border-color .2s ease;
  will-change: transform;
}
@media (hover: hover) and (pointer: fine) {
  .stat-card:hover, .course-card:hover, .resource-card:hover, .path-card:hover, .exercise-card:hover, .submission-card:hover {
    transform: perspective(900px) translateY(-4px) rotateX(2deg);
    box-shadow: var(--p-shadow-3);
    border-color: var(--p-line-strong) !important;
  }
  .button:hover, .icon-button:hover, .logout-button:hover { transform: translateY(-1px); }
}
.stat-card { position: relative; overflow: hidden; }
.stat-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.9), transparent);
}
.stat-card > strong { font-size: clamp(1.6rem, 1.2rem + 1.2vw, 2.2rem); font-weight: 750; font-variant-numeric: tabular-nums; }
.stat-icon, .course-icon, .resource-icon, .path-icon, .banner-icon {
  border-radius: 14px !important;
  box-shadow: 0 1px 0 rgba(255,255,255,.6) inset, 0 -2px 0 rgba(0,0,0,.08) inset, 0 8px 16px -8px rgba(20,26,46,.35);
  transform: perspective(300px) rotateX(10deg) rotateY(-6deg);
}
.stat-icon.blue, .blue { background: var(--p-blue-soft); color: var(--p-blue); }
.stat-icon.violet, .violet { background: #ecebfb; color: #5a4fc4; }
.stat-icon.teal, .teal { background: var(--p-green-soft); color: var(--p-green); }
.stat-icon.amber, .amber, .course-icon-warm { background: var(--p-accent-soft); color: var(--p-accent-deep); }

/* ---------- Buttons ---------- */
.button {
  font-family: var(--p-font); font-weight: 650; letter-spacing: -.005em;
  border-radius: 12px !important;
  transition: transform .14s var(--p-ease-out), box-shadow .2s ease, background-color .15s ease, filter .15s ease;
}
.button:active, .icon-button:active, .logout-button:active, .mobile-menu:active { transform: scale(.97) !important; }
.button-primary {
  background: linear-gradient(180deg, var(--p-ink-3), var(--p-ink)) !important;
  color: #fff !important; border: 1px solid rgba(0,0,0,.25) !important;
  box-shadow: 0 1px 0 rgba(255,255,255,.18) inset, 0 -2px 0 rgba(0,0,0,.25) inset, 0 6px 14px -6px rgba(20,26,46,.55) !important;
}
.button-primary:hover { filter: brightness(1.12); }
:root[data-theme="dark"] .button-primary {
  background: linear-gradient(180deg, #f4bd62, var(--p-accent-deep)) !important; color: var(--p-ink) !important;
}
.button-secondary, .button-quiet {
  background: var(--p-surface) !important; color: var(--p-text) !important;
  border: 1px solid var(--p-line-strong) !important; box-shadow: var(--p-shadow-1) !important;
}
.button-danger {
  background: linear-gradient(180deg, #e3604f, var(--p-red)) !important; color: #fff !important;
  border: 1px solid rgba(0,0,0,.15) !important;
  box-shadow: 0 1px 0 rgba(255,255,255,.2) inset, 0 6px 14px -6px rgba(212,72,59,.6) !important;
}
.text-link { color: var(--p-blue); font-weight: 600; text-underline-offset: 3px; }

/* ---------- Forms ---------- */
input:not([type=checkbox]):not([type=radio]):not([type=hidden]):not([type=file]), select, textarea {
  border-radius: 12px !important; border: 1px solid var(--p-line-strong) !important;
  background: var(--p-surface) !important; color: var(--p-text);
  box-shadow: 0 1px 2px rgba(20,26,46,.05) inset;
  transition: border-color .15s ease, box-shadow .2s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--p-accent) !important; outline: none !important;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--p-accent) 22%, transparent) !important;
}
label { font-weight: 600; color: var(--p-text-soft); }
input[type=checkbox], input[type=radio] { accent-color: var(--p-ink-2); }

/* ---------- Tables ---------- */
.table-wrap {
  border: 1px solid var(--p-line) !important; border-radius: var(--p-r) !important;
  background: var(--p-surface); box-shadow: var(--p-shadow-1); overflow: auto;
}
.table-wrap table { border-collapse: separate; border-spacing: 0; width: 100%; }
.table-wrap thead th {
  position: sticky; top: 0; z-index: 1;
  background: color-mix(in srgb, var(--p-ivory) 85%, var(--p-surface));
  color: var(--p-muted); font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
  border-bottom: 1px solid var(--p-line);
}
.table-wrap tbody tr { transition: background-color .15s ease; }
.table-wrap tbody tr:hover { background: color-mix(in srgb, var(--p-accent-soft) 55%, transparent); }
.table-wrap td { border-bottom: 1px solid var(--p-line); font-variant-numeric: tabular-nums; }
.table-wrap tbody tr:last-child td { border-bottom: 0; }

/* ---------- Badges / notices ---------- */
.badge, .status-pill {
  border-radius: 999px !important; font-weight: 650; font-size: 11.5px; letter-spacing: .01em;
  box-shadow: 0 1px 0 rgba(255,255,255,.6) inset; border: 1px solid transparent;
}
.badge-blue { background: var(--p-blue-soft) !important; color: var(--p-blue) !important; }
.badge-green { background: var(--p-green-soft) !important; color: var(--p-green) !important; }
.badge-amber { background: var(--p-accent-soft) !important; color: var(--p-accent-deep) !important; }
.badge-red { background: var(--p-red-soft) !important; color: var(--p-red) !important; }
.notice {
  border-radius: var(--p-r) !important; border: 1px solid var(--p-line) !important;
  box-shadow: var(--p-shadow-1); animation: p-rise .32s var(--p-ease-out) both;
}
.notice-success { background: var(--p-green-soft) !important; color: var(--p-green) !important; }
.notice-error { background: var(--p-red-soft) !important; color: var(--p-red) !important; }
.notice-info { background: var(--p-blue-soft) !important; color: var(--p-blue) !important; }
.empty-state {
  border: 1.5px dashed var(--p-line-strong) !important; border-radius: var(--p-r) !important;
  background: color-mix(in srgb, var(--p-surface) 70%, transparent) !important; color: var(--p-muted);
}

/* ---------- Dialog ---------- */
.confirm-modal::backdrop { background: rgba(10,14,30,.45); backdrop-filter: blur(6px); }
.confirm-modal[open] form { animation: p-pop .24s var(--p-ease-out) both; box-shadow: var(--p-shadow-3); }
.confirm-mark { background: var(--p-accent-soft) !important; color: var(--p-accent-deep) !important; }

/* ---------- Auth pages ---------- */
.auth-wrap {
  background:
    radial-gradient(700px 420px at 15% 10%, rgba(232,163,61,.18), transparent 60%),
    radial-gradient(800px 500px at 90% 90%, rgba(63,91,217,.16), transparent 60%),
    var(--p-ivory);
  perspective: 1200px;
}
.auth-card { box-shadow: var(--p-shadow-3); animation: p-tilt-in .6s var(--p-ease-out) both; }

/* ---------- Page-entry motion ---------- */
.content > * { animation: p-rise .42s var(--p-ease-out) both; }
.content > *:nth-child(2) { animation-delay: .04s; }
.content > *:nth-child(3) { animation-delay: .08s; }
.content > *:nth-child(4) { animation-delay: .12s; }
.stat-grid > *, .card-grid > * { animation: p-rise .45s var(--p-ease-out) both; }
.stat-grid > *:nth-child(2), .card-grid > *:nth-child(2) { animation-delay: .05s; }
.stat-grid > *:nth-child(3), .card-grid > *:nth-child(3) { animation-delay: .1s; }
.stat-grid > *:nth-child(4), .card-grid > *:nth-child(4) { animation-delay: .15s; }

@keyframes p-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes p-pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
@keyframes p-tilt-in { from { opacity: 0; transform: rotateX(8deg) translateY(16px); } to { opacity: 1; transform: none; } }

.footer { color: var(--p-muted); border-top: 1px solid var(--p-line); }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .sidebar { box-shadow: 24px 0 60px -10px rgba(10,14,30,.55); }
}
@media (max-width: 700px) {
  .panel, .stat-card, .course-card, .resource-card, .auth-card { border-radius: var(--p-r) !important; }
  .table-wrap { border-radius: 12px !important; }
  .button { min-height: 44px; }
  .stat-icon, .course-icon, .resource-icon, .path-icon { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; }
  .stat-card:hover, .course-card:hover, .resource-card:hover { transform: none !important; }
}
