/* static/css/layout.css */

html, body{
  width:100%;
  overflow-x:hidden;
}

html {
  scroll-behavior: smooth;
}

* { box-sizing: border-box; }

a { color: inherit; text-decoration: none; }

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px 1fr;
  min-width: 0;
}

/* prevent grid children from forcing horizontal overflow */
.sidebar,
.sidebar-card,
.main,
.page,
.now-playing{
  min-width: 0;
}

/* ─────────────────────────
   Theme toggle
───────────────────────── */

.theme-toggle {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: 36px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  border-radius: 0;
  color: var(--text);
  cursor: pointer;
}

.theme-toggle-track {
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: var(--toggle-track);
  border: 1px solid var(--line);
  position: relative;
}

.theme-toggle-thumb {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--toggle-thumb);
  color: var(--toggle-icon);
  position: absolute;
  top: 50%;
  left: 3px;
  transform: translateY(-50%);
  transition: left 180ms ease, background-color 180ms ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* icons inside the toggle thumb */
.tt-icon {
  position: absolute;
  font-size: 13px;
  line-height: 1;
  transition: opacity 160ms ease, transform 160ms ease;
}

/* light mode default */
.tt-sun {
  opacity: 1;
  transform: scale(1);
}

.tt-moon {
  opacity: 0;
  transform: scale(0.6);
}

html[data-theme="dark"] .theme-toggle-thumb {
  left: 23px;
}

html[data-theme="dark"] .tt-sun {
  opacity: 0;
  transform: scale(0.6);
}

html[data-theme="dark"] .tt-moon {
  opacity: 1;
  transform: scale(1);
}

.theme-toggle:hover .theme-toggle-track {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}

.theme-toggle-label {
  font-size: 14px;
  color: var(--muted);
}

@media (max-width: 700px) {
  .theme-toggle-label { display: none; }
}

/* ─────────────────────────
   Sidebar
───────────────────────── */

.sidebar {
  padding: 28px 22px;
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
}

.sidebar-card {
  /* match the main site background so the profile box reads as one surface */
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 20px 18px;
}

/* Avatar */
.avatar-wrap {
  display: flex;
  width: fit-content;
  margin: 0 auto;
  padding: 10px;
  border: 1px solid var(--accent);
  border-radius: 26px;
  /* match the main site background so the profile box reads as one surface */
  background: var(--bg);
  box-shadow: var(--shadow);
}

.avatar {
  width: 190px;
  height: 190px;
  object-fit: cover;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--avatar-fallback);
}

/* Name */
.name {
  margin-top: 18px;
  text-align: center;
  font-family: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  font-size: 31px;
  font-weight: 600;
}

/* Tagline */
.tagline {
  margin-top: 4px;
  margin-bottom: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

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

.social .icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  overflow: hidden;
  transition: transform 120ms ease, background 120ms ease;
}

.social .icon img {
  width: 18px;
  height: 18px;
  object-fit: contain;
}

.social .icon:hover {
  background: var(--panel-2);
  transform: translateY(-1px);
}

/* ─────────────────────────
   Navigation
───────────────────────── */

.nav {
  margin-top: 22px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-link {
  padding: 10px 12px;
  border-radius: 12px;
  border-left: 3px solid transparent;
  color: var(--muted);
}

.nav-link.active {
  color: var(--accent);
}

.nav-arrow {
  display: inline-block;
  margin-left: 4px;
  opacity: 0;
  transform: translate(-4px, 2px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.nav-link-external:hover .nav-arrow {
  opacity: 1;
  transform: translate(0, 0);
}

/* ─────────────────────────
   Main content
───────────────────────── */

.main {
  padding: 56px 28px;
}

.page {
  max-width: 980px;
  margin: 0 auto;
}

/* /projects, the project explorer and the file viewer all run wide */
body.is-projects .page {
  max-width: 1440px;
}

/* ─────────────────────────
   Now playing
───────────────────────── */

.now-playing{
  display:flex;
  flex-direction:column;
  gap:8px;
  min-width: 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.np-row{
  display:flex;
  align-items:center;
  gap:12px;
  width:100%;
  min-width:0;
}

.np-info{
  display:flex;
  flex-direction:column;
  gap:2px;
  min-width:0;
  flex:1 1 auto;
}

.np-label{
  display:flex;
  align-items:center;
  gap:6px;
  font-size:10px;
  letter-spacing:.08em;
  text-transform:uppercase;
  color:var(--muted);
}

.np-label-gif{
  width:13px;
  height:13px;
  object-fit:contain;
  flex-shrink: 0;
}

.np-marquee{
  position:relative;
  flex:1 1 auto;
  min-width:0;
  max-width:100%;
  height:40px;
}

.np-swap{
  position:absolute;
  inset:0;
  display:flex;
  align-items:center;
  transition:opacity 260ms ease, transform 260ms ease;
}

.np-swap-title{
  overflow:hidden;
  opacity:1;
  transform:translateY(0);
}

.np-swap-progress{
  flex-direction:column;
  align-items:stretch;
  justify-content:center;
  gap:5px;
  opacity:0;
  transform:translateY(6px);
  pointer-events:none;
}

.np-marquee.is-playing .np-swap-title{
  opacity:0;
  transform:translateY(-6px);
}

.np-marquee.is-playing .np-swap-progress{
  opacity:1;
  transform:translateY(0);
  pointer-events:auto;
}

.np-track{
  display:flex;
  align-items:center;
  width:max-content;
  animation:np-marquee 14s linear infinite;
  gap:8px;
}

.np-marquee:hover .np-track,
.np-marquee.is-playing .np-track{
  animation-play-state:paused;
}

.np-text{
  font-size:15px;
  font-weight:600;
  white-space:nowrap;
}

.np-separator{
  width:20px;
  height:20px;
  object-fit:contain;
  margin:0;
  flex-shrink:0;
  display:block;
}

@keyframes np-marquee{
  from{ transform:translateX(0); }
  to{ transform:translateX(-50%); }
}

.np-seek{
  -webkit-appearance:none;
  appearance:none;
  width:100%;
  height:5px;
  margin:0;
  border-radius:999px;
  background:linear-gradient(to right, var(--accent) var(--np-pct, 0%), var(--line) var(--np-pct, 0%));
  cursor:pointer;
  outline:none;
}

.np-seek::-webkit-slider-thumb{
  -webkit-appearance:none;
  width:11px;
  height:11px;
  border-radius:50%;
  background:var(--accent);
  border:2px solid var(--bg);
  box-shadow:0 0 0 1px var(--line);
  cursor:pointer;
}

.np-seek::-moz-range-track{
  height:5px;
  border-radius:999px;
  background:var(--line);
}

.np-seek::-moz-range-progress{
  height:5px;
  border-radius:999px;
  background:var(--accent);
}

.np-seek::-moz-range-thumb{
  width:11px;
  height:11px;
  border-radius:50%;
  background:var(--accent);
  border:2px solid var(--bg);
  box-shadow:0 0 0 1px var(--line);
  cursor:pointer;
}

.np-time{
  font-size:11.5px;
  line-height:1;
  color:var(--muted);
  text-align:left;
  white-space:nowrap;
}

.np-play{
  display:flex;
  align-items:center;
  justify-content:center;
  flex-shrink:0;
  width:36px;
  height:36px;
  border:1.5px solid var(--accent);
  border-radius:50%;
  background:transparent;
  color:var(--accent);
  cursor:pointer;
  padding:0;
}

.np-play:hover{
  background:var(--accent-tint);
}

.np-icon{
  width:14px;
  height:14px;
}

.np-icon-pause{
  display:none;
}

.np-play.is-playing .np-icon-play{
  display:none;
}

.np-play.is-playing .np-icon-pause{
  display:block;
}

/* pinned to the bottom-left of the sidebar: .sidebar is a flex column on
   desktop, so margin-top:auto pushes this past the nav list */
.visitor-count{
  margin-top:auto;
  padding-top:12px;
  display:flex;
  align-items:center;
  gap:5px;
  font-size:11px;
  line-height:1;
  color:var(--muted);
}

/* desktop: pull into the sidebar's padding so it sits in the corner
   (10px from the left edge, 10px from the bottom) */
@media (min-width: 981px){
  .visitor-count{
    margin-left:-12px;
    margin-bottom:-18px;
  }
}

/* eye.svg has a hardcoded navy fill, so it's used as a mask and painted
   with the text colour — keeps it legible in both themes */
.vc-eye{
  width:13px;
  height:13px;
  flex-shrink:0;
  background-color:currentColor;
  -webkit-mask:url("../images/eye.svg") center / contain no-repeat;
  mask:url("../images/eye.svg") center / contain no-repeat;
}

/* home-page copy (main.html, under "Things I know"): mobile only, where
   it replaces the sidebar one */
.visitor-count-home{
  display:none;
}

@media (max-width: 980px){
  .sidebar .visitor-count{
    display:none;
  }

  .visitor-count-home{
    display:flex;
    justify-content:flex-end;
    padding:10px 6px 0 0;
  }
}

/* ─────────────────────────
   Bottom tab bar (mobile)
───────────────────────── */

.bottom-nav {
  display: none;
}

.bn-sheet-backdrop,
.bn-sheet {
  display: none;
}

@media (max-width: 980px) {
  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 900;
    background: var(--bg);
    border-top: 1px solid var(--line);
    padding: 8px 4px max(8px, env(safe-area-inset-bottom));
    transition: transform 300ms ease;
  }

  /* toggled by bottom_nav.js once scrolling has stopped */
  .bottom-nav.bn-hidden {
    transform: translateY(100%);
  }

  /* light --sidebar-bg is translucent, so the bar uses --bg there; dark
     keeps the solid sidebar colour */
  html[data-theme="dark"] .bottom-nav {
    background: var(--sidebar-bg);
  }

  .bn-link {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: none;
    background: none;
    color: var(--muted);
    font-family: inherit;
    font-size: 10px;
    line-height: 1;
    padding: 4px 2px;
    cursor: pointer;
  }

  .bn-link svg {
    width: 22px;
    height: 22px;
  }

  .bn-link.active {
    color: var(--accent);
  }

  /* the sheet replaces the bar while it is open */
  body.bn-sheet-open .bottom-nav {
    visibility: hidden;
  }

  /* transparent tap-to-close layer only. The dimming is painted by
     .bn-sheet's box-shadow instead: a coloured fixed element touching the
     top edge makes iOS Safari tint the status bar with it, and the tint
     stuck after the sheet closed. */
  .bn-sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 950;
    visibility: hidden;
    pointer-events: none;
  }

  .bn-sheet-backdrop.open {
    visibility: visible;
    pointer-events: all;
  }

  .bn-sheet {
    display: flex;
    flex-direction: column;
    gap: 2px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 960;
    background: var(--bg);
    border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0;
    box-shadow: var(--shadow), 0 0 0 100vmax rgba(0, 0, 0, 0);
    padding: 10px 10px calc(14px + env(safe-area-inset-bottom));
    transform: translateY(100%);
    visibility: hidden;
    transition: transform 220ms ease, box-shadow 220ms ease, visibility 0s linear 220ms;
  }

  .bn-sheet.open {
    transform: translateY(0);
    visibility: visible;
    box-shadow: var(--shadow), 0 0 0 100vmax rgba(0, 0, 0, 0.35);
    transition: transform 220ms ease, box-shadow 220ms ease, visibility 0s;
  }

  .bn-sheet-link {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 13px 12px;
    border-radius: 12px;
    color: var(--text);
  }

  .bn-sheet-link svg {
    width: 20px;
    height: 20px;
    color: var(--muted);
    flex-shrink: 0;
  }

  .bn-sheet-link:hover {
    background: var(--panel-2);
  }

  .bn-sheet-link.active {
    color: var(--accent);
  }

  .bn-sheet-link.active svg {
    color: var(--accent);
  }
}

/* ─────────────────────────
   Responsive
───────────────────────── */

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }

  /* mobile: toggle scrolls away with the page instead of hovering over
     content. Anchored to .app (in normal flow) rather than the initial
     containing block, since body is the scroll container here — an
     absolute box against the ICB would still look pinned. */
  .app { position: relative; }

  .theme-toggle {
    position: absolute;
    top: max(12px, env(safe-area-inset-top));
  }

  /* sidebar (profile card + nav list) is hidden on mobile by default —
     bottom-nav replaces the nav list; home page re-shows the profile
     card portion only (see body.is-home override + .nav { display:none }) */
  .sidebar {
    display: none;
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding-top: 72px; /* reserve space for fixed toggle */
  }

  body.is-home .sidebar {
    display: block;
  }

  body.is-home .sidebar .nav {
    display: none;
  }

  /* mobile home: circular avatar + matching circular gold frame */
  body.is-home .avatar {
    border-radius: 50%;
  }

  body.is-home .avatar-wrap {
    border-radius: 50%;
  }

  .main {
    padding: 28px 18px;
    padding-top: 72px; /* reserve space for fixed toggle */
    padding-bottom: calc(84px + env(safe-area-inset-bottom));
  }

  .page { max-width: 100%; }
}

/* iPad landscape (Pro 11"/12.9" etc.) sits between the mobile breakpoint
   (980) and desktop — without this it inherits raw desktop sidebar
   width/padding squeezed into less room. Targeted via pointer/hover
   instead of a fixed px width since Safari zoom/display-scale settings
   shift the reported viewport width per-device. */
@media (hover: none) and (pointer: coarse) and (orientation: landscape) and (min-width: 980px) and (max-width: 1400px) {
  .app {
    grid-template-columns: 260px 1fr;
  }

  .sidebar {
    padding: 22px 16px;
    overflow-y: auto;
    /* iOS Safari's `vh` is the largest viewport (ignores its own visible
       toolbar chrome) — 100vh overclaims height, pushing bottom nav links
       past the actually-visible area. `dvh` tracks the real visible area. */
    height: 100dvh;
  }

  .avatar {
    width: 150px;
    height: 150px;
  }

  .name {
    font-size: 23px;
  }

  .tagline {
    font-size: 13px;
  }

  .main {
    padding: 40px 22px;
  }
}

/* tighter sizing on small phones so it doesn’t feel “zoomed in” */
@media (max-width: 520px){
  .sidebar{
    padding: 16px 14px;
    padding-top: 68px; /* still reserves space for toggle */
  }

  .sidebar-card{
    padding: 14px 14px 16px 14px;
  }

  .avatar{
    width: 150px;
    height: 150px;
  }

  .name{
    font-size: 21px;
    margin-top: 12px;
  }

  .tagline{
    font-size: 12px;
    margin-bottom: 12px;
  }

  .main{
    padding: 18px 14px;
    padding-top: 68px; /* still reserves space for toggle */
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
  }

  .theme-toggle{
    top: max(10px, env(safe-area-inset-top));
    right: 10px;
  }

  .np-text{
    font-size: 12px;
  }
}
