:root {
    --bg-color: #0b0f1a;
    --section-bg: #131824;
    --card-bg: #1a2030;
    --text-color: #e6edf3;
    --text-secondary: #93a0b5;
    --primary-color: #6e8efb;
    --primary-hover: #566ff0;
    --accent-color: #a779f7;
    --accent-hover: #9560e8;
    --border-color: #283041;
    --shadow-color: rgba(0, 0, 0, 0.45);
    --success-color: #3fb950;
    --gradient-start: #5b8def;
    --gradient-end: #a779f7;
    --primary-rgb: 110, 142, 251;
    --accent-rgb: 167, 121, 247;
    --anchor-offset: 88px;
}

body.light-theme,
html.pre-light body {
    --bg-color: #ffffff;
    --section-bg: #f6f8fa;
    --card-bg: #ffffff; 
    --text-color: #1f2328; 
    --text-secondary: #4f5864; 
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --accent-color: #7c3aed;
    --accent-hover: #6d28d9;
    --border-color: #c5ccd3;
    --shadow-color: rgba(0, 0, 0, 0.08);
    --success-color: #1a7f37;
    --primary-rgb: 79, 70, 229;
    --accent-rgb: 124, 58, 237;
    --gradient-start: #6366f1;
    --gradient-end: #a855f7;
}

section, .section {
  scroll-margin-top: var(--anchor-offset);
}

.section[id]:target::before,
section[id]:target::before {
  content: "";
  display: block;
  height: var(--anchor-offset);
  margin-top: calc(var(--anchor-offset) * -1);
  visibility: hidden;
}

@media (max-width: 768px) {
  :root { --anchor-offset: 72px; }
}
@media (max-width: 480px) {
  :root { --anchor-offset: 64px; }
}

/* Hidden until focused. Never park it at left:-9999px - in RTL that off-screen
   space becomes scrollable overflow and drags the whole page out of view. */
.skip-link {
  position: absolute;
  top: 0;
  inset-inline-start: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  background: var(--primary-color);
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  z-index: 3000;
}
.skip-link:focus {
  width: auto;
  height: auto;
  overflow: visible;
  clip-path: none;
  top: 16px;
  inset-inline-start: 16px;
}

h1, .header-content h1 { font-size: clamp(2rem, 6vw, 4rem); }
.section h2 { font-size: clamp(1.4rem, 4.2vw, 2.2rem); }

.profile-text h3,
.experience-card h3,
.skill-card h3,
.skill-card-header h4 { font-size: clamp(1rem, 3.2vw, 1.4rem); }

p, li, .info-card p, .flip-card-back p, .flip-card-front p {
  font-size: clamp(0.95rem, 2.6vw, 1rem);
}

.section {
  margin: clamp(36px, 8vw, 80px) auto;
  padding: clamp(24px, 5vw, 60px) clamp(16px, 4vw, 40px);
}

.section h2::after { width: clamp(36%, 18vw, 60%); }

.table-wrapper { overflow-x: auto; }
.sample-table { min-width: 520px; }

@media (max-width: 1175px) {
  .section { margin: 60px auto; padding: 44px 28px; }
  .profile-content { gap: 20px; }
  .experience-media { height: 160px; }
}

@media (max-width: 1175px) {
  header { min-height: 85vh; background-attachment: scroll; }
  .header-content { padding: 0 12px; }
  .projects-scroll { gap: 16px; padding: 12px 2px 24px; }
}

@media (max-width: 768px) {
  .section { margin: 40px auto; padding: 28px 18px; }
  .flip-card-front h3, .flip-card-back h3 { font-size: 1.0rem; }
  .flip-card-front p, .flip-card-back p { font-size: 0.5rem; }
  .experience-media { height: 150px; }
  .experience-card h3 { font-size: 1rem; }
  .skills-category-title { font-size: 1.4rem; }
  .skill-card { padding: 20px; }
  .skill-card-header h4 { font-size: 1.1rem; }
  .formation-item {
    padding: 16px 16px 16px 42px; 
    display: block;
  }
  .formation-timeline::before { left: 14px; }   
  .formation-item::before { top: 18px; left: 10px; } 
  .formation-icon{
    display: block;
    margin: 2px 0 10px 0;
  }
  [dir="rtl"] .formation-item {
    padding-right: 42px;
    padding-left: 16px;
  }
  [dir="rtl"] .formation-timeline::before { right: 14px; }
  [dir="rtl"] .formation-item::before { right: 10px; }
  [dir="rtl"] .formation-icon { margin-left: 0; }
  .language-card { width: 100%; }
}

@media (max-width: 600px) {
  .profile-image img { width: 110px; height: 110px; }
  .header-content p { font-size: clamp(1rem, 3.5vw, 1.2rem); }
  .info-card { padding: 20px; }
  .publication-card { padding: 20px; }
}

@media (max-width: 480px) {
  .section { padding: 22px 14px; }
}

@media (max-width: 360px) {
}

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

html {
    /* The scrolling element is <html>, not <body>: declared on body this had
       no effect and anchor links jumped instead of gliding. */
    scroll-behavior: smooth;
    /* Anchors land below the fixed navbar instead of underneath it. */
    scroll-padding-top: var(--anchor-offset);
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

nav {
    position: fixed;
    top: 0;
    left: 0;             /* Always anchor to the physical left, even in Arabic */
    width: 100vw;        /* Force full viewport width, ignoring RTL flow */
    
    background: rgba(26, 31, 46, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 1000;
    padding: 16px 0;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 2px 12px var(--shadow-color);
    
    /* Animation settings */
    transition: transform 0.3s ease;
    will-change: transform;
    
    /* SAFARI FIX: Promotes layer to GPU to prevent disappearance in RTL */
    -webkit-transform: translateZ(0);
    transform: translateZ(0); 
}

body.light-theme nav,
html.pre-light body nav {
    background: rgba(255, 255, 255, 0.95);
}

nav.nav-hidden {
  transform: translateY(-100%);
  transition: transform 0.4s ease;
}

.nav-container {
    width: 90%;
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

nav .logo a {
    color: var(--primary-color);
    font-size: 1.5em;
    font-weight: 700;
    text-decoration: none;
    transition: color 0.3s ease;
}

nav .logo a:hover {
    color: var(--accent-color);
}

nav ul {
    list-style: none;
    display: flex;
    gap: 8px;
}

nav ul li a {
    color: var(--text-color);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95em;
    padding: 8px 16px;
    border-radius: 8px;
    transition: all 0.3s ease;
    position: relative;
}

nav ul li a:hover {
    color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

.controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.language-selector {
    position: relative;
    display: inline-block;
}

#languageButton {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9em;
    transition: all 0.3s ease;
}

#languageButton:hover {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

.language-dropdown {
    display: none;
    position: absolute;
    top: 45px;
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    list-style: none;
    padding: 8px;
    margin: 0;
    width: 140px;
    z-index: 100;
    box-shadow: 0 4px 12px var(--shadow-color);
}

.language-dropdown li {
    padding: 10px 14px;
    cursor: pointer;
    color: var(--text-color);
    border-radius: 6px;
    transition: all 0.2s ease;
    font-size: 0.9em;
}

.language-dropdown li:hover {
    background: var(--primary-color);
    color: white;
}

.lang-switcher {
    display: flex;
    gap: 8px;
    background: var(--card-bg);
    padding: 4px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.lang-switcher button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    font-size: 0.85em;
}

.lang-switcher button:hover {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary-color);
}

.lang-switcher button[aria-pressed="true"] {
    background: var(--primary-color);
    color: white;
}

header {
    position: relative;
    min-height: 100vh;
    height: auto;
    /* Clears the fixed navbar and lets the hero grow on short screens rather
       than centring content that no longer fits and clipping the title. */
    padding: calc(var(--anchor-offset) + 24px) 0 48px;
    box-sizing: border-box;
    /* source.unsplash.com was retired and now 503s on every load; the hero is
       painted entirely in CSS instead. */
    background:
        radial-gradient(90% 70% at 15% 0%, rgba(var(--primary-rgb), 0.22), transparent 60%),
        radial-gradient(80% 70% at 85% 100%, rgba(var(--accent-rgb), 0.20), transparent 60%),
        linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(236, 72, 153, 0.12)),
        var(--bg-color);
    background-attachment: fixed;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.header-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 20, 25, 0.75);
}

body.light-theme .header-overlay,
html.pre-light body .header-overlay {
    background: rgba(255, 255, 255, 0.85);
}

.header-content {
    position: relative;
    z-index: 1;
    color: var(--text-color);
    animation: fadeInDown 1s ease-out;
    max-width: 800px;
    padding: 0 20px;
}

.header-content h1 {
    font-size: clamp(2.5em, 6vw, 4em);
    margin-bottom: 16px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--gradient-start), var(--gradient-end));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-content p {
    font-size: clamp(1.1em, 3vw, 1.5em);
    color: var(--text-secondary);
    font-weight: 400;
}

.scroll-indicator {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    cursor: pointer;
    z-index: 2;
}

.scroll-indicator span {
    display: block;
    width: 28px;
    height: 28px;
    border-bottom: 2px solid var(--primary-color);
    border-right: 2px solid var(--primary-color);
    transform: rotate(45deg);
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% { transform: rotate(45deg) translateY(0); }
    40% { transform: rotate(45deg) translateY(10px); }
    60% { transform: rotate(45deg) translateY(5px); }
}

.section {
    position: relative;
    background: var(--section-bg);
    border-radius: 16px;
    margin: 80px auto;
    padding: 60px 40px;
    width: 90%;
    max-width: 1200px;
    overflow: hidden;
    opacity: 0;
    transform: translateY(50px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 24px var(--shadow-color);
}

.section.in-view {
    opacity: 1;
    transform: translateY(0);
}

.section h2 {
    font-size: clamp(1.8em, 4vw, 2.5em);
    margin-bottom: 32px;
    color: var(--primary-color);
    font-weight: 700;
    position: relative;
    display: inline-block;
    padding-bottom: 12px;
}

.section h2::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 60%;
    height: 3px;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
    border-radius: 2px;
}

.container {
    width: 100%;
}

.info-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.info-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 28px 24px;
    border-radius: 12px;
    box-shadow: 0 2px 8px var(--shadow-color);
    text-align: center;
    transition: all 0.3s ease;
}

.info-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px var(--shadow-color);
    border-color: var(--primary-color);
}

.info-card h3 {
    font-size: 1.1em;
    margin-bottom: 12px;
    color: var(--primary-color);
    font-weight: 600;
}

.info-card p {
    font-size: 0.95em;
    margin: 0;
    color: var(--text-secondary);
}

.info-card a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s ease;
}

.info-card a:hover {
    color: var(--accent-color);
}

.profile-section {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.05), rgba(236, 72, 153, 0.05));
    padding: 40px;
    border-radius: 16px;
}

.profile-content {
    display: flex;
    align-items: center;
    gap: 32px;
    margin-top: 24px;
    animation: fadeIn 1s ease-out;
    flex-wrap: wrap;
}

.profile-text {
    flex: 1 1 340px;
    min-width: 0;
}

.profile-image img {
    border-radius: 50%;
    width: 150px;
    height: 150px;
    object-fit: cover;
    border: 4px solid var(--primary-color);
    box-shadow: 0 4px 16px var(--shadow-color);
    transition: transform 0.3s ease;
}

.profile-image img:hover {
    transform: scale(1.08);
}

.profile-text h3 {
    color: var(--primary-color);
    margin-bottom: 12px;
    font-size: clamp(1.15rem, 4.6vw, 1.6rem);
    line-height: 1.25;
    font-weight: 700;
}

.profile-text p {
    font-size: clamp(0.95rem, 3.6vw, 1rem);
    line-height: 1.6;
    margin-bottom: 12px;
    color: var(--text-secondary);
    text-wrap: pretty;
}

@media (max-width: 600px) {
  .profile-section { padding: 12px; }            
  .profile-content { gap: 12px; align-items: flex-start; }
  .section { padding: 22px 12px; width: 96%; }   
  .section h2 {                                  
    font-size: clamp(1.1rem, 5vw, 1.5rem);
    margin-bottom: 16px;
  }
}

.formation-timeline {
    list-style: none;
    padding-left: 0;
    margin-top: 24px;
    position: relative;
    padding-left: 0;
}

.formation-timeline::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 28px;
  width: 2px;
  background: var(--border-color);
}

.formation-item {
    display: flex;
    align-items: flex-start;
    margin-bottom: 28px;
    position: relative;
    padding-left: 0;
    padding: 20px 20px 20px 64px; 
    background: var(--card-bg);
    border-radius: 12px;
    transition: all 0.3s ease;
    border-left: none;            
}

.formation-item:hover {
    transform: translateX(4px);
    box-shadow: 0 4px 16px var(--shadow-color);
}

.formation-item::before {
    content: "";
    position: absolute;
    left: 22px;
    top: 28px;
    width: 12px;
    height: 12px;
    background: var(--primary-color);
    border-radius: 50%;
    box-shadow: 0 0 0 4px var(--section-bg);
}

.formation-icon {
    font-size: 1.8em;
    margin-right: 16px;
}

.formation-content h3 {
    margin: 0 0 8px 0;
    color: var(--primary-color);
    font-weight: 600;
    font-size: 1.2em;
}

.formation-content p {
    margin: 6px 0;
    font-size: 0.95em;
    color: var(--text-secondary);
}

.cert-link {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 0.9em;
    font-weight: 500;
    transition: color 0.3s ease;
}

.cert-link:hover {
    color: var(--accent-color);
    text-decoration: underline;
}

.publication-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 32px;
    box-shadow: 0 4px 16px var(--shadow-color);
    border: 1px solid var(--border-color);
    animation: fadeIn 1s ease-out;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.pub-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 16px;
    margin-bottom: 16px;
}

.pub-date,
.pub-location {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 0.95em;
}

.pub-body {
    font-size: 1.05em;
    line-height: 1.7;
    color: var(--text-secondary);
}

.pub-footer {
    margin-top: 16px;
    text-align: right;
}

.publication-link {
    display: inline-block;
    background: var(--primary-color);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.publication-link:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.table-wrapper {
    max-height: 240px;
    overflow-y: auto;
    margin-top: 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.sample-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed; 
}

.sample-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}

.sample-table th,
.sample-table td {
    border: 1px solid var(--border-color);
    padding: 12px;
    text-align: left;
    font-size: 0.9em;
}

.sample-table td.preview {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sample-table th {
    background: var(--primary-color);
    color: white;
    font-weight: 600;
}

.sample-table td {
    color: var(--text-secondary);
}

/* Horizontal scroller. The scrollbar is deliberately visible so the row reads
   as scrollable, and scroll-snap keeps cards aligned while swiping. */
.projects-scroll {
    display: flex;
    gap: 24px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 20px 4px 28px;
    scroll-snap-type: x proximity;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) var(--card-bg);
    overscroll-behavior-x: contain;
}

.projects-scroll::-webkit-scrollbar {
    height: 10px;
}
.projects-scroll::-webkit-scrollbar-track {
    background: var(--card-bg);
    border-radius: 5px;
}
.projects-scroll::-webkit-scrollbar-thumb {
    background: linear-gradient(90deg, var(--gradient-start), var(--gradient-end));
    border-radius: 5px;
}

/* These must stay after the responsive blocks earlier in the file, which is
   why the overrides live here rather than up there. */
.projects-scroll .flip-card {
    flex: 0 0 auto;
    scroll-snap-align: start;
    width: clamp(260px, 42vw, 300px);
    height: 340px;
}

@media (max-width: 768px) {
    .projects-scroll .flip-card { width: 82vw; height: 360px; }
}
@media (max-width: 480px) {
    .projects-scroll .flip-card { width: 86vw; height: 380px; }
}

.flip-card {
    background: transparent;
    width: 300px;
    height: 320px;
    perspective: 1000px;
    cursor: pointer; 
    outline: none; 
}

.flip-card:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 4px;
    border-radius: 12px;
}

.flip-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.8s;
    transform-style: preserve-3d;
}

.flip-card.flipped .flip-card-inner {
  transform: rotateY(180deg);
}

@media (hover: hover) and (pointer: fine) {
  .flip-card:hover .flip-card-inner {
    transform: rotateY(180deg);
  }
}

.flip-card-front,
.flip-card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px;
    box-shadow: 0 4px 16px var(--shadow-color);
    border: 1px solid var(--border-color);
}

.flip-card-front {
    background: linear-gradient(135deg, var(--gradient-start), var(--gradient-end));
    color: white;
}

.flip-card-front h3 {
    margin-bottom: 16px;
    font-weight: 700;
    font-size: 1.3em;
}

.flip-card-front p {
    font-size: 0.95em;
    line-height: 1.5;
}

.flip-card-front .hover-text {
    font-size: 0.8em;
    margin-top: 16px;
    opacity: 0.9;
    font-style: italic;
}

.flip-card-back {
    background: var(--card-bg);
    color: var(--text-color);
    transform: rotateY(180deg);
    overflow-y: auto;
    overscroll-behavior: contain;
    /* Vertically centred. "safe" keeps the top reachable if a description ever
       does overflow, instead of clipping it out of scroll range. */
    justify-content: safe center;
}

.flip-card-back h3 {
    margin-bottom: 16px;
    color: var(--primary-color);
    font-weight: 700;
}

.flip-card-back p {
    font-size: 0.9em;
    margin-bottom: 20px;
    line-height: 1.6;
    color: var(--text-secondary);
}

/* Without this the trailing 20px margin pushes the text off-centre on cards
   that have no links row below the description. */
.flip-card-back p:last-child {
    margin-bottom: 0;
}

.github-link {
    display: inline-block;
    margin-top: 12px;
    color: var(--primary-color);
    font-weight: 600;
    text-decoration: none;
    transition: color 0.3s;
    font-size: 0.9em;
}

.github-link:hover {
    color: var(--accent-color);
    text-decoration: underline;
}

.experience-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    margin-top: 24px;
}

.experience-card {
    position: relative;
    background: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px var(--shadow-color);
    border: 1px solid var(--border-color);
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.experience-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px var(--shadow-color);
}

.experience-media {
    position: relative;
    width: 100%;
    height: 180px;
    overflow: hidden;
}

.experience-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.5s ease;
}

.experience-details {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(
    135deg,
    rgba(var(--primary-rgb), 0.95),
    rgba(var(--accent-rgb), 0.95)
  );
    color: white;
    padding: 20px;
    text-align: center;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.experience-details {
  display: flex;
  flex-direction: column;   
  align-items: center;      
  text-align: center;
}

.experience-details p {
  margin: 0 0 8px 0;        
}

.experience-details a {
  display: block;           
  margin-top: 8px;
}

.experience-card:hover .experience-img {
    opacity: 0;
}

.experience-card:hover .experience-details {
    opacity: 1;
}

.experience-img-logo {
    background: #fff;
    object-fit: contain;
    padding: 1.35rem;
}

/* Avignon publishes a white-on-transparent mark, so it needs a dark plate. */
.experience-img-dark {
    background: var(--section-bg);
}

/* Touch and keyboard users get the same detail overlay as hover. */
.experience-card.revealed .experience-img {
    opacity: 0;
}
.experience-card.revealed .experience-details,
.experience-card:focus-visible .experience-details {
    opacity: 1;
}
.experience-card:focus-visible .experience-img {
    opacity: 0;
}
.experience-card:focus-visible,
.flip-card:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 3px;
}

.experience-details a {
    color: white;
    text-decoration: underline;
}

.experience-card h3 {
    margin: 20px 0;
    color: var(--primary-color);
    font-weight: 600;
    font-size: 1.2em;
    padding: 0 16px;
}

.experience-details .xp-highlights {
  margin-top: 8px;
  text-align: left;
  list-style: disc;
  padding-left: 18px;
  font-size: 0.9em;
  line-height: 1.5;
}
.experience-details .xp-highlights li {
  margin: 4px 0;
}

.skills-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 24px;
    margin-top: 24px;
}

.skill-card {
    position: relative;
    background: var(--card-bg);
    padding: 28px 24px;
    border-radius: 12px;
    box-shadow: 0 2px 8px var(--shadow-color);
    border: 1px solid var(--border-color);
    text-align: left;
    transition: all 0.5s ease;
    transform: scale(0.95);
    opacity: 0;
}

.skill-card.in-view {
    transform: scale(1);
    opacity: 1;
}

.section.in-view .skill-card,
.section.in-view .language-card {
  opacity: 1;
  transform: scale(1);
}

.skill-card h3 {
    color: var(--primary-color);
    margin-bottom: 20px;
    font-size: 1.4em;
    text-align: center;
    font-weight: 700;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border-color);
}

.skill-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.skill-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.skill-list li:last-child {
    border-bottom: none;
}

.skill-name {
    font-weight: 600;
    flex: 1;
    color: var(--text-color);
    font-size: 0.95em;
}

.skill-bar {
    background: var(--border-color);
    width: 50%;
    height: 8px;
    border-radius: 4px;
    margin-left: 16px;
    overflow: hidden;
    position: relative;
}

.skill-progress {
    background: linear-gradient(90deg, var(--gradient-start), var(--gradient-end));
    height: 100%;
    width: 0;
    transition: width 1s ease-out;
    border-radius: 4px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
  padding: 0;
  list-style: none;
}
.tag {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: rgba(var(--primary-rgb), 0.08);
  color: var(--text-color);
  font-size: 0.9em;
  font-weight: 600;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}
.tag:hover {
  border-color: var(--primary-color);
  background: rgba(var(--primary-rgb), 0.12);
  transform: translateY(-1px);
}

.language-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 10px;
}
.level-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--primary-color);
  color: #fff;
  font-weight: 700;
  font-size: 0.85em;
  box-shadow: 0 2px 6px rgba(var(--primary-rgb), 0.25);
}
.level-dots {
  display: inline-flex;
  gap: 6px;
}
.level-dots .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-color);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.05);
}
.level-dots .dot.active {
  background: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(var(--primary-rgb), 0.2);
}

.skill-card .tag-list {
  margin-top: 8px;
}

.languages-grid {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 24px;
}

.language-card {
    width: min(280px, 100%);
    flex-shrink: 0;
    background: var(--card-bg);
    padding: 32px 24px;
    border-radius: 12px;
    box-shadow: 0 2px 8px var(--shadow-color);
    border: 1px solid var(--border-color);
    text-align: center;
    transition: all 0.5s ease;
    transform: scale(0.95);
    opacity: 0;
}

.language-card.in-view {
    transform: scale(1);
    opacity: 1;
}

.language-card h3 {
    font-size: 1.2em;
    margin-bottom: 16px;
    color: var(--primary-color);
    font-weight: 700;
}

.language-card p {
    font-size: 0.9em;
    margin: 12px 0 0;
    color: var(--text-secondary);
}

footer {
    background: var(--section-bg);
    color: var(--text-secondary);
    text-align: center;
    padding: 32px 0;
    margin-top: 60px;
    border-top: 1px solid var(--border-color);
}

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

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

.hamburger {
    display: none;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 1.5em;
    cursor: pointer;
    color: var(--text-color);
    transition: all 0.3s ease;
    flex-direction: column;
    width: 40px;
    height: 40px;
    justify-content: center;
    align-items: center;
}

.hamburger:hover {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

.hamburger span {
    width: 20px;
    height: 2px;
    background: var(--text-color);
    margin: 2px 0;
    transition: 0.3s;
    display: block;
}

.hamburger.active span:nth-child(1) {
    transform: rotate(-45deg) translate(-5px, 6px);
}

.hamburger.active span:nth-child(2) {
    opacity: 0;
}

.hamburger.active span:nth-child(3) {
    transform: rotate(45deg) translate(-5px, -6px);
}



.lang-switcher {
    display: flex;
    gap: 4px;
    background: var(--card-bg);
    padding: 2px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.lang-switcher button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    font-size: 0.8em;
    min-width: 32px;
}

@media (max-width: 768px) {
    .nav-links {
        display: none;
    }
    
    .hamburger {
        display: flex;
    }
    
    .controls {
        gap: 8px;
    }
    
    .lang-switcher {
        display: none;
    }
    
    .nav-container {
        gap: 10px;
    }
    
    nav .logo a {
        font-size: 1.3em;
    }
}

@media (max-width: 480px) {
  .formation-item {
    padding: 14px 12px 14px 38px; 
    display: block;
  }
  .formation-timeline::before { left: 12px; }
  .formation-item::before { top: 18px; left: 8px; }

  .formation-icon{
    display: block;
    margin: 2px 0 10px 0;
  }

  [dir="rtl"] .formation-item { padding-right: 38px; padding-left: 12px; }
  [dir="rtl"] .formation-timeline::before { right: 12px; }
  [dir="rtl"] .formation-item::before { right: 8px; }
  [dir="rtl"] .formation-icon { margin-left: 0; }

  .info-cards {
      grid-template-columns: 1fr;
  }
  
  .skills-grid {
      grid-template-columns: 1fr;
  }
  
  .experience-grid {
      grid-template-columns: 1fr;
  }
}

.card-links {
  display: inline-flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  margin-top: 8px;
}
.card-links .github-link {
  margin-top: 0; 
}

.cert-preview {
  margin-top: 10px;
}
.cert-preview .pdf-embed {
  width: 100%;
  height: 240px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 2px 8px var(--shadow-color);
}

.skill-category {
  margin-bottom: 18px;
}

.skill-category h4 {
  color: var(--primary-color);
  font-size: 1.05em;
  margin-bottom: 8px;
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 4px;
}

.skills-category-container {
  margin-bottom: 60px;
}

.skills-category-title {
  font-size: 1.8em;
  color: var(--primary-color);
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
  position: relative;
}

.skills-category-title::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 120px;
  height: 3px;
  background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
  border-radius: 2px;
}

.skill-card {
  padding: 30px;
  border-radius: 12px;
  background: var(--card-bg);
  box-shadow: 0 4px 20px var(--shadow-color);
  border: 1px solid var(--border-color);
  height: 100%;
  display: flex;
  flex-direction: column;
  transition: all 0.4s ease;
}

.skill-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 30px var(--shadow-color);
  border-color: var(--primary-color);
}

.skill-card-header {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.skill-icon {
  font-size: 2rem;
  margin-right: 15px;
}

.skill-card-header h4 {
  font-size: 1.5em;
  font-weight: 700;
  color: var(--primary-color);
  margin: 0;
}

.skill-content {
  flex: 1;
}

.skill-group {
  margin-bottom: 24px;
}

.skill-group:last-child {
  margin-bottom: 0;
}

.skill-group h5 {
  font-size: 1.05em;
  color: var(--text-color);
  margin-bottom: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
}

.skill-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tag {
  padding: 6px 14px;
  border-radius: 30px;
  background: rgba(var(--primary-rgb), 0.08);
  color: var(--text-color);
  font-size: 0.9em;
  font-weight: 500;
  border: 1px solid var(--border-color);
  transition: all 0.3s ease;
}

.tag:hover {
  background: rgba(var(--primary-rgb), 0.15);
  transform: translateY(-2px);
  border-color: var(--primary-color);
}

.tag-featured {
  background: rgba(var(--primary-rgb), 0.18);
  border-color: var(--primary-color);
  font-weight: 600;
}


.feature-list {
  padding-left: 20px;
  margin: 0;
  color: var(--text-secondary);
}

.feature-list li {
  margin-bottom: 8px;
  line-height: 1.5;
}

.skill-group .feature-list {
  list-style: none;
  padding: 0;
  margin: 8px 0;
  display: grid;
  gap: 10px;                          
}

.skill-group .feature-list li {
  position: relative;
  padding: 10px 12px 10px 36px;       
  background: rgba(var(--primary-rgb), 0.06);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  font-size: 0.92em;
  line-height: 1.45;
  color: var(--text-color);
  transition: border-color 0.2s ease, transform 0.2s ease, background 0.2s ease;
}

.skill-group .feature-list li::before {
  content: "✓";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 50%;
  background: var(--primary-color);
  color: #fff;
  font-weight: 700;
  font-size: 0.75em;
  box-shadow: 0 0 0 2px rgba(var(--primary-rgb), 0.2);
}

.skill-group .feature-list li:hover {
  border-color: var(--primary-color);
  background: rgba(var(--primary-rgb), 0.09);
  transform: translateY(-1px);
}

[dir="rtl"] .skill-group .feature-list li {
  padding: 10px 36px 10px 12px;       
}
[dir="rtl"] .skill-group .feature-list li::before {
  left: auto;
  right: 12px;
}

.soft-skills-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-top: 30px;
}

.soft-skill-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 25px 20px;
  text-align: center;
  box-shadow: 0 4px 15px var(--shadow-color);
  border: 1px solid var(--border-color);
  transition: all 0.4s ease;
}

.soft-skill-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px var(--shadow-color);
  border-color: var(--primary-color);
}

.soft-skill-icon {
  font-size: 2.5rem;
  margin-bottom: 15px;
}

.soft-skill-card h4 {
  font-size: 1.2em;
  font-weight: 600;
  color: var(--primary-color);
  margin-bottom: 12px;
}

.soft-skill-card p {
  color: var(--text-secondary);
  font-size: 0.9em;
  line-height: 1.6;
}

@media (max-width: 768px) {
  .skill-columns {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .soft-skills-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }
  
  .skill-card-header {
    flex-direction: column;
    text-align: center;
  }
  
  .skill-icon {
    margin-right: 0;
    margin-bottom: 10px;
  }
  
  .skills-category-title {
    font-size: 1.6em;
  }
}

@media (max-width: 480px) {
  .soft-skills-grid {
    grid-template-columns: 1fr;
  }
  
  .skill-card {
    padding: 20px;
  }
}

.nav-hover-zone {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 10px; 
  z-index: 999; 
  background: transparent;
}

.nav-hover-zone:hover + nav,
nav:hover {
  transform: translateY(0) !important; 
}



[dir="rtl"] .flip-card-front,
[dir="rtl"] .flip-card-back {
  direction: rtl; 
}

[dir="rtl"] .flip-card.flipped .flip-card-inner {
  transform: rotateY(-180deg);
}

@media (hover: hover) and (pointer: fine) {
  [dir="rtl"] .flip-card:hover .flip-card-inner {
    transform: rotateY(-180deg);
  }
}
[dir="rtl"] .flip-card-back {
  transform: rotateY(-180deg); 
}

[dir="rtl"] .skill-icon {
  margin-right: 0;
  margin-left: 15px;
}

[dir="rtl"] .section h2::after,
[dir="rtl"] .skills-category-title::after {
  left: auto;
  right: 0;
}

[dir="rtl"] .formation-timeline::before {
  left: auto;
  right: 28px;
}

[dir="rtl"] .formation-item {
  padding-left: 20px;
  padding-right: 64px;
}

[dir="rtl"] .formation-item::before {
  left: auto;
  right: 22px;
}

[dir="rtl"] .formation-icon {
  margin-right: 0;
  margin-left: 16px;
}

[dir="rtl"] .feature-list {
  padding-left: 0;
  padding-right: 20px;
}

[dir="rtl"] nav.nav-hidden {
  transform: translateY(-100%);
  transition: transform 0.4s ease;
}

[dir="rtl"] .nav-hover-zone:hover + nav,
[dir="rtl"] nav:hover {
  transform: translateY(0) !important;
}

[dir="rtl"] .profile-text,
[dir="rtl"] .flip-card p,
[dir="rtl"] .publication-card,
[dir="rtl"] .formation-content,
[dir="rtl"] .language-card,
[dir="rtl"] .soft-skill-card p {
  text-align: right;
}

[dir="rtl"] .card-links,
[dir="rtl"] .language-meta {
  justify-content: right;
}

[dir="rtl"] .flip-card-front h3,
[dir="rtl"] .flip-card-front h3,
[dir="rtl"] .flip-card-back h3,
[dir="rtl"] .flip-card-front p,
[dir="rtl"] .flip-card-back p {
  width: 100%;
  text-align: center;
}

[dir="rtl"] .hover-text {
  width: 100%;
  text-align: right;
  direction: rtl;
}

[dir="rtl"] .profile-text h3 { letter-spacing: 0; }

@media (max-width: 768px) {
  .nav-links {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 60px;
    right: 0;
    width: 100%;
    background-color: var(--background, white);
    text-align: right;
    padding: 1rem;
    z-index: 1000;
  }

  .hover-text {
    font: 10px
  }
  .nav-links.active {
    display: flex;
  }
}

.hover-text {
  font-size: 1rem;   
}
html[dir="ltr"] .hover-text {
  text-align: left;
  direction: ltr;
}
@media (max-width: 768px) {
  .hover-text {
    font-size: 0.9rem;
  }
}

@media (max-width: 480px) {
  .hover-text {
    font-size: 0.8rem;  
  }
}
.lang-switcher .lang-options {
  display: none;
}

.lang-switcher.open .lang-options {
  display: block;
}

.lang-switcher {
  position: relative;
  display: inline-block;
}

.formation-content p {
  margin: 0.3rem 0; 
}

.formation-content .cert-link {
  display: block;   
  margin-top: 0.4rem;
  font-size: 0.9rem; 
}

.formation-content {
  display: grid;
  gap: 6px;                
}

.formation-content p {
  display: block !important;
  margin: 0;               
}

.formation-content .cert-link {
  display: inline-block;   
  margin-top: 4px;         
  font-size: 0.9rem;       
}

.lang-options {
  display: none;
  position: absolute;
  right: 0;
  background-color: var(--card-bg);
  border: 1px solid var(--text-color, #333);
  border-radius: 5px;
  margin-top: 0.4rem;
  z-index: 1000;
}

.lang-options button {
  display: block;
  width: 100%;
  padding: 0.4rem 0.8rem;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  font-size: 0.9rem;
}
.lang-options button {
  color: var(--text-color);
  white-space: nowrap;
  border-radius: 4px;
  transition: background-color 0.2s ease, color 0.2s ease;
}
.lang-options button:hover,
.lang-options button:focus-visible {
  background-color: rgba(var(--primary-rgb), 0.14);
  color: var(--primary-color);
}
.lang-options button.is-active {
  font-weight: 700;
  color: var(--primary-color);
}
.lang-options button.is-active::after {
  content: " ✓";
}
[dir="rtl"] .lang-options {
  right: auto;
  left: 0;
}
[dir="rtl"] .lang-options button {
  text-align: right;
}

@media screen and (max-width: 1175px) {
  .burger {
    display: flex;
    flex-direction: column;
    gap: 5px;
    cursor: pointer;
    z-index: 1001;
    margin-left: auto;
  }

  .burger div {
    width: 25px;
    height: 3px;
    background-color: var(--text-color, #333);
    transition: all 0.3s ease;
  }

  .nav-links {
    display: none;
    flex-direction: column;
    background-color: var(--card-bg);
    position: absolute;
    top: 100%;
    right: 0;
    width: 100%;
    padding: 1.5rem 1rem;
    z-index: 1000;
    box-shadow: 0 8px 20px var(--shadow-color);
    border-top: 1px solid var(--border-color);
    border-radius: 0 0 12px 12px;
    text-align: center;
  }

  .nav-links.nav-active {
    display: flex;
  }

  .nav-links li {
    margin: 0.75rem 0;
  }

  .nav-container {
    justify-content: space-between;
    align-items: center;
  }

  .controls {
    display: flex;
    gap: 10px;
    align-items: center;
  }

  .controls > * {
    margin-left: 6px;
  }

  .burger {
    margin-left: 10px;
  }
}

#themeToggle {
    background: transparent;
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 1.4em;
    cursor: pointer;
    color: var(--text-color);
    transition: all 0.3s ease;
}

.lang-toggle {
    background: transparent;
    padding: 2.5px 10px;
    border-radius: 8px;
    font-size: 1.4em;
    cursor: pointer;
    color: var(--text-color);
    transition: all 0.3s ease;
}

#themeToggle:hover,
.lang-toggle:hover {
  background-color: rgba(255, 255, 255, 0.05);
      border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
    transform: scale(1.05);

}

@media (max-width: 820px), (pointer: coarse) {
  .section,
  .skill-card,
  .language-card {
    opacity: 1 !important;
    transform: none !important;
  }
}

[dir="rtl"] .experience-details .xp-highlights {
  list-style: none;       
  margin: 0;
  padding: 0;             
  direction: rtl;         
  text-align: right;      
}

[dir="rtl"] .experience-details .xp-highlights li {
  position: relative;
  padding-right: 1.2rem;  
  margin: 6px 0;
}

[dir="rtl"] .experience-details .xp-highlights li::before {
  content: "•";
  position: absolute;
  right: 0;              
  top: 0.3em;
  font-size: 1.1em;
  color: #fff;
}

.skill-card .tag,
.skill-card .feature-list li {
  user-select: none;     
  cursor: default;       
}

.tag:hover {
  border-color: var(--primary-color);
  background: rgba(var(--primary-rgb), 0.12);
  transform: translateY(-1px);
}

.tag-featured {
  background: rgba(var(--primary-rgb), 0.08); 
  border-color: var(--border-color); 
  font-weight: 500;
}

.hover-text {
  font-size: 0.9rem;     
  text-align: center;    
  margin: 0.5rem 0;
}

html[dir="rtl"] .hover-text {
  text-align: right;     
  direction: rtl;        
}

/* Arabic inherits dir="rtl" from <html>, so the grid flows right-to-left on
   its own; the old direction overrides existed only for the scroller. */





#chat-toggle{
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  user-select: none;
  background: #6b5cff;
  color: #fff;
  box-shadow: 0 18px 45px rgba(0,0,0,.35);
  z-index: 9999;
}

#chatbox{
  position: fixed;
  right: 22px;
  bottom: 92px;
  width: min(380px, calc(100vw - 44px));
  height: min(560px, calc(100vh - 140px));
  background: rgba(16, 16, 22, .92);
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 18px;
  box-shadow: 0 25px 70px rgba(0,0,0,.45);
  overflow: hidden;
  z-index: 9999;
  backdrop-filter: blur(12px);
}

.hidden{ display:none; }

#chatbox .chat-header{
  height: 56px;
  padding: 0 14px 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,.04);
  border-bottom: 1px solid rgba(255,255,255,.08);
}

#chatbox .chat-header span{
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .2px;
  color: rgba(255,255,255,.92);
}

#chat-close{
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.9);
  cursor: pointer;
}

#chat-close:hover{
  background: rgba(255,255,255,.10);
}

#chatbox .chat-body{
  height: calc(100% - 56px - 64px);
  padding: 14px;
}

#chatbox .chat-messages{
  height: 100%;
  overflow-y: auto;
  padding-right: 6px;
}

#chatbox .chat-messages::-webkit-scrollbar{ width: 8px; }
#chatbox .chat-messages::-webkit-scrollbar-thumb{
  background: rgba(255,255,255,.12);
  border-radius: 10px;
}
#chatbox .chat-messages::-webkit-scrollbar-thumb:hover{
  background: rgba(255,255,255,.18);
}

.chat-bubble{
  max-width: 86%;
  padding: 10px 12px;
  border-radius: 14px;
  margin: 8px 0;
  line-height: 1.35;
  font-size: 13px;
  color: rgba(255,255,255,.92);
  word-wrap: break-word;
}

.chat-bubble.user{
  margin-left: auto;
  background: rgba(107, 92, 255, .28);
  border: 1px solid rgba(107, 92, 255, .40);
}

.chat-bubble.bot{
  margin-right: auto;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.10);
}

#chatbox .chat-form{
  height: 64px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px 12px;
  border-top: 1px solid rgba(255,255,255,.08);
  background: rgba(16, 16, 22, .75);
}

#chat-input{
  width: 100%;
  height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.92);
  padding: 0 12px;
  outline: none;
}

#chat-input::placeholder{ color: rgba(255,255,255,.45); }

#chat-input:focus{
  border-color: rgba(107, 92, 255, .55);
  box-shadow: 0 0 0 4px rgba(107, 92, 255, .18);
}

.chat-send{
  height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.10);
  background: #6b5cff;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.chat-send:hover{ filter: brightness(1.05); }
.chat-send:disabled{ opacity: .6; cursor: not-allowed; }

@media (max-width: 520px){
  #chatbox{
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 86px;
    height: min(520px, calc(100vh - 120px));
  }
  #chat-toggle{
    right: 14px;
    bottom: 14px;
  }
}

#chat-toggle {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 2000;
  background: var(--primary-color);
  color: #fff;
  text-decoration: none;
  padding: 10px 14px;
  border-radius: 999px;
  font-weight: 700;
  border: 1px solid var(--border-color);
  box-shadow: 0 6px 18px var(--shadow-color);
}
#chat-toggle:hover { background: var(--primary-hover); }

.chatbox.hidden { display: none; }

.chatbox {
  position: fixed;
  right: 18px;
  bottom: 68px;
  width: min(360px, calc(100vw - 36px));
  height: 420px;
  z-index: 2000;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  box-shadow: 0 10px 28px var(--shadow-color);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chatbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
}

.chatbox-title { font-weight: 800; color: var(--primary-color); }

#chat-close {
  background: transparent;
  border: none;
  color: var(--text-color);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.chatbox-messages {
  padding: 12px;
  overflow: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chatbox-form {
  display: flex;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--border-color);
}

#chat-input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--section-bg);
  color: var(--text-color);
}

.chatbox-form button {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--primary-color);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
.chatbox-form button:hover { background: var(--primary-hover); }

.chat-bubble {
  max-width: 85%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  line-height: 1.4;
  font-size: 0.95em;
}
.chat-bubble.user { align-self: flex-end; background: rgba(var(--primary-rgb), 0.12); }
.chat-bubble.bot  { align-self: flex-start; background: rgba(var(--accent-rgb), 0.10); }
.chat-bubble.pending { opacity: 0.6; font-style: italic; }
.chat-bubble.error { background: rgba(220, 80, 80, 0.12); }

#chat-toggle {
  display: block !important;
  position: fixed !important;
  right: 18px !important;
  bottom: 18px !important;
  z-index: 999999 !important;
  background: #2e98e3 !important;
  color: #ffffff !important;
  padding: 12px 16px !important;
  border-radius: 999px !important;
  font-weight: 800 !important;
}

.chat-toggle {
  position: fixed;
  bottom: 22px;
  right: 22px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 10px 25px rgba(0,0,0,0.25);
  z-index: 9999;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 14px 30px rgba(0,0,0,0.3);
}

#chat-toggle.chat-toggle{
  width: 58px !important;
  height: 58px !important;
  padding: 0 !important;
  border-radius: 50% !important;
  border: 1px solid rgba(255,255,255,0.12) !important;
  background: linear-gradient(135deg, var(--gradient-start), var(--gradient-end)) !important;
  color: #fff !important;
  font-size: 28px !important;
  line-height: 1 !important;
  display: grid !important;
  place-items: center !important;
}

#chat-toggle.chat-toggle:hover{
  transform: scale(1.08) !important;
}
#chat-toggle.chat-toggle:hover{
  transform: scale(1.08) !important;
}

#chat-toggle{
  position: fixed !important;
  right: 22px !important;
  bottom: 22px !important;
  z-index: 999999 !important;

  width: 58px !important;
  height: 58px !important;
  padding: 0 !important;
  border-radius: 50% !important;

  display: grid !important;
  place-items: center !important;

  background-color: transparent !important;
  background-image: linear-gradient(135deg, var(--gradient-start), var(--gradient-end)) !important;

  border: 1px solid rgba(255,255,255,0.12) !important;
  box-shadow: 0 18px 45px rgba(0,0,0,.35) !important;

  color: #fff !important;
  font-weight: 800 !important;
  text-decoration: none !important;
  line-height: 1 !important;
  font-size: 28px !important;
}

#chat-toggle i{
  font-size: 28px !important;
  line-height: 1 !important;
}

#chat-toggle svg{
  width: 28px !important;
  height: 28px !important;
  display: block !important;
}

#chat-toggle:hover{
  transform: scale(1.08) !important;
}

/* ===================== POLISH ENHANCEMENTS ===================== */

/* Hero: replace dead Unsplash bg with layered brand glow */
#header {
  background:
    radial-gradient(55% 45% at 18% 22%, rgba(var(--primary-rgb),0.22), transparent 60%),
    radial-gradient(50% 42% at 82% 28%, rgba(var(--accent-rgb),0.20), transparent 60%),
    radial-gradient(75% 60% at 50% 108%, rgba(var(--primary-rgb),0.10), transparent 70%),
    var(--bg-color) !important;
  background-attachment: scroll !important;
}
body.light-theme #header,
html.pre-light body #header {
  background:
    radial-gradient(55% 45% at 18% 22%, rgba(var(--primary-rgb),0.10), transparent 60%),
    radial-gradient(50% 42% at 82% 28%, rgba(var(--accent-rgb),0.09), transparent 60%),
    var(--bg-color) !important;
}
.header-overlay { display: none; }
.header-content { max-width: 880px; }
.header-content h1 { letter-spacing: -0.02em; }
.header-content p { margin-bottom: 4px; }

/* Hero credibility chips */
.hero-chips {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 10px; margin: 24px 0 30px;
}
.hero-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 15px; border-radius: 999px;
  background: rgba(var(--primary-rgb), 0.08);
  border: 1px solid rgba(var(--primary-rgb), 0.28);
  color: var(--text-color); font-size: 0.84rem; font-weight: 600;
  backdrop-filter: blur(6px);
}

/* Hero CTA buttons */
.hero-cta { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 13px 26px; border-radius: 10px;
  font-weight: 700; font-size: 0.95rem; text-decoration: none;
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease, color .2s ease;
  cursor: pointer; border: 1px solid transparent;
}
.btn-primary {
  background: linear-gradient(135deg, var(--gradient-start), var(--gradient-end));
  color: #fff; box-shadow: 0 6px 20px rgba(var(--primary-rgb), 0.35);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(var(--primary-rgb), 0.45); }
.btn-secondary { background: transparent; color: var(--text-color); border-color: var(--border-color); }
.btn-secondary:hover { transform: translateY(-2px); border-color: var(--primary-color); color: var(--primary-color); }

/* Stats band (About) */
.stats-band {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 16px; margin-top: 0;
  flex: 1 1 300px; min-width: 260px;
}
.stat {
  background: var(--card-bg); border: 1px solid var(--border-color);
  border-radius: 14px; padding: 22px 16px; text-align: center;
  box-shadow: 0 2px 8px var(--shadow-color);
  transition: transform .25s ease, border-color .25s ease;
  min-width: 0; overflow-wrap: break-word;
}
.stat:hover { transform: translateY(-3px); border-color: rgba(var(--primary-rgb), 0.5); }
.stat-num {
  display: block; font-size: 1.7rem; font-weight: 800; line-height: 1.1;
  background: linear-gradient(135deg, var(--gradient-start), var(--gradient-end));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.stat-label { display: block; margin-top: 9px; font-size: 0.82rem; color: var(--text-secondary); line-height: 1.4; }
@media (max-width: 760px) { .stats-band { grid-template-columns: repeat(2, 1fr); } }

/* Featured flagship projects */
.flip-card.featured .flip-card-front,
.flip-card.featured .flip-card-back {
  border: 1.5px solid rgba(var(--accent-rgb), 0.75);
  box-shadow: 0 6px 24px rgba(var(--accent-rgb), 0.28);
}
.featured-badge {
  position: absolute; top: 10px; right: 10px; z-index: 3;
  background: rgba(0,0,0,0.32); color: #fff;
  font-size: 0.62rem; font-weight: 800; letter-spacing: 0.05em;
  padding: 4px 10px; border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.4); text-transform: uppercase;
}

/* ===================== Dual-profile emphasis ===================== */
.profile-highlight {
  margin-top: 18px;
  padding: 16px 20px;
  border-inline-start: 4px solid var(--primary-color);
  border-radius: 10px;
  background: rgba(var(--primary-rgb), 0.08);
  font-size: clamp(1rem, 1.4vw, 1.14rem);
  font-weight: 600;
  line-height: 1.6;
  color: var(--text-color);
}
.hero-chip-star {
  background: linear-gradient(135deg, var(--gradient-start, var(--primary-color)), var(--gradient-end, var(--primary-color)));
  color: #fff;
  border-color: transparent;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(var(--primary-rgb), 0.35);
}

/* ===================== Responsive polish & overflow safety ===================== */
html, body { overflow-x: hidden; }
img, svg, video, canvas, table { max-width: 100%; }
* { min-width: 0; }

/* Tablet / iPad range */
@media (max-width: 1024px) {
  .info-cards, .experience-grid, .skills-grid { gap: 18px; }
  .profile-content { gap: 24px; }
}

/* Phones */
@media (max-width: 600px) {
  .hero-cta { width: 100%; }
  .hero-cta .btn { flex: 1 1 100%; justify-content: center; }
  .profile-highlight { font-size: 1rem; padding: 14px 16px; }
  .stats-band { gap: 12px; }
  .stat { padding: 18px 10px; }
  .stat-num { font-size: 1.4rem; overflow-wrap: break-word; }
  .stat-label { font-size: 0.78rem; }
}

/* Small phones */
@media (max-width: 380px) {
  .hero-chip { font-size: 0.76rem; padding: 6px 11px; }
  .btn { padding: 12px 18px; font-size: 0.9rem; }
  .info-card, .skill-card { padding: 22px 18px; }
}

/* Hero: secondary tagline line */
.header-tagline {
  font-size: clamp(0.9rem, 2.2vw, 1.1rem);
  font-weight: 600;
  opacity: 0.92;
  margin-top: 6px;
}

/* Was an <h4> under an <h2>, which skipped a heading level; promoted to <h3>
   and pinned to its previous size so nothing shifts visually. */
.publication-card .pub-table-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 18px 0 10px;
  color: var(--text-color);
}

/* ---- Publication sample table: scrollable, rows open the full article ---- */
.pub-table-hint {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin: 0 0 10px;
}
.pub-table-scroll {
  max-height: 340px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border-color);
  border-radius: 10px;
}
.pub-table-scroll .sample-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--section-bg);
}
.pub-row {
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.pub-row:hover,
.pub-row:focus-visible {
  background: rgba(var(--primary-rgb), 0.12);
  outline: none;
}
.pub-row:focus-visible {
  box-shadow: inset 0 0 0 2px var(--primary-color);
}
.pub-row .pub-kw {
  font-weight: 600;
  color: var(--text-color);
  white-space: normal;
  min-width: 190px;
}

/* Reading dialog */
.pub-modal {
  position: fixed;
  inset: 0;
  z-index: 4000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}
.pub-modal.hidden { display: none; }
.pub-modal-box {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  box-shadow: 0 24px 60px var(--shadow-color);
  width: min(760px, 100%);
  max-height: min(80vh, 720px);
  display: flex;
  flex-direction: column;
  padding: 22px 24px 24px;
}
.pub-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 6px;
}
.pub-modal-head h3 {
  margin: 0;
  color: var(--primary-color);
  font-size: 1.15rem;
}
#pub-modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 6px;
  border-radius: 8px;
}
#pub-modal-close:hover,
#pub-modal-close:focus-visible {
  color: var(--text-color);
  background: rgba(var(--primary-rgb), 0.14);
}
.pub-modal-kw {
  margin: 0 0 14px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--accent-color);
  line-height: 1.5;
}
.pub-modal-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  line-height: 1.75;
  color: var(--text-secondary);
  white-space: pre-wrap;
  padding-right: 6px;
}
.pub-modal-body:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: -2px;
}
#pub-modal-close:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}
[dir="rtl"] .pub-modal-body,
[dir="rtl"] .pub-modal-kw { text-align: right; }

@media (max-width: 600px) {
  .pub-table-scroll { max-height: 300px; }
  .pub-modal-box { padding: 18px 16px 20px; max-height: 86vh; }
}

/* ---- Small-screen navbar ----
   The name must stay on one line without running into the burger, so the logo
   is allowed to shrink and the burger is pinned at its intrinsic size. */
.logo {
  min-width: 0;
  flex: 0 1 auto;
  overflow: hidden;
}
.logo a {
  white-space: nowrap;
}
.burger {
  flex: 0 0 auto;
}
.controls {
  flex: 0 0 auto;
}
@media (max-width: 480px) {
  .nav-container { width: 94%; gap: 10px; }
  .logo a { font-size: 1rem; }
  /* The floating chat button used to sit on top of the hero buttons. */
  .hero-cta { padding-bottom: 72px; }
}
@media (max-width: 380px) {
  .logo a { font-size: 0.9rem; }
  .nav-container { gap: 8px; }
  #chat-toggle { width: 48px; height: 48px; right: 14px; bottom: 14px; }
}
@media (max-width: 340px) {
  .logo a { font-size: 0.82rem; }
  .nav-container { width: 96%; gap: 6px; }
}

/* 10px uppercase was below comfortable reading size. */
.featured-badge { font-size: 0.68rem; }

/* Grades stay private; this signals the evidence exists without publishing it. */
.cert-note {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* On a phone the two-column sample table needed sideways scrolling to read.
   The preview column is redundant there — tapping a row opens the full
   article anyway — so below 620px only the keywords show, with a read cue. */
@media (max-width: 620px) {
  /* A hard min-width of 520px was forcing the sideways scroll. */
  .pub-table-scroll .sample-table {
    min-width: 0;
  }
  .pub-table-scroll .sample-table th:nth-child(2),
  .pub-table-scroll .sample-table td.preview {
    display: none;
  }
  .pub-table-scroll .sample-table th:first-child,
  .pub-row .pub-kw {
    width: 100%;
    min-width: 0;
  }
  .pub-row .pub-kw::after {
    content: " ↗";
    color: var(--primary-color);
    font-weight: 700;
  }
  .pub-table-scroll { max-height: 320px; }
}

/* Tells a recruiter at a glance which projects are coursework and which are
   personal work, so the production systems stand out by contrast. */
.card-kind {
  display: inline-block;
  margin-top: 14px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #fff;
}

.profile-refs {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-style: italic;
  margin: 14px 0 0;
}
