/*
Theme Name: Artist Theme
Theme URI: https://example.com/artisttheme
Author: You
Author URI: https://example.com
Description: 汎用的なアーティスト向けブロックテーマ（作品・展示のCPT、ギャラリー、ニュース、プロフィール/コンタクト対応）
Requires at least: 6.2
Tested up to: 6.6
Requires PHP: 7.4
Version: 0.1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: artisttheme
Tags: full-site-editing, block-styles, blog, portfolio, accessibility-ready
*/

/* 最低限のフロント補助（詳細は theme.json） */
:root { 
  --artisttheme-max-width: 1200px;
  --header-height: 80px;
}

/* Typography */
body {
  font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-weight: 300;
  letter-spacing: 0.02em;
  line-height: 1.8;
  color: #333;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 400;
  letter-spacing: 0.04em;
  line-height: 1.4;
}

/* Header Styles */
.wp-site-blocks > header:first-child,
header.site-header {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  width: 100% !important;
  z-index: 1000 !important;
  background: rgba(255, 255, 255, 0.95) !important;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
}

header.site-header .wp-block-navigation__container {
  gap: 2rem;
}

header.site-header .wp-block-navigation-item__link {
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #666;
  transition: color 0.3s ease;
  text-decoration: none;
}

header.site-header .wp-block-navigation-item__link:hover {
  color: #000;
}

/* Main Content Spacing */
.wp-site-blocks > *:nth-child(2) {
  margin-top: 80px;
}

/* Hero section after header - no margin */
.wp-site-blocks > header:first-child + .alignfull {
  margin-top: 60px !important;
}

.wp-site-blocks > header:first-child + .alignfull .hero-random-works {
  margin-top: 0 !important;
}

/* Remove default WordPress margins on full-width blocks */
.alignfull {
  margin-left: calc(-50vw + 50%) !important;
  margin-right: calc(-50vw + 50%) !important;
  max-width: 100vw !important;
  width: 100vw !important;
}

/* Image Gallery Styles */
.wp-block-gallery {
  gap: 20px;
}

.wp-block-gallery .wp-block-image img {
  width: 100%;
  height: auto;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.wp-block-gallery .wp-block-image:hover img {
  transform: scale(1.02);
}

/* Hero Random Works */
.hero-random-works {
  margin: 0 !important;
  padding: 0 !important;
  width: 100vw !important;
  max-width: 100vw !important;
  margin-left: calc(-50vw + 50%) !important;
  height: 60vh;
  overflow: hidden;
}

.hero-random-works .wp-block-query {
  margin: 0 !important;
  padding: 0 !important;
  width: 100% !important;
  height: 100%;
}

.hero-random-works .wp-block-post-template {
  display: flex !important;
  flex-wrap: nowrap !important;
  gap: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  width: 100% !important;
  height: 100%;
  align-items: stretch !important;
}

.hero-random-works .wp-block-post-template > * {
  flex: 1 1 33.333% !important;
  width: 33.333% !important;
  height: 100%;
}

.hero-random-works .wp-block-post-template > *:nth-child(n+4) {
  display: none !important;
}

.hero-random-works .wp-block-group {
  position: relative;
  overflow: hidden;
  margin: 0 !important;
  padding: 0 !important;
  width: 100% !important;
  height: 100%;
}

.hero-random-works .wp-block-post-featured-image {
  margin: 0 !important;
  padding: 0 !important;
  line-height: 0;
  width: 100% !important;
  height: 100% !important;
  aspect-ratio: unset !important;
}

.hero-random-works .wp-block-post-featured-image img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  object-position: center !important;
  display: block;
}

.hero-work-title {
  position: absolute;
  bottom: 20px;
  left: 20px;
  color: white;
  font-size: 14px;
  font-weight: 300;
  letter-spacing: 0.05em;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  z-index: 10;
}

/* タブレット対応 (768px - 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
  .hero-random-works {
    height: 50vh;
  }
  
  .hero-random-works .wp-block-post-template > * {
    flex: 1 1 50% !important;
    width: 50% !important;
  }
  
  .hero-random-works .wp-block-post-template > *:nth-child(n+3) {
    display: none !important;
  }
}

/* モバイル対応 (768px以下) */
@media (max-width: 768px) {
  .hero-random-works {
    height: 80vw;
  }
  
  .hero-random-works .wp-block-post-template > * {
    flex: 1 1 100% !important;
    width: 100% !important;
  }
  
  .hero-random-works .wp-block-post-template > *:nth-child(n+2) {
    display: none !important;
  }
  
  .hero-work-title {
    font-size: 12px;
    bottom: 15px;
    left: 15px;
  }
}

/* Flow Layout Margin Override */
:root :where(.is-layout-flow) > *:not(h1, h2, h3, h4, h5, h6):not(.masonry-item) {
  margin-block-start: 1rem;
  margin-block-end: 0;
}

/* Constrained Layout Margin (triple spacing) - only for section-level groups */
:root :where(.is-layout-constrained) > .wp-block-group {
  margin-block-start: 6rem;
  margin-block-end: 0;
}

/* Also apply 6rem above headings inside constrained layout */
:root :where(.is-layout-constrained) > :is(h1, h2, h3, h4, h5, h6) {
  margin-block-start: 6rem;
}

/* Do not apply the 6rem spacing inside header */
header :where(.is-layout-constrained) > .wp-block-group {
  margin-block-start: 0;
  margin-block-end: 0;
}
header :where(.is-layout-constrained) > :is(h1, h2, h3, h4, h5, h6) {
  margin-block-start: 0;
}

/* If the header element itself is constrained, also reset spacing on its direct children */
header.is-layout-constrained > .wp-block-group {
  margin-block-start: 0;
  margin-block-end: 0;
}
header.is-layout-constrained > :is(h1, h2, h3, h4, h5, h6) {
  margin-block-start: 0;
}

/* Gallery specific flow layout override */
.masonry-gallery.is-layout-flow > * {
  margin-block-start: 0 !important;
  margin-block-end: 0 !important;
}

/* Force column layout for post template */
.masonry-gallery .is-layout-flow {
  display: block !important;
}

/* Heading overrides for Tailwind classes */
.wp-block-heading.\!text-5xl {
  font-size: 3rem !important;
}

.wp-block-heading.\!text-6xl {
  font-size: 3.75rem !important;
}

@media (min-width: 768px) {
  .wp-block-heading.md\:\!text-6xl {
    font-size: 3.75rem !important;
  }
}

/* Gallery Masonry Layout */
.gallery-container {
  width: 100%;
  max-width: var(--wp--custom--wide-size);
  margin: 0 auto;
  padding: 40px 0; /* horizontal padding now handled by utility classes */
}

.gallery-title {
  text-align: center;
  font-size: 2.5rem;
  margin-bottom: 40px;
  font-weight: 300;
  letter-spacing: 0.1em;
}

/* Simple Masonry using columns */
.masonry-gallery {
  width: 100%;
  max-width: 100%;
}

/* Override any conflicting styles */
.masonry-gallery .wp-block-query,
.masonry-gallery .is-layout-flow {
  display: block !important;
  width: 100% !important;
}

.masonry-gallery ul.masonry-grid,
.masonry-gallery .masonry-grid,
.masonry-gallery .wp-block-post-template {
  column-count: 4 !important;
  -webkit-column-count: 4 !important;
  -moz-column-count: 4 !important;
  column-fill: balance; /* distribute content across columns */
  column-gap: 10px !important;
  -webkit-column-gap: 10px !important;
  -moz-column-gap: 10px !important;
  margin: 0 !important;
  padding: 0 !important;
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  list-style: none !important;
}

.masonry-gallery ul.masonry-grid > li,
.masonry-gallery .masonry-grid > li,
.masonry-gallery .wp-block-post-template > li,
.masonry-item {
  break-inside: avoid !important;
  -webkit-column-break-inside: avoid !important;
  page-break-inside: avoid !important;
  display: block !important; /* block works best with CSS columns */
  width: 100% !important;
  margin: 0 0 5px 0 !important; /* half vertical gap on desktop */
  padding: 0 !important;
  position: relative;
  background: #f5f5f5;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.masonry-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.masonry-item .wp-block-group {
  margin: 0 !important;
  padding: 0 !important;
  width: 100%;
}

.masonry-item .gallery-image,
.masonry-item .wp-block-post-featured-image {
  width: 100%;
  height: auto;
  margin: 0 !important;
  padding: 0 !important;
  line-height: 0;
}

.masonry-item .gallery-image img,
.masonry-item .wp-block-post-featured-image img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: cover;
}

.gallery-image-title {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 10px 15px;
  background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
  color: white;
  font-size: 14px;
  font-weight: 300;
  letter-spacing: 0.05em;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.masonry-item:hover .gallery-image-title {
  opacity: 1;
}

/* Lightbox */
.lightbox {
  display: none;
  position: fixed;
  z-index: 999999;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0,0,0,0.95);
}

/* Admin bar adjustment */
body.admin-bar .lightbox {
  top: 32px;
  height: calc(100% - 32px);
}

@media screen and (max-width: 782px) {
  body.admin-bar .lightbox {
    top: 46px;
    height: calc(100% - 46px);
  }
}

.lightbox-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 90%;
  max-height: 85vh;
  object-fit: contain;
}

.lightbox-caption {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  width: 80%;
  max-width: 700px;
  text-align: center;
  color: #fff;
  padding: 10px 20px;
  font-size: 16px;
  letter-spacing: 0.05em;
  background: rgba(0,0,0,0.5);
  border-radius: 4px;
}

.lightbox-close {
  position: absolute;
  top: 25px;
  right: 35px;
  color: #f1f1f1;
  font-size: 40px;
  font-weight: 300;
  transition: 0.3s;
  cursor: pointer;
  z-index: 10000;
}

.lightbox-close:hover,
.lightbox-close:focus {
  color: #bbb;
}

/* Gallery Pagination */
.gallery-pagination {
  margin-top: 50px;
  padding: 20px 0;
  text-align: center;
}

.gallery-pagination a {
  color: #333;
  padding: 8px 16px;
  text-decoration: none;
  transition: background-color 0.3s;
  margin: 0 5px;
}

.gallery-pagination a:hover {
  background-color: #f1f1f1;
}

.gallery-pagination .current {
  background-color: #333;
  color: white;
  padding: 8px 16px;
  margin: 0 5px;
}

/* Responsive Gallery */
/* Desktop: ensure 4 columns from 1024px and up */
@media screen and (min-width: 1024px) {
  .masonry-gallery ul.masonry-grid,
  .masonry-gallery .masonry-grid,
  .masonry-gallery .wp-block-post-template {
    column-count: 4 !important;
    -webkit-column-count: 4 !important;
    -moz-column-count: 4 !important;
  }
}

@media screen and (min-width: 1200px) {
  .masonry-gallery ul.masonry-grid,
  .masonry-gallery .masonry-grid,
  .masonry-gallery .wp-block-post-template {
    column-count: 4 !important;
    -webkit-column-count: 4 !important;
    -moz-column-count: 4 !important;
  }
}

/* Tablet landscape: use 3 columns up to 1023px */
@media (max-width: 1023px) and (min-width: 769px) {
  .masonry-gallery ul.masonry-grid,
  .masonry-gallery .masonry-grid,
  .masonry-gallery .wp-block-post-template {
    column-count: 3 !important;
    -webkit-column-count: 3 !important;
    -moz-column-count: 3 !important;
    column-gap: 10px !important;
  }
  
  .masonry-gallery ul.masonry-grid > li,
  .masonry-gallery .masonry-grid > li,
  .masonry-item {
    margin: 0 0 5px 0 !important; /* half vertical gap */
  }
}

@media (max-width: 768px) {
  .gallery-container {
    padding: 20px 10px;
  }
  
  .gallery-title {
    font-size: 2rem;
    margin-bottom: 30px;
  }
  
  .masonry-gallery ul.masonry-grid,
  .masonry-gallery .masonry-grid,
  .masonry-gallery .wp-block-post-template {
    column-count: 2 !important;
    -webkit-column-count: 2 !important;
    -moz-column-count: 2 !important;
    column-gap: 8px !important;
  }
  
  .masonry-gallery ul.masonry-grid > li,
  .masonry-gallery .masonry-grid > li,
  .masonry-item {
  margin: 0 0 4px 0 !important; /* half vertical gap */
  }
  
  .gallery-image-title {
    font-size: 12px;
    padding: 8px 10px;
  }
  
  .lightbox-close {
    top: 15px;
    right: 20px;
    font-size: 30px;
  }
  
  .lightbox-caption {
    bottom: 20px;
    font-size: 14px;
    padding: 8px 15px;
  }
}

@media (max-width: 480px) {
  .masonry-gallery ul.masonry-grid,
  .masonry-gallery .masonry-grid,
  .masonry-gallery .wp-block-post-template {
    column-count: 2 !important;
    -webkit-column-count: 2 !important;
    -moz-column-count: 2 !important;
    column-gap: 6px !important;
  }
  
  .masonry-gallery ul.masonry-grid > li,
  .masonry-gallery .masonry-grid > li,
  .masonry-item {
  margin: 0 0 3px 0 !important; /* half vertical gap */
  }
}

/* Work Grid */
.work-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 30px;
  padding: 60px 0;
}

.work-item {
  position: relative;
  overflow: hidden;
  background: #f9f9f9;
  transition: transform 0.3s ease;
}

.work-item:hover {
  transform: translateY(-5px);
}

.work-item img {
  width: 100%;
  height: auto;
  aspect-ratio: 4/3;
  object-fit: cover;
}

.work-item-info {
  padding: 20px;
  background: white;
}

.work-item-title {
  font-size: 16px;
  font-weight: 400;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.work-item-meta {
  font-size: 13px;
  color: #999;
  letter-spacing: 0.03em;
}

/* Section Spacing */
.wp-block-group.section-padding {
  padding: 80px 0;
}

/* Footer */
footer.site-footer {
  background: #fafafa;
  border-top: 1px solid #eee;
  padding: 60px 0 40px;
  margin-top: 100px;
}

footer.site-footer p {
  font-size: 13px;
  color: #999;
  letter-spacing: 0.03em;
}

/* Utilities */
.alignwide { max-width: min(1200px, 92vw); margin-left: auto; margin-right: auto; }
.alignfull { max-width: 100%; }
.wp-block-post-featured-image img { width: 100%; height: auto; display: block; }
.is-hidden { display: none !important; }

/* Minimalist Buttons */
.wp-block-button__link {
  background: transparent;
  color: #333;
  border: 1px solid #333;
  padding: 12px 32px;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: all 0.3s ease;
}

.wp-block-button__link:hover {
  background: #333;
  color: white;
}

/* Responsive */
@media (max-width: 768px) {
  :root {
    --header-height: 60px;
  }
  
  .work-grid {
    grid-template-columns: 1fr;
    gap: 20px;
    padding: 40px 20px;
  }
  
  .wp-block-group.section-padding {
    padding: 50px 20px;
  }
  
  header.site-header .wp-block-navigation__container {
    gap: 1rem;
  }
}
