/*
Theme Name: Masonry Audio Archive
Author: ChatGPT (refined)
Version: 3.0
Description: Stable masonry audio archive with custom fonts and color palettes
Text Domain: masonry-audio-archive
*/

/* ============================================================
   CSS CUSTOM PROPERTIES
   ============================================================ */
:root {
  --paper:    #f2efe8;
  --ink:      #1a1a1a;
  --accent:   #9c7b5b;
  --tile-bg:  #ffffff;
  --gap:      24px;
  --max-w:    1200px;
  --pad-x:    28px;
  --font-body: Georgia, serif;

  /* touch-friendly minimum target height */
  --touch-min: 44px;

  /* footer separator */
  --footer-sep: #dddddd;

  /* header icon size */
  --maa-icon-size: 28px;
}

/* ============================================================
   RESET / BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
}

/* Prevent any element from causing horizontal scroll on mobile */
html {
  overflow-x: hidden;
}

body {
  margin: 0;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

/* Subtle paper-grain overlay — pointer-events off so it never blocks taps */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  touch-action: none;
  opacity: .15;
  background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg"><filter id="n"><feTurbulence type="fractalNoise" baseFrequency="0.8" numOctaves="2" stitchTiles="stitch"/></filter><rect width="100%" height="100%" filter="url(%23n)" opacity="0.35"/></svg>');
  mix-blend-mode: multiply;
  z-index: 0;
}

/* ============================================================
   SITE WRAPPER
   ============================================================ */
.site {
  position: relative;
  z-index: 1;
  width: 100%;
  overflow-x: hidden;
}

/* Admin bar offsets */
body.admin-bar .site-header { top: 32px; }
@media (max-width: 782px) {
  body.admin-bar .site-header { top: 46px; }
}

/* ============================================================
   HEADER
   ============================================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--paper);
  border-bottom: 1px solid rgba(0,0,0,.06);
  padding: 20px 0 16px;
}

.site-header__inner {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 var(--pad-x);
}

.site-title {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  font-size: clamp(22px, 4vw, 32px);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: .2px;
}

.maa-header-icon {
  width: var(--maa-icon-size);
  height: var(--maa-icon-size);
  max-width: var(--maa-icon-size);
  max-height: var(--maa-icon-size);
  object-fit: contain;
  flex-shrink: 0;
  position: relative;
  top: 0.05em; /* optical baseline nudge */
}

/* Also cap the WP custom-logo if used */
.custom-logo {
  width: var(--maa-icon-size) !important;
  height: auto !important;
}

.site-tagline {
  margin-top: 5px;
  font-size: 13px;
  opacity: .65;
}

/* ============================================================
   MAIN CONTENT AREA
   ============================================================ */
.site-main {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 24px var(--pad-x) 60px;
}

/* ============================================================
   TAG FILTER
   ============================================================ */
.tag-filter {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

.tag-filter button {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch-min);
  padding: 0 14px;
  border: 1px solid #ccc;
  border-radius: 22px;
  background: none;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  -webkit-tap-highlight-color: transparent;
}

.tag-filter button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tag-filter button.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

/* ============================================================
   MASONRY GRID
   ============================================================ */
.archive-grid {
  width: 100%;
  column-count: 3;
  column-gap: var(--gap);
  column-fill: balance;
}

@media (max-width: 1100px) {
  .archive-grid { column-count: 2; }
}

@media (max-width: 680px) {
  .archive-grid { column-count: 1; }
}

/* ============================================================
   ARCHIVE TILE
   ============================================================ */
.archive-item {
  position: relative;
  display: inline-block; /* required for CSS columns */
  width: 100%;
  margin: 0 0 var(--gap);
  padding: 18px;
  background: var(--tile-bg);
  border: 1px solid #e6e1d7;
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0,0,0,.06);
  transition: transform .15s, box-shadow .15s;
  overflow: hidden; /* prevent accent dot and any child from bleeding out */

  /* prevent tiles from splitting across columns */
  break-inside: avoid;
  -webkit-column-break-inside: avoid;
  page-break-inside: avoid;
}

.archive-item:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 28px rgba(0,0,0,.12);
}

/* Accent dot — bottom-right of each tile */
.archive-item::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  right: 12px;
  bottom: 12px;
  background: var(--accent);
  opacity: .6;
}

.tile-title {
  margin: 0 0 10px;
  font-size: clamp(16px, 4vw, 20px);
  font-weight: 600;
  line-height: 1.3;
}

.entry {
  font-size: 14px;
  line-height: 1.6;
}

/* Prevent audio controls from splitting across columns */
.entry audio,
.entry .wp-block-audio {
  break-inside: avoid;
  -webkit-column-break-inside: avoid;
}

/* Make native audio controls fill the tile width */
audio {
  width: 100%;
  min-height: 40px; /* comfortable touch height */
  margin-top: 10px;
}

.tile-tags {
  margin-top: 10px;
  font-size: 12px;
  opacity: .65;
  line-height: 1.5;
}

/* ============================================================
   LISTENING FOCUS MODE
   ============================================================ */

/* Blur the whole site content behind the focused tile */
body.listening .site {
  filter: blur(5px);
  pointer-events: none;
  user-select: none;
}

/* The focus-layer sits above everything and is unaffected by the blur */
#focus-layer {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none; /* pass-through when idle */
}

/* The cloned focused tile */
#focus-layer .focus-tile {
  position: fixed;
  pointer-events: auto;
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  background: var(--tile-bg);
  border: 1px solid #e6e1d7;
  padding: 18px;
  transition: top .3s cubic-bezier(.4,0,.2,1),
              left .3s cubic-bezier(.4,0,.2,1),
              width .3s cubic-bezier(.4,0,.2,1),
              box-shadow .3s;
  will-change: top, left, width;
  max-width: min(480px, 92vw);
}

/* Dismiss button inside focus tile */
.focus-dismiss {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: rgba(0,0,0,.08);
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

.focus-dismiss:hover {
  background: rgba(0,0,0,.16);
}

/* ============================================================
   FOOTER
   ============================================================ */
.site-footer {
  border-top: 1px solid var(--footer-sep, #ddd);
  padding: 32px 0 40px;
}

.site-footer__inner {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 var(--pad-x);
}

.footer-copy {
  font-size: 14px;
  line-height: 1.7;
  opacity: .75;
  max-width: 680px;
}

.footer-copy p { margin: 0 0 0.75em; }
.footer-copy p:last-child { margin-bottom: 0; }

/* ============================================================
   MOBILE REFINEMENTS
   ============================================================ */
@media (max-width: 600px) {
  :root {
    --pad-x: 20px;
    --gap: 20px;
  }

  .site-header {
    padding: 14px 0 12px;
  }

  .site-main {
    padding-top: 28px;
    padding-bottom: 80px;
  }

  .archive-item {
    padding: 24px;
    margin-bottom: 20px;
  }

  .tile-title {
    font-size: 18px;
    margin-bottom: 14px;
  }

  .entry {
    font-size: 15px;
    line-height: 1.7;
  }

  .tile-tags {
    margin-top: 14px;
    font-size: 13px;
  }

  .tag-filter {
    gap: 10px;
    margin-bottom: 24px;
  }

  /* On small screens, float the focus tile to the bottom like a mini-player */
  #focus-layer .focus-tile {
    left: 50% !important;
    transform: translateX(-50%);
    top: auto !important;
    bottom: 20px;
    width: calc(100vw - 32px) !important;
    max-width: 100%;
  }
}
