/* ════════════════════════════════════════════════════
   myjpeg.jp — macOS Finder–style gallery
   (reference: 379784.cargo.site)
   ════════════════════════════════════════════════════ */

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

/* ──────────────────────────────────────────────
   Color tokens — Apple system colors (iOS / macOS)
   Light is the default; dark via prefers-color-scheme.
   ────────────────────────────────────────────── */
:root {
  /* layout */
  --sidebar-w:     286px;
  --sidebar-inset: 12px;
  --card-radius:   20px;
  --radius-item:   11px;
  /* Apple system font (SF Pro via -apple-system; SF Text/Display optical split is automatic) */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
          "Helvetica Neue", Helvetica, Arial, "Hiragino Sans",
          "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;

  /* LIGHT — Apple system colors */
  --bg:          #F2F2F7;               /* systemGroupedBackground       */
  --main-bg:     #FFFFFF;               /* systemBackground              */
  --sidebar-bg:  rgba(255,255,255,0.72);/* frosted sidebar material      */
  --card-border: #C6C6C8;               /* opaqueSeparator               */
  --ink:         rgba(0,0,0,0.85);      /* labelColor                    */
  --ink-soft:    rgba(0,0,0,0.5);       /* secondaryLabelColor           */
  --ink-mute:    rgba(0,0,0,0.25);      /* tertiaryLabelColor            */
  --accent:      #007AFF;               /* systemBlue                    */
  --hover-bg:    rgba(0,0,0,0.05);
  --active-bg:   rgba(0,0,0,0.07);
  --overlay-bg:  rgba(242,242,247,0.8); /* preview backdrop              */
  --track:       rgba(0,0,0,0.22);      /* slider track                  */
  --img-shadow:  rgba(0,0,0,0.22);
}

@media (prefers-color-scheme: dark) {
  :root {
    /* DARK — Apple system colors */
    --bg:          #000000;               /* systemGroupedBackground (dark)        */
    --main-bg:     #1C1C1E;               /* secondarySystemGroupedBackground      */
    --sidebar-bg:  rgba(44,44,46,0.72);   /* tertiarySystemBackground, frosted     */
    --card-border: #38383A;               /* opaqueSeparator (dark)                */
    --ink:         rgba(255,255,255,0.85);/* labelColor (dark)                     */
    --ink-soft:    rgba(235,235,245,0.6); /* secondaryLabelColor (dark)            */
    --ink-mute:    rgba(235,235,245,0.3); /* tertiaryLabelColor (dark)             */
    --accent:      #0A84FF;               /* systemBlue (dark)                     */
    --hover-bg:    rgba(255,255,255,0.08);
    --active-bg:   rgba(255,255,255,0.11);
    --overlay-bg:  rgba(0,0,0,0.8);
    --track:       rgba(255,255,255,0.28);
    --img-shadow:  rgba(0,0,0,0.6);
  }
}

html, body {
  height: 100%;
  color-scheme: light dark;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;                 /* 1rem = 16px → rem multiples hit HIG pt sizes */
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ── Layout ── */
.content-wrap { display: flex; min-height: 100vh; }

/* ════════════ Sidebar (floating card) ════════════ */
.sidebar {
  position: fixed;
  top: var(--sidebar-inset);
  left: var(--sidebar-inset);
  bottom: var(--sidebar-inset);
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  padding: 14px 12px 18px;
  overflow-y: auto;
  z-index: 20;
  /* floating translucent card */
  background: var(--sidebar-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--card-radius);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

/* Title row (traffic lights + name) */
.titlebar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0px 8px 0;
  margin-bottom: 22px;
}

.traffic-lights { display: flex; gap: 8px; flex-shrink: 0; }
.tl { width: 14px; height: 14px; border-radius: 50%; }
.tl-red    { background: #FF5F56; cursor: pointer; }
.tl-green  { background: #27C93F; cursor: pointer; }
.tl-red:hover, .tl-green:hover { filter: brightness(0.92); }
.tl-yellow { background: #FFBD2E; }
.tl-green  { background: #27C93F; }

.site-title {
  font-size: 1.0625rem;         /* HIG Headline · 17pt */
  font-weight: 600;             /* Semibold */
  line-height: 1.4;             /* room for j/p/g descenders */
  letter-spacing: -0.024em;     /* -0.43pt */
  color: var(--ink);
  white-space: nowrap;          /* no clipping — short fixed brand name */
}

/* Mobile menu button — hidden on desktop */
.menu-toggle { display: none; }

/* ── Nav ── */
.nav-inner { display: flex; flex-direction: column; }

.nav-section { margin-top: 26px; }
.nav-section:first-child { margin-top: 0; }

.nav-label {
  font-size: 0.8125rem;         /* HIG Footnote · 13pt (iOS sidebar header) */
  font-weight: 600;             /* Semibold */
  line-height: 1.3846;          /* 18/13 */
  letter-spacing: -0.006em;     /* -0.08pt */
  color: var(--ink-soft);
  padding: 0 6px 6px;
}

.nav-list { list-style: none; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: var(--radius-item);
  cursor: pointer;
  color: var(--ink);
  font-size: 1.0625rem;         /* HIG Body · 17pt (iOS sidebar row) */
  font-weight: 400;             /* Regular */
  line-height: 1.2941;          /* 22/17 leading */
  letter-spacing: normal;       /* trust SF's native metrics */
  white-space: nowrap;
  transition: background 0.12s ease, color 0.12s ease;
}

.nav-item > .label {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.nav-item:hover:not(.active) { background: var(--hover-bg); }

.nav-item.active {
  background: var(--active-bg);
  color: var(--accent);
}

/* Small folder glyph in the sidebar — monochrome SF-style symbol */
.nav-glyph {
  width: 18px; height: 18px;
  flex-shrink: 0;
  color: var(--ink-soft);            /* secondaryLabel — adapts to light/dark */
}
.nav-glyph path { fill: currentColor; }
.nav-item.active .nav-glyph { color: var(--accent); }   /* tint when selected */

/* Coloured dot (folders / links) */
.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

/* Link items */
.link-item a { color: inherit; text-decoration: none; flex: 1; }
.link-item a:hover { text-decoration: underline; }
.ext-arrow { color: var(--ink-soft); font-size: 0.85em; }

/* Brand icon for links (monochrome, adapts to light/dark) */
.link-icon { width: 18px; height: 18px; flex-shrink: 0; color: var(--ink); }
.link-icon path { fill: currentColor; }

/* ════════════ Content ════════════ */
.pages {
  /* floating white card, fixed to viewport */
  position: fixed;
  top: var(--sidebar-inset);
  right: var(--sidebar-inset);
  bottom: var(--sidebar-inset);
  left: calc(var(--sidebar-w) + var(--sidebar-inset) * 2);
  display: flex;
  flex-direction: column;
  overflow: hidden;                 /* clip footer to rounded corners */
  background: var(--main-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--card-radius);
  min-width: 0;
}

/* Scrollable content region */
.pages-scroll {
  flex: 1;
  min-height: 0;          /* allow shrink so the card matches its height */
  overflow-y: auto;
  padding: 40px 40px 28px;
}

/* Footer (full width of main area) */
.main-footer {
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  padding: 0 18px;
  border-top: 1px solid var(--card-border);
}

.copyright {
  font-size: 0.75rem;           /* HIG Caption 1 · 12pt */
  line-height: 1.3333;          /* 16/12 */
  letter-spacing: 0.02em;
  color: var(--ink-soft);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;   /* fixed-width digits → no jitter as ms tick */
  font-feature-settings: "tnum" 1;
}

/* Finder-style grids (folders & images share base) */
.finder-grid {
  display: grid;
  gap: 30px 24px;
}

/* Overview: grouped by sidebar section, divided into rows */
#overview-view {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.ov-group {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 40px 46px;   /* ≒ reference 3rem gutter */
}
.ov-divider {
  width: 100%;
  border: none;
  border-top: 1px solid var(--card-border);
  margin: 28px 0;
}

/* Image view: thumbnails — column count driven by the slider */
#image-view {
  grid-template-columns: repeat(var(--img-cols, 6), minmax(0, 1fr));
}
.loading { color: var(--ink-soft); font-size: 0.9rem; padding: 4px 2px; }

/* ── Cell (folder, file, or photo) ── */
.cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  text-align: center;
}

.cell-icon {
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

/* Folder / file icon size (reference ≈ 90px square) */
.folder-cell .cell-icon svg,
.file-cell   .cell-icon svg { width: 84px; height: auto; }

.cell-icon img.icon-png {
  width: 92px;
  height: 92px;
  object-fit: contain;
}

/* Photo thumbnail */
.photo-cell .cell-icon {
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
.photo-cell .cell-icon img {
  display: block;
  width: 100%;
  height: auto;
  transition: opacity 0.15s ease;
}
.photo-cell:hover .cell-icon img { opacity: 0.9; }

/* Caption */
.cell-caption {
  font-size: 0.8125rem;         /* HIG Footnote · 13pt */
  line-height: 1.3846;          /* 18/13 */
  letter-spacing: -0.006em;     /* -0.08pt */
  color: var(--ink);
  display: block;
  max-width: 100%;
  white-space: nowrap;          /* never wrap to 2 lines */
  overflow: hidden;
  text-overflow: ellipsis;      /* over-long names truncate with … */
  text-align: center;
  padding: 1px 7px;
  border-radius: 6px;
}
.cell-caption .dot {            /* keep the marker on the same line */
  display: inline-block;
  vertical-align: middle;
  margin-right: 6px;
  margin-bottom: 2px;
}

/* Selected caption look (Finder blue highlight) */
.folder-cell:hover .cell-caption,
.file-cell:hover .cell-caption {
  background: var(--active-bg);
}

/* ════════════ Lightbox ════════════ */
.lightbox {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);          /* adapts to light / dark */
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.lightbox.hidden { display: none !important; }

.lb-figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.lb-img {
  max-width: 86vw;
  max-height: 82vh;
  object-fit: contain;
  border-radius: 0;                       /* 角丸なし */
  box-shadow: 0 14px 50px var(--img-shadow);
}
.lb-caption {
  font-size: 0.8125rem;         /* HIG Footnote · 13pt */
  line-height: 1.3846;
  letter-spacing: -0.006em;
  color: var(--ink-soft);
}

/* Close button */
.lb-close {
  position: fixed;
  top: 20px; right: 24px;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: none;
  color: var(--ink-soft);
  cursor: pointer; transition: color 0.15s;
}
.lb-close:hover { color: var(--ink); }

/* Prev / next arrows (icon only, no circle) */
.lb-nav {
  position: fixed;
  top: 50%; transform: translateY(-50%);
  width: 52px; height: 52px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: none;
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 0.15s;
}
.lb-nav:hover { color: var(--ink); }
.lb-prev { left: 24px; }
.lb-next { right: 24px; }
.lb-nav.hidden { display: none !important; }

.hidden { display: none !important; }

/* ════════════ Document popup (about me.rtf) ════════════ */
.doc-modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;            /* vertical center */
  justify-content: center;
  padding: 24px;
}
.doc-modal.hidden { display: none !important; }

.doc-window {
  width: min(620px, 100%);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: var(--main-bg);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.28);
  overflow: hidden;
}

.doc-titlebar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 18px 12px;
  flex-shrink: 0;
}
.doc-title {
  font-size: 1.0625rem;           /* HIG Headline · 17pt */
  font-weight: 600;
  letter-spacing: -0.024em;
  color: var(--ink);
}

.doc-body {
  padding: 12px 26px 100px;
  overflow-y: auto;
  color: var(--ink);
  font-size: 1.0625rem;           /* Body · 17pt */
  line-height: 1.55;
  letter-spacing: -0.012em;
}
.doc-body p { margin: 0 0 1.25em; }
.doc-body p:last-child { margin-bottom: 0; }
.doc-body a { color: var(--ink); text-decoration: underline; text-underline-offset: 2px; }

/* Decorative blinking text cursor at the end */
.caret {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  margin-left: 3px;
  vertical-align: -0.2em;
  background: var(--ink);
  animation: caret-blink 1.06s steps(1) infinite;
}
@keyframes caret-blink {
  0%, 50%   { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

@media (max-width: 760px) {
  .doc-modal { padding: 16px 24px; }   /* more side margin → narrower window */
  .doc-window { max-height: 78vh; border-radius: 20px; }
  .doc-body { padding: 10px 22px 86px; }
}

/* ════════════ Grid size slider (in footer, right) ════════════ */
.grid-slider {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
}
.grid-slider.hidden { display: none !important; }

#gs-range {
  -webkit-appearance: none;
  appearance: none;
  width: 108px;
  height: 16px;
  background: transparent;
  cursor: pointer;
}
#gs-range::-webkit-slider-runnable-track {
  height: 3px; border-radius: 3px; background: var(--track);
}
#gs-range::-moz-range-track {
  height: 3px; border-radius: 3px; background: var(--track);
}
#gs-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; margin-top: -6.5px;
  border-radius: 50%; background: #fff;
  border: 0.5px solid rgba(0,0,0,0.2);
  box-shadow: 0 1px 3px rgba(0,0,0,0.35);
}
#gs-range::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%; background: #fff;
  border: 0.5px solid rgba(0,0,0,0.2);
  box-shadow: 0 1px 3px rgba(0,0,0,0.35);
}

/* ════════════ Responsive ════════════ */
@media (max-width: 760px) {
  .sidebar {
    position: static;
    inset: auto;
    width: auto;
    margin: 12px 12px 0;
    border-radius: 28px;
    padding: 0 18px;
  }
  .sidebar.open { padding-bottom: 14px; }

  /* Clean header row */
  .titlebar {
    height: 54px;
    margin-bottom: 0;
    gap: 12px;
    align-items: center;
    padding: 0px 2px 0;
  }
  .titlebar .site-title {
    font-size: 1.0625rem;        /* HIG Headline · 17pt */
    line-height: 1.4;            /* room for descenders */
  }
  .traffic-lights { gap: 7px; }

  /* Menu button — three dots (ellipsis) */
  .menu-toggle {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-left: auto;
    width: 40px; height: 44px;
    background: none; border: none; cursor: pointer;
  }
  .menu-toggle span {
    display: block;
    width: 4px; height: 4px;
    border-radius: 50%;
    background: var(--ink-soft);
    transition: transform 0.2s ease, background 0.2s ease;
  }
  .menu-toggle:hover span,
  .sidebar.open .menu-toggle span { background: var(--ink); }

  /* Collapsible nav (pulldown) — grid-rows animates the real height,
     so open and close are perfectly symmetric (no jerk). */
  .nav {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.45s ease;
  }
  .sidebar.open .nav { grid-template-rows: 1fr; }

  .nav-inner {
    overflow: hidden;
    min-height: 0;          /* can shrink to 0 when collapsed */
  }
  .sidebar.open .nav-inner {
    max-height: 75vh;
    overflow-y: auto;       /* scroll only if the menu is very long */
  }
  /* Top gap lives on the content (clipped when closed) → no leftover
     8px strip, and no snap during collapse. */
  .nav-inner > .nav-section:first-child { padding-top: 8px; }
  .pages {
    position: static;
    inset: auto;
    margin: 12px;
    border-radius: 28px;
    flex: 1;              /* fill remaining screen height */
    min-height: 0;
  }
  .pages-scroll { padding: 24px 24px 24px; }
  .content-wrap {
    flex-direction: column;
    height: 100vh;
    height: 100dvh;       /* fixed → card fills the screen, scrolls inside */
    overflow: hidden;
  }
  /* nav rows inherit the iOS Body · 17pt size from base */
  .grid-slider { right: 14px; }
  #gs-range { width: 86px; }
  .copyright { font-size: 0.74rem; }

  /* rounder corners overall on mobile */
  .nav-item { border-radius: 13px; }
  .photo-cell .cell-icon { border-radius: 12px; }

  /* wider overview columns so folder names fit on one line */
  .ov-group { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 20px 0px; }

  .ov-divider { margin: 24px 0; }
  .cell { gap: 10px; }                    /* photo thumbnails keep their spacing */
  .folder-cell, .file-cell { gap: 4px; }  /* Overview only: icon ↔ title closer */
  .cell-icon img.icon-png { width: 112px; height: 112px; }  /* one size up on mobile */

  /* preview: hide arrows, navigate by swipe instead */
  .lb-nav { display: none; }
}
