/* ===== Global polish ===== */
html { scroll-behavior: smooth; }

body { line-height: 1.65; }

/* Smoother link transitions */
a { transition: color 0.2s ease; }

/* ===== Fade-in on scroll ===== */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fade-in-section {
  animation: fadeInUp 0.6s ease both;
}

/* Staggered entrance for publication items */
.publications ol.bibliography li {
  opacity: 0;
  animation: fadeInUp 0.5s ease both;
}
.publications ol.bibliography li:nth-child(1)  { animation-delay: 0.05s; }
.publications ol.bibliography li:nth-child(2)  { animation-delay: 0.10s; }
.publications ol.bibliography li:nth-child(3)  { animation-delay: 0.15s; }
.publications ol.bibliography li:nth-child(4)  { animation-delay: 0.20s; }
.publications ol.bibliography li:nth-child(5)  { animation-delay: 0.25s; }
.publications ol.bibliography li:nth-child(6)  { animation-delay: 0.30s; }
.publications ol.bibliography li:nth-child(7)  { animation-delay: 0.35s; }
.publications ol.bibliography li:nth-child(8)  { animation-delay: 0.40s; }
.publications ol.bibliography li:nth-child(9)  { animation-delay: 0.45s; }
.publications ol.bibliography li:nth-child(10) { animation-delay: 0.50s; }
.publications ol.bibliography li:nth-child(11) { animation-delay: 0.55s; }
.publications ol.bibliography li:nth-child(12) { animation-delay: 0.60s; }
.publications ol.bibliography li:nth-child(13) { animation-delay: 0.65s; }

/* Staggered entrance for media cards */
.media-grid .media-card {
  opacity: 0;
  animation: fadeInUp 0.5s ease both;
}
.media-grid .media-card:nth-child(1) { animation-delay: 0.05s; }
.media-grid .media-card:nth-child(2) { animation-delay: 0.12s; }
.media-grid .media-card:nth-child(3) { animation-delay: 0.19s; }
.media-grid .media-card:nth-child(4) { animation-delay: 0.26s; }
.media-grid .media-card:nth-child(5) { animation-delay: 0.33s; }
.media-grid .media-card:nth-child(6) { animation-delay: 0.40s; }
.media-grid .media-card:nth-child(7) { animation-delay: 0.47s; }
.media-grid .media-card:nth-child(8) { animation-delay: 0.54s; }
.media-grid .media-card:nth-child(9) { animation-delay: 0.61s; }

/* ===== Section headings ===== */
section h2 {
  position: relative;
  padding-bottom: 8px;
  margin-top: 2.2rem;
  margin-bottom: 1.2rem;
}

section h2::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  width: 40px;
  height: 3px;
  background: var(--global-theme-color, #002D72);
  border-radius: 2px;
  transition: width 0.35s ease;
}

section h2:hover::after {
  width: 80px;
}

/* ===== News timeline ===== */
section > ul {
  list-style: none;
  padding-left: 0;
}

section > ul > li {
  position: relative;
  padding-left: 20px;
  padding-bottom: 6px;
  border-left: 2px solid #e0e0e0;
  margin-bottom: 2px;
  transition: border-color 0.2s ease;
}

section > ul > li:hover {
  border-left-color: var(--global-theme-color, #002D72);
}

section > ul > li::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e0e0e0;
  transition: background 0.2s ease;
}

section > ul > li:hover::before {
  background: var(--global-theme-color, #002D72);
}

@media (prefers-color-scheme: dark) {
  section > ul > li { border-left-color: #3a3b4a; }
  section > ul > li::before { background: #3a3b4a; }
  section > ul > li:hover { border-left-color: var(--global-theme-color); }
  section > ul > li:hover::before { background: var(--global-theme-color); }
}

/* ===== Media coverage cards ===== */
.media-card {
  text-decoration: none;
  color: inherit;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
  display: flex;
  flex-direction: column;
}

.media-card:hover {
  transform: translateY(-6px) scale(1.01);
  box-shadow: 0 12px 32px rgba(0,0,0,0.14);
  color: inherit;
}

.media-card img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  transition: transform 0.45s cubic-bezier(0.25, 0.46, 0.45, 0.94), filter 0.3s ease;
}

.media-card:hover img {
  transform: scale(1.06);
  filter: brightness(1.04);
}

.media-card .card-body {
  padding: 14px 16px;
  flex: 1;
}

.media-card .card-date {
  font-size: 0.78rem;
  color: #888;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.media-card .card-source {
  font-weight: 700;
  font-size: 1rem;
  margin: 4px 0 6px;
  transition: color 0.2s ease;
}

.media-card:hover .card-source {
  color: var(--global-theme-color, #002D72);
}

.media-card .card-title {
  font-size: 0.88rem;
  color: #555;
  line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
  .media-card { border-color: #3a3b4a; background: #282936; box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
  .media-card:hover { box-shadow: 0 12px 36px rgba(0,0,0,0.4); }
  .media-card .card-date { color: #8899aa; }
  .media-card .card-source { color: #e0e0e0; }
  .media-card:hover .card-source { color: var(--global-theme-color); }
  .media-card .card-title { color: #aab; }
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 22px;
  margin-top: 1rem;
}

/* ===== Skills pills ===== */
.skills-section h4 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--global-theme-color, #002D72);
  margin-bottom: 8px;
  margin-top: 0;
}

.skills-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.skill-pill {
  display: inline-block;
  padding: 5px 16px;
  font-size: 0.85rem;
  border-radius: 20px;
  background: #f0f4f8;
  color: #333;
  border: 1px solid #d8dfe6;
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  cursor: default;
}

.skill-pill:hover {
  background: var(--global-theme-color, #002D72);
  color: #fff;
  border-color: var(--global-theme-color, #002D72);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 45, 114, 0.2);
}

@media (prefers-color-scheme: dark) {
  .skill-pill { background: #2a2b3a; color: #ccd; border-color: #3a3b4a; }
  .skill-pill:hover { background: var(--global-theme-color); color: #fff; border-color: var(--global-theme-color); box-shadow: 0 4px 12px rgba(36, 150, 203, 0.25); }
}

/* ===== Contact form ===== */
.contact-form {
  margin-top: 20px;
}

.contact-form input,
.contact-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d0d5dd;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fafbfc;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  box-sizing: border-box;
}

.contact-form input:focus,
.contact-form textarea:focus {
  outline: none;
  border-color: var(--global-theme-color, #002D72);
  box-shadow: 0 0 0 3px rgba(0, 45, 114, 0.1);
}

.contact-form textarea {
  height: 100px;
  resize: vertical;
}

.contact-form .btn-submit {
  width: 100%;
  padding: 11px 20px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: var(--global-theme-color, #002D72);
  color: #fff;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  overflow: hidden;
}

.contact-form .btn-submit::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255,255,255,0.15);
  border-radius: 50%;
  transition: width 0.4s ease, height 0.4s ease;
  transform: translate(-50%, -50%);
}

.contact-form .btn-submit:hover::after {
  width: 300px;
  height: 300px;
}

.contact-form .btn-submit:hover {
  background: #001d4f;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 45, 114, 0.3);
}

.contact-form .btn-submit:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 2px 8px rgba(0, 45, 114, 0.2);
}

@media (prefers-color-scheme: dark) {
  .contact-form input,
  .contact-form textarea { background: #282936; border-color: #3a3b4a; color: #dadbdf; }
  .contact-form input:focus,
  .contact-form textarea:focus { border-color: var(--global-theme-color); box-shadow: 0 0 0 3px rgba(36, 150, 203, 0.15); }
  .contact-form .btn-submit { background: rgb(36, 150, 203); }
  .contact-form .btn-submit:hover { background: rgb(28, 130, 180); box-shadow: 0 4px 12px rgba(36, 150, 203, 0.3); }
}

/* ===== Honors & highlights ===== */
section > ul > li strong {
  color: inherit;
}

/* ===== Research interests clean list ===== */

/* ===== Affiliations polish ===== */
section ol[style] li div[style*="display: flex"] {
  transition: background 0.2s ease;
  padding: 8px;
  border-radius: 8px;
}

/* ===== Responsive: Tablet (961px and below) ===== */
@media screen and (max-width: 960px) {
  /* Header becomes horizontal top section */
  header {
    text-align: center;
    padding: 20px 16px !important;
  }

  section {
    padding: 20px 16px !important;
  }

  /* Center the avatar */
  .image.avatar {
    display: block;
    margin: 0 auto 1rem;
  }

  /* Social icons centered */
  .social-icons {
    justify-content: center;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
  }

  /* Media grid 2 columns on tablet */
  .media-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }

  /* Publication images scale better */
  .publications ol.bibliography li .teaser {
    width: 100%;
    max-width: 270px;
    height: auto;
    min-height: 80px;
  }

  /* Pub row flex wrap for medium screens */
  .pub-row {
    padding: 10px 8px;
    gap: 12px;
  }

  /* Affiliation rows */
  section ol[style] li div[style*="display: flex"] {
    gap: 10px;
  }
}

/* ===== Responsive: Mobile (480px and below) ===== */
@media screen and (max-width: 480px) {
  body {
    font-size: 15px;
  }

  /* Tighter section spacing */
  section h2 {
    font-size: 1.35rem;
    margin-top: 1.6rem;
    margin-bottom: 0.9rem;
  }

  /* Media grid single column */
  .media-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .media-card img {
    height: 140px;
  }

  .media-card .card-body {
    padding: 12px 14px;
  }

  .media-card .card-source {
    font-size: 0.92rem;
  }

  .media-card .card-title {
    font-size: 0.82rem;
  }

  /* Publication row stacks vertically */
  .pub-row {
    flex-direction: column !important;
    display: flex !important;
    align-items: flex-start !important;
    padding: 10px 6px;
    gap: 8px;
  }

  /* Publication image full width on mobile */
  .pub-row .col-sm-3 {
    width: 100% !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    margin-bottom: 4px;
  }

  .publications ol.bibliography li .teaser {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    margin-left: 0 !important;
    border-radius: 8px;
  }

  .publications ol.bibliography li .abbr {
    height: auto !important;
    margin-bottom: 0 !important;
  }

  .publications ol.bibliography li .abbr abbr {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    display: inline-block;
    margin-bottom: 6px;
  }

  .pub-row .col-sm-9 {
    width: 100% !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  .pub-row .title {
    font-size: 0.95rem;
    line-height: 1.35;
  }

  .pub-row .author {
    font-size: 0.85rem;
  }

  .pub-row .periodical {
    font-size: 0.82rem;
  }

  .pub-row .links {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
  }

  .pub-row .links a.btn {
    font-size: 11px !important;
    padding: 4px 10px !important;
  }

  /* Skills */
  .skills-group {
    gap: 6px;
  }

  .skill-pill {
    font-size: 0.8rem;
    padding: 4px 12px;
  }

  .skills-section h4 {
    font-size: 0.8rem;
    margin-bottom: 6px;
  }

  /* News timeline tighter */
  section > ul > li {
    padding-left: 16px;
    padding-bottom: 5px;
    font-size: 0.9rem;
    line-height: 1.5;
  }

  section > ul > li::before {
    width: 6px;
    height: 6px;
    left: -4px;
    top: 7px;
  }

  /* Disable hover translateX on mobile (touch) */
  section > ul > li:hover {
    transform: none;
  }

  /* Affiliation rows stack on small screens */
  section ol[style] li div[style*="display: flex"] {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 6px;
  }

  section ol[style] li div[style*="display: flex"] > div:first-child {
    flex: 0 0 auto !important;
    width: 60px !important;
    margin-right: 0 !important;
  }

  /* Contact form */
  .contact-form input,
  .contact-form textarea {
    font-size: 16px; /* prevents iOS zoom on focus */
    padding: 12px;
  }

  .contact-form textarea {
    height: 80px;
  }

  .contact-form .btn-submit {
    padding: 12px 20px;
    font-size: 16px;
  }

  /* Magic button smaller on mobile */
  a[href="/ubuntu/"] {
    padding: 8px 12px !important;
    font-size: 0.85rem !important;
    bottom: 14px !important;
    right: 14px !important;
  }
}

/* ===== Responsive: Small mobile (360px and below) ===== */
@media screen and (max-width: 360px) {
  body {
    font-size: 14px;
    padding: 10px !important;
  }

  section h2 {
    font-size: 1.2rem;
  }

  .media-card img {
    height: 120px;
  }

  .skill-pill {
    font-size: 0.75rem;
    padding: 3px 10px;
  }

  .pub-row .title {
    font-size: 0.88rem;
  }
}

/* ===== Touch device adjustments ===== */
@media (hover: none) {
  /* Remove hover transforms that feel janky on touch */
  .media-card:hover {
    transform: none;
  }

  .skill-pill:hover {
    transform: none;
    background: #f0f4f8;
    color: #333;
    border-color: #d8dfe6;
    box-shadow: none;
  }

  .pub-row:hover {
    background: transparent;
    box-shadow: none;
  }

  .pub-row:hover .teaser {
    transform: none;
  }

  section > ul > li:hover {
    transform: none;
    background: transparent;
  }

  /* Keep active states for tap feedback */
  .media-card:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }

  .skill-pill:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
  }

  .contact-form .btn-submit:active {
    transform: scale(0.97);
  }
}

@media (hover: none) and (prefers-color-scheme: dark) {
  .skill-pill:hover { background: #2a2b3a; color: #ccd; border-color: #3a3b4a; box-shadow: none; }
}

/* ===== Publication row hover ===== */
.pub-row {
  padding: 12px 10px;
  border-radius: 10px;
  transition: background 0.25s ease, box-shadow 0.25s ease;
}

.pub-row:hover {
  background: rgba(0, 45, 114, 0.03);
  box-shadow: 0 2px 16px rgba(0,0,0,0.06);
}

.pub-row .teaser {
  transition: transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94), box-shadow 0.3s ease !important;
}

.pub-row:hover .teaser {
  transform: scale(1.03);
  box-shadow: 4px 4px 12px rgba(0,0,0,0.15) !important;
}

.pub-row .links a.btn {
  transition: all 0.2s ease !important;
  border-radius: 4px !important;
}

.pub-row .links a.btn:hover {
  background: var(--global-theme-color, #002D72) !important;
  color: #fff !important;
  border-color: var(--global-theme-color, #002D72) !important;
  transform: translateY(-1px);
}

@media (prefers-color-scheme: dark) {
  .pub-row:hover { background: rgba(36, 150, 203, 0.06); box-shadow: 0 2px 16px rgba(0,0,0,0.15); }
  .pub-row .links a.btn:hover { background: var(--global-theme-color) !important; color: #fff !important; border-color: var(--global-theme-color) !important; }
}

/* ===== Avatar hover ===== */
.image.avatar img {
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}

.image.avatar:hover img {
  transform: scale(1.05);
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
}

/* ===== Social icons enhanced ===== */
.social-icons a {
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
}

/* ===== Badge pulse for "Under Review" ===== */
.publications ol.bibliography li .abbr abbr {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.publications ol.bibliography li:hover .abbr abbr {
  transform: scale(1.05);
  box-shadow: 0 3px 10px rgba(0, 45, 114, 0.25);
}

/* ===== Contact form input focus glow ===== */
.contact-form input:focus,
.contact-form textarea:focus {
  transform: translateY(-1px);
}

/* ===== News timeline enhanced ===== */
section > ul > li {
  transition: border-color 0.2s ease, transform 0.2s ease, background 0.2s ease;
  border-radius: 4px;
}

section > ul > li:hover {
  transform: translateX(4px);
  background: rgba(0, 45, 114, 0.02);
}

@media (prefers-color-scheme: dark) {
  section > ul > li:hover { background: rgba(36, 150, 203, 0.04); }
}

/* ===== Magic button polish ===== */
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 6px 20px rgba(233, 84, 32, 0.25); }
  50%      { box-shadow: 0 6px 28px rgba(233, 84, 32, 0.45); }
}

a[href="/ubuntu/"] {
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease !important;
  animation: pulse-glow 2.5s ease-in-out infinite !important;
}

a[href="/ubuntu/"]:hover {
  transform: scale(1.1) !important;
  box-shadow: 0 8px 28px rgba(233, 84, 32, 0.4) !important;
  animation: none !important;
}

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
