/* ==========================================================================
   HALL VIII · IIT KANPUR  -  responsive.css  (loaded LAST on every page)

   One place for phone / tablet / desktop behaviour, so it can be tuned without touching
   the design files. It only overrides layout, sizing and touch behaviour; colours and fonts
   still come from the tokens in styles.css.

   Breakpoints
     >= 1440px   large desktop: wider content column, slightly larger text
     <= 1040px   tablet / small laptop: nav collapses into a menu button
     <=  860px   tablet portrait: single-column layouts
     <=  640px   phone: stacked facilities table, full-width buttons
     <=  400px   small phone: tightest spacing
   Also: (hover: none) = touch devices, (pointer: coarse) = finger-sized targets,
         landscape phones (short height).

   01. Foundations
   02. Header, menu button & navigation
   03. Hero
   04. Sections & cards
   05. Research-journey timeline
   06. Facilities table
   07. Slideshow, dialogs & footer
   08. Gallery, rooms & HEC archive pages
   09. Touch devices
   10. Large screens
   11. Short landscape screens
   ========================================================================== */

/* 01. FOUNDATIONS ---------------------------------------------------------- */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  overflow-x: clip; /* nothing may ever make the page scroll sideways */
}
img,
svg,
canvas,
video {
  max-width: 100%;
}
/* Keep content out of the notch / rounded corners when a phone is turned sideways */
.bar,
.wrap,
main,
.fg {
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
}
/* The global `nav` rule (right-aligned, sideways-scrolling) is meant for the header only;
   breadcrumbs are also <nav> and should simply wrap */
.g-crumbs {
  margin-left: 0;
  overflow: visible;
}
.g-crumbs a {
  padding: 0; /* undo the header-nav link padding/background that also matches these <nav> links */
  font: inherit;
  background: none;
  border-radius: 0;
}
.fg a,
.card p,
.log strong {
  overflow-wrap: anywhere; /* long e-mail addresses never push the layout wide */
}
/* Auto-fit grids that can never overflow a very narrow screen */
.people {
  grid-template-columns: repeat(auto-fill, minmax(min(250px, 100%), 1fr));
}
.links {
  grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr));
}
.pillars {
  grid-template-columns: repeat(auto-fit, minmax(min(230px, 100%), 1fr));
}
.stats {
  grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));
}
.g-albums {
  grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr));
}
.g-grid {
  grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr));
}
section {
  padding-top: clamp(56px, 9vw, 88px);
}
footer {
  margin-top: clamp(56px, 8vw, 96px);
}
/* iOS zooms the page when a text field under 16px is focused */
.srch {
  font-size: 16px;
}
.top {
  right: max(16px, env(safe-area-inset-right, 0px));
}

/* 02. HEADER, MENU BUTTON & NAVIGATION ------------------------------------- */
.mb {
  display: none;
  flex: none;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--ink);
  font: 20px/1 var(--m);
  cursor: pointer;
}
.mb:hover {
  border-color: var(--acc);
}

@media (max-width: 1040px) {
  .bar {
    gap: 10px;
  }
  .brand {
    margin-right: auto;
  }
  /* Without JS the nav stays a scrolling bar; with JS it becomes a dropdown */
  header nav {
    flex: 1;
    min-width: 0;
  }
  .nav-js .mb {
    display: grid;
  }
  .nav-js header nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex: none;
    flex-direction: column;
    gap: 2px;
    margin: 0;
    padding: 8px max(12px, env(safe-area-inset-right, 0px)) 16px
      max(12px, env(safe-area-inset-left, 0px));
    max-height: calc(100dvh - 64px - env(safe-area-inset-top, 0px));
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 18px 30px -18px rgba(4, 16, 31, 0.45);
  }
  .nav-js header.open nav {
    display: flex;
  }
  .nav-js header nav a {
    padding: 14px 12px;
    font-size: 15px;
    border-radius: 6px;
  }
}
@media (max-width: 860px) {
  .brand .bt > span {
    display: none;
  }
}
@media (max-width: 520px) {
  .brand-iitk img,
  .brand-logo {
    height: 34px;
  }
  .brand-iitk {
    padding-right: 10px;
  }
}
@media (max-width: 400px) {
  .brand .bt {
    display: none; /* very narrow phones: logos only, keeps the menu and theme buttons on screen */
  }
  .bar {
    padding-left: max(14px, env(safe-area-inset-left, 0px));
    padding-right: max(14px, env(safe-area-inset-right, 0px));
  }
  .brand {
    font-size: 18px;
  }
}

/* 03. HERO ----------------------------------------------------------------- */
.hero {
  /* svh = the visible height with the phone's URL bar showing; the old vh rule stays as fallback */
  min-height: min(calc(100svh - 64px - env(safe-area-inset-top, 0px)), 780px);
}
@media (max-width: 860px) {
  .hero {
    min-height: 0;
    padding: 28px 0 24px;
    gap: 20px;
  }
  .hero h1 {
    font-size: clamp(34px, 11vw, 56px);
    margin: 10px 0 16px;
  }
  .hero p {
    font-size: 16px;
  }
  .hero .draw {
    max-width: min(460px, 100%);
    margin: 0 auto;
    animation: none; /* no bobbing: saves battery and avoids sub-pixel jitter on phones */
  }
  .stat-line {
    margin-top: 22px;
    gap: 8px 16px;
  }
  .aur i {
    filter: blur(60px); /* heavy blur is costly on mobile GPUs */
  }
}
@media (max-width: 480px) {
  .btns {
    gap: 10px;
  }
  .btns .btn {
    flex: 1 1 100%;
    text-align: center;
  }
  .hero h1 {
    letter-spacing: -0.03em;
  }
}

/* 04. SECTIONS & CARDS ----------------------------------------------------- */
@media (max-width: 860px) {
  .sub {
    margin-bottom: 24px;
  }
  .about .panel {
    padding: 20px;
  }
  .about blockquote {
    font-size: 17px;
  }
  .stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  .stats b {
    font-size: clamp(28px, 8vw, 40px);
  }
  .fg {
    gap: 24px;
    padding-top: 32px;
    padding-bottom: 32px;
  }
}
@media (min-width: 561px) and (max-width: 860px) {
  .fg {
    grid-template-columns: 1fr 1fr; /* footer: two columns on tablets, first block spans both */
  }
  .fg > :first-child {
    grid-column: 1 / -1;
  }
}
@media (max-width: 560px) {
  .log li {
    padding: 14px 16px;
    gap: 2px 12px;
  }
  summary {
    padding: 14px 16px;
  }
  details p {
    padding: 0 16px 14px;
  }
  .card.lead {
    grid-template-columns: 1fr;
  }
  .card.lead .av {
    grid-row: auto;
    margin-bottom: 8px;
  }
  .fac-intro {
    padding: 20px;
  }
  .cp {
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }
}
@media (max-width: 400px) {
  .stats .panel {
    padding: 14px;
  }
  .fac-tiles {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }
}

/* 05. RESEARCH-JOURNEY TIMELINE -------------------------------------------- */
/* Tablet: shrink the 820px minimum so it scrolls less; phone: becomes a vertical timeline */
@media (max-width: 1040px) {
  .pi {
    min-width: 720px;
  }
}
@media (max-width: 760px) {
  .path {
    padding: 22px 18px;
    overflow-x: visible;
  }
  .pi {
    min-width: 0;
  }
  .pl {
    display: none; /* the horizontal progress line is replaced by the vertical rail below */
  }
  .path ol {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .path ol::before {
    content: "";
    position: absolute;
    left: 6px;
    top: 8px;
    bottom: 24px;
    width: 3px;
    background: var(--line);
  }
  .path li {
    padding: 0 0 22px 36px;
    min-height: 44px;
  }
  .path li:last-child {
    padding-bottom: 0;
  }
  .path li::before {
    top: 3px;
    z-index: 1;
  }
}

/* 06. FACILITIES TABLE ----------------------------------------------------- */
/* Phone: each row becomes a small card (name + status on top, details below) instead of scrolling sideways */
@media (max-width: 640px) {
  #facilities .scroll table,
  #facilities .scroll tbody {
    display: block;
  }
  #facilities .scroll thead {
    position: absolute; /* hidden visually, still read by screen readers */
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  #facilities .scroll tr {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
  }
  #facilities .scroll tr:last-child {
    border-bottom: 0;
  }
  #facilities .scroll td {
    padding: 0;
    border: 0;
  }
  #facilities .scroll td:first-child {
    grid-column: 1;
    font-size: 16px;
    white-space: normal;
  }
  #facilities .scroll td:nth-child(2) {
    grid-column: 1 / -1;
    grid-row: 2;
    color: var(--mute);
    font-size: 14px;
  }
  #facilities .scroll td:last-child {
    grid-column: 2;
    grid-row: 1;
    align-self: center;
  }
  /* Other tables (e.g. room timings) keep a tighter sideways-scroll layout */
  th,
  td {
    padding: 12px 14px;
  }
}

/* 07. SLIDESHOW, DIALOGS & FOOTER ------------------------------------------ */
@media (max-width: 700px) {
  .show {
    aspect-ratio: 4 / 3;
    min-height: 0;
  }
  .cap {
    padding: 36px 14px 12px;
    font-size: 14px;
    flex-wrap: wrap;
    gap: 2px 10px;
  }
  .ar {
    width: 40px;
    height: 40px;
    font-size: 22px;
  }
  .pv {
    left: 8px;
  }
  .nx {
    right: 8px;
  }
  .srow > div:last-child {
    width: 100%;
  }
  .srow .btn {
    flex: 1 1 0;
    text-align: center;
  }
}
/* Bigger finger target for the pager dots without changing how they look */
.dots button {
  position: relative;
}
.dots button::before {
  content: "";
  position: absolute;
  inset: -14px -4px;
}
@media (max-width: 600px) {
  .nd {
    width: calc(100vw - 24px);
    max-height: min(85dvh, 640px);
  }
  .nd-head,
  .nd-foot {
    padding-left: 16px;
    padding-right: 16px;
  }
  .nd-foot {
    flex-wrap: wrap;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  .soon-act .btn {
    flex: 1 1 100%;
    text-align: center;
  }
}

/* 08. GALLERY, ROOMS & HEC ARCHIVE PAGES ----------------------------------- */
@media (max-width: 700px) {
  .g-stage {
    aspect-ratio: 4 / 3;
    max-height: 62dvh;
  }
  .g-cap {
    padding: 28px 14px 10px;
    flex-wrap: wrap;
    gap: 2px 10px;
  }
  .g-cap span {
    font-size: 14px;
  }
  .g-thumbs button {
    width: 72px;
  }
  .g-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .g-seg {
    display: flex;
  }
  .g-seg button {
    flex: 1;
  }
  .g-ctrl .btn,
  .g-ctrl button {
    flex: 1 1 auto;
  }
  .g-albums {
    gap: 14px;
    margin-bottom: 48px;
  }
  .g-grid {
    gap: 8px;
  }
}
@media (max-width: 760px) {
  .r-panel {
    scroll-margin-top: calc(72px + env(safe-area-inset-top, 0px));
  }
  .r-grid {
    gap: 20px;
  }
}
@media (max-width: 480px) {
  .r-cards {
    grid-template-columns: repeat(2, 1fr);
  }
  .r-panel {
    padding: 14px;
  }
  .r-glance div {
    flex: 1 1 calc(50% - 10px);
  }
}
.r-panel {
  scroll-margin-top: calc(80px + env(safe-area-inset-top, 0px));
}
.g-show:fullscreen {
  padding: max(16px, env(safe-area-inset-top, 0px))
    max(16px, env(safe-area-inset-right, 0px))
    max(16px, env(safe-area-inset-bottom, 0px))
    max(16px, env(safe-area-inset-left, 0px));
}

/* Member cards (photo frame): on phones the portrait sits beside the text instead of filling the card width */
@media (max-width: 560px) {
  .card.has-ph {
    display: grid;
    grid-template-columns: 92px 1fr;
    column-gap: 14px;
    align-content: start;
    align-items: start;
  }
  .card.has-ph .ph,
  .card.lead.has-ph .ph {
    grid-column: 1;
    grid-row: 1 / span 4;
    width: 92px;
    margin: 0;
    font-size: 28px;
  }
  .card.has-ph > :not(.ph) {
    grid-column: 2;
    min-width: 0;
  }
  .card.has-ph h3 {
    font-size: 17px;
  }
}

/* 09. TOUCH DEVICES -------------------------------------------------------- */
/* Fingers cannot hover: stop hover effects from sticking after a tap, and drop pointer-only decoration */
@media (hover: none) {
  .spot,
  .xh {
    display: none;
  }
  .hero {
    cursor: auto;
  }
  .card:not(.lead):hover,
  .links a:hover {
    transform: none;
    border-color: var(--line);
    background: var(--panel);
  }
  .stats .panel:hover,
  .pillars .panel:hover,
  .g-album:hover {
    transform: none;
    box-shadow: var(--sh);
  }
  .btn:hover {
    transform: translate(var(--tx, 0px), var(--ty, 0px));
    box-shadow: none;
  }
  .log li:hover {
    padding-left: 20px;
    background: none;
  }
  .g-album:hover .g-cover img,
  .g-tile:hover img {
    transform: none;
  }
  /* Photo captions are hover-only on desktop; on touch they must be visible */
  .g-tile::after {
    opacity: 1;
  }
}
@media (pointer: coarse) {
  .tt,
  .mb {
    width: 44px;
    height: 44px;
  }
  .btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .sel button,
  .g-seg button,
  .tk-btn {
    min-height: 44px;
  }
  .srch {
    min-height: 44px;
  }
  .nd-x {
    width: 44px;
    height: 44px;
  }
  .g-ar {
    width: 48px;
    height: 48px;
    margin-top: -24px;
  }
  summary {
    min-height: 48px;
    align-items: center;
  }
  .fac-room,
  .r-card {
    min-height: 44px;
  }
}

/* 10. LARGE SCREENS -------------------------------------------------------- */
@media (min-width: 1440px) {
  body {
    font-size: 17px;
  }
  .bar,
  .wrap,
  main,
  .fg {
    max-width: 1320px;
  }
  .hero {
    min-height: min(calc(100svh - 64px), 820px);
  }
}
@media (min-width: 1920px) {
  body {
    font-size: 18px;
  }
  .bar,
  .wrap,
  main,
  .fg {
    max-width: 1480px;
  }
  .people {
    grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr));
  }
}

/* 11. SHORT LANDSCAPE SCREENS (phones turned sideways) --------------------- */
@media (max-height: 500px) and (orientation: landscape) {
  html {
    scroll-padding-top: calc(56px + env(safe-area-inset-top, 0px));
  }
  .bar {
    height: 56px;
  }
  .hero {
    min-height: 0;
    padding: 20px 0;
  }
  .nav-js header nav {
    max-height: calc(100dvh - 56px - env(safe-area-inset-top, 0px));
  }
  .g-stage {
    max-height: 80dvh;
  }
  section {
    padding-top: 48px;
  }
}

@media print {
  .mb {
    display: none !important;
  }
}
