/* ============================================================
   まちライブラリー＠きほく — 案A「しずか」
   ============================================================ */

:root {
  --base:        #f6f0e4;
  --sub:         #efe7d6;
  --dark:        #38332a;
  --text:        #38332a;
  --text-mid:    #6f6757;
  --text-weak:   #8a8170;
  --text-weaker: #a89f8c;
  --accent:      #b06a47;
  --accent-lt:   #c98a64;
  --border:      rgba(56,51,42,.12);
  --border-btn:  rgba(56,51,42,.25);
  --shadow-card: 0 6px 16px rgba(56,51,42,.1);
  --max-w:       1240px;
  --pad-x:       56px;
  --pad-y:       80px;
  --nav-h:       102px;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Zen Kaku Gothic New', sans-serif;
  font-size: 16px;
  line-height: 1.8;
  color: var(--dark);
  background: var(--base);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

img { display: block; max-width: 100%; }
a { text-decoration: none; }
button { cursor: pointer; font-family: inherit; }


/* ============ NAV ============ */
.nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: rgba(246,240,228,.96);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.nav-inner {
  max-width: var(--max-w); margin: 0 auto;
  padding: 28px var(--pad-x);
  display: flex; align-items: center; justify-content: space-between;
}

.nav-logo img { height: 46px; width: auto; }

.nav-links {
  display: flex; gap: 36px;
  font-size: 14px; letter-spacing: .05em; color: var(--text-mid);
}

.nav-links a { color: inherit; transition: color .2s; }
.nav-links a:hover { color: var(--accent); }

.hamburger {
  display: none; flex-direction: column; gap: 5px;
  background: none; border: none; padding: 6px;
}
.hamburger span {
  display: block; width: 22px; height: 1.5px;
  background: var(--dark); border-radius: 2px; transition: all .3s;
}
.hamburger.active span:nth-child(1) { transform: rotate(-45deg) translate(-4px, 5px); }
.hamburger.active span:nth-child(2) { opacity: 0; }
.hamburger.active span:nth-child(3) { transform: rotate(45deg) translate(-4px, -5px); }


/* ============ HERO ============ */
.hero {
  padding-top: var(--nav-h);
  background: var(--base);
}

.hero-inner {
  max-width: var(--max-w); margin: 0 auto;
  padding: 40px var(--pad-x) 80px;
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 64px; align-items: center;
}

.hero-label {
  font-size: 13px; letter-spacing: .32em;
  color: var(--accent); font-weight: 500; margin-bottom: 28px;
}

.hero-text h1 {
  font-size: 54px; line-height: 1.5; font-weight: 500;
  letter-spacing: .02em; margin-bottom: 32px;
}

.hero-lead {
  font-size: 16px; line-height: 2.1;
  color: var(--text-mid); margin-bottom: 40px;
}

.hero-btns { display: flex; gap: 16px; flex-wrap: wrap; }

.btn-primary {
  display: inline-block;
  background: var(--dark); color: var(--base);
  padding: 15px 30px; font-size: 14px; letter-spacing: .04em;
  transition: opacity .2s;
}
.btn-primary:hover { opacity: .82; color: var(--base); }

.btn-secondary {
  display: inline-block;
  background: transparent; color: var(--dark);
  border: 1px solid var(--border-btn);
  padding: 15px 30px; font-size: 14px; letter-spacing: .04em;
  transition: border-color .2s;
}
.btn-secondary:hover { border-color: var(--dark); }

.hero-photo { position: relative; }

.hero-photo img {
  width: 100%; height: 560px; object-fit: cover;
}

.hero-img {
  filter: sepia(8%) brightness(105%) saturate(105%) contrast(96%);
}

.hero-caption {
  position: absolute; bottom: -20px; left: -20px;
  background: var(--base);
  padding: 18px 22px;
  font-size: 12px; letter-spacing: .1em; color: var(--text-weak);
}


/* ============ SECTION COMMON ============ */
.section-inner {
  max-width: var(--max-w); margin: 0 auto;
  padding: var(--pad-y) var(--pad-x);
}

.section-label {
  font-size: 12px; letter-spacing: .3em; color: var(--accent);
  margin-bottom: 20px; font-weight: 500;
}

.section-label.accent-lt { color: var(--accent-lt); }


/* ============ ABOUT ============ */
.about { border-top: 1px solid var(--border); }

.about h2 {
  font-size: 36px; font-weight: 500; line-height: 1.6;
  max-width: 680px; margin-bottom: 48px;
}

.about-body {
  font-size: 16px; line-height: 2.2; color: var(--text-mid);
  max-width: 680px; margin-bottom: 60px;
}

.about-features {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 48px;
}

.feature-bar {
  width: 36px; height: 2px; background: var(--accent); margin-bottom: 20px;
}

.feature h3 { font-size: 18px; font-weight: 500; margin-bottom: 12px; }
.feature p { font-size: 14px; line-height: 2; color: var(--text-weak); }


/* ============ BOOKS ============ */
.books-section { background: var(--sub); }

.books-header {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 48px;
}

.books-header h2 { font-size: 36px; font-weight: 500; line-height: 1.5; }

.books-all-link {
  font-size: 14px; color: var(--text-mid);
  border-bottom: 1px solid var(--accent); padding-bottom: 4px;
  white-space: nowrap; transition: color .2s; cursor: pointer;
}
.books-all-link:hover { color: var(--accent); }

/* Spine grid */
.spine-grid {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px;
  margin-bottom: 24px;
}

.spine-card {
  height: 260px; border-radius: 2px;
  padding: 16px 12px;
  display: flex; flex-direction: column; justify-content: space-between;
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition: transform .2s ease, box-shadow .2s ease;
}
.spine-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px rgba(56,51,42,.18);
}

.spine-title {
  font-size: 13px; font-weight: 500; color: #fffdf7;
  line-height: 1.5; writing-mode: vertical-rl;
  overflow: hidden;
  flex: 1; min-height: 0;
}

.spine-cat { font-size: 10px; color: rgba(255,253,247,.7); flex-shrink: 0; }

.spine-loading {
  grid-column: 1/-1;
  display: flex; flex-direction: column; align-items: center;
  gap: .875rem; padding: 3rem; color: var(--text-weak); font-size: .875rem;
}

.books-note { font-size: 13px; color: var(--text-weak); line-height: 2; }

/* Full books list */
.full-books-wrap {
  display: none;
  border-top: 1px solid var(--border);
  padding-top: 2.5rem; margin-top: 2rem;
}
.full-books-wrap.open { display: block; }

.filter-wrap { margin-bottom: 1.5rem; overflow-x: auto; padding-bottom: 4px; }
.filter-tags { display: flex; gap: .5rem; flex-wrap: wrap; }

.filter-tag {
  padding: .32rem .95rem; border-radius: 50px;
  border: 1px solid var(--border);
  background: var(--sub); color: var(--text-mid);
  font-size: .76rem; white-space: nowrap; transition: all .2s;
}
.filter-tag:hover { border-color: var(--accent); color: var(--accent); }
.filter-tag.active { background: var(--dark); border-color: var(--dark); color: var(--base); }

.books-count { font-size: .76rem; color: var(--text-weak); margin-bottom: 1rem; }

.books-status {
  display: flex; flex-direction: column; align-items: center;
  padding: 3rem 1rem; gap: .875rem;
  color: var(--text-weak); font-size: .875rem; text-align: center;
}

.books-table-wrap {
  display: none; overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: 1.5rem;
  max-height: 540px; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.books-table-wrap::-webkit-scrollbar { width: 5px; }
.books-table-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.books-section.is-loaded .books-table-wrap { display: block; }

.books-table { width: 100%; border-collapse: collapse; background: var(--base); font-size: .875rem; }
.books-table thead th {
  background: var(--dark); color: var(--base);
  padding: .825rem 1.375rem; text-align: left;
  font-weight: 500; font-size: .75rem; letter-spacing: .08em;
  white-space: nowrap; position: sticky; top: 0; z-index: 2;
}
.sortable { cursor: pointer; user-select: none; }
.sortable:hover { background: #4a443a; }
.sortable.sort-active { background: #4a443a; }
.sort-icon { margin-left: 6px; opacity: .6; font-style: normal; }
.books-table tbody tr { border-bottom: 1px solid var(--border); transition: background .15s; }
.books-table tbody tr:last-child { border-bottom: none; }
.books-table tbody tr:hover { background: rgba(56,51,42,.04); }
.books-table td { padding: .8rem 1.375rem; vertical-align: middle; }
.col-title { font-weight: 500; min-width: 160px; }
.col-author { color: var(--text-mid); font-size: .825rem; min-width: 90px; }

.cat-tag {
  display: inline-block; padding: .18rem .7rem; border-radius: 50px;
  background: rgba(176,106,71,.1); color: var(--accent);
  font-size: .72rem; font-weight: 500;
  border: 1px solid rgba(176,106,71,.2); white-space: nowrap;
}

.status-badge {
  display: inline-block; padding: .18rem .7rem; border-radius: 50px;
  font-size: .72rem; font-weight: 500; white-space: nowrap;
}
.status-ok { background: #e4f0e8; color: #1e5a30; border: 1px solid #9ecaaa; }
.status-restricted { background: #fdf0e2; color: #7a4020; border: 1px solid #ddb888; }

.books-cards {
  display: none; grid-template-columns: 1fr; gap: .875rem;
  margin-bottom: 1.5rem; max-height: 640px; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.books-section.is-loaded .books-cards { display: grid; }

.book-card {
  background: var(--base); border: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
}
.book-card-title { font-size: .95rem; font-weight: 500; margin-bottom: .3rem; line-height: 1.55; }
.book-card-author { font-size: .82rem; color: var(--text-weak); margin-bottom: .875rem; }
.book-card-footer { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

.books-donate {
  background: var(--base); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 1rem 1.5rem; font-size: .85rem;
  color: var(--text-mid); line-height: 1.9; margin-top: 2rem;
}
.books-donate strong { color: var(--accent); }


/* ============ EVENTS ============ */
.events-section { border-top: 1px solid var(--border); }

.events-section h2 {
  font-size: 36px; font-weight: 500; line-height: 1.5; margin-bottom: 56px;
}

.events-note {
  font-size: 13px; color: var(--text-weak); margin-bottom: 20px;
}
.events-note a {
  color: var(--text-weak); border-bottom: 1px solid rgba(111,103,87,.4);
  padding-bottom: 1px; transition: opacity .2s;
}
.events-note a:hover { opacity: .6; }

.event-photo {
  width: 100%; aspect-ratio: 1/1;
  object-fit: cover; display: block;
}

.events-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  column-gap: 14px; row-gap: 0;
}

.event-cell {
  background: var(--base); padding: 32px 24px;
  aspect-ratio: 1/1; display: flex; flex-direction: column; justify-content: center;
  border: 1px solid var(--border); border-bottom: none;
}
.event-cell h3 { font-size: 17px; font-weight: 500; margin-bottom: 14px; }
.event-cell p { font-size: 13px; line-height: 1.9; color: var(--text-weak); }


/* ============ ACCESS ============ */
.access-section { background: var(--dark); color: var(--base); }

.access-section .section-inner {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 64px; align-items: center;
}

.access-section h2 {
  font-size: 36px; font-weight: 500; line-height: 1.5; margin-bottom: 40px;
}

.access-info {
  display: flex; flex-direction: column; gap: 24px;
  font-size: 15px; line-height: 1.9;
}

.info-label {
  display: block; color: var(--accent-lt);
  font-size: 12px; letter-spacing: .1em; margin-bottom: 4px;
}

.access-instagram {
  display: inline-block; margin-top: 10px;
  font-size: 13px; color: var(--accent-lt);
  letter-spacing: .05em; border-bottom: 1px solid rgba(201,138,100,.4);
  padding-bottom: 2px; transition: opacity .2s;
}
.access-instagram:hover { opacity: .7; }

.access-photos { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.access-photos img { width: 100%; height: 300px; object-fit: cover; }


/* ============ FOOTER ============ */
.footer {
  background: var(--base); padding: 56px;
  text-align: center;
}

.footer img { height: 42px; width: auto; margin: 0 auto 18px; }
.footer > p { font-size: 14px; color: var(--text-mid); line-height: 2; }

.footer a {
  display: inline-block; margin-top: 18px;
  font-size: 13px; color: var(--accent); letter-spacing: .05em;
  transition: opacity .2s;
}
.footer a:hover { opacity: .7; }

.footer-copy { font-size: 11px; color: var(--text-weaker); margin-top: 28px !important; }


/* ============ LOADING ============ */
.loading-spinner {
  width: 28px; height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }


/* ============ RESPONSIVE ============ */
@media (max-width: 960px) {
  :root { --pad-x: 36px; }
  .spine-grid { grid-template-columns: repeat(4, 1fr); }
  .spine-card { height: 220px; }
  .about-features { grid-template-columns: 1fr 1fr; gap: 32px; }
  .events-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  :root { --pad-x: 24px; --pad-y: 56px; }

  .hamburger { display: flex; }

  .nav-links {
    position: fixed; top: var(--nav-h); right: -100%;
    width: 260px; height: calc(100vh - var(--nav-h));
    background: var(--base); border-left: 1px solid var(--border);
    flex-direction: column; gap: 0;
    padding: .5rem 0;
    transition: right .3s ease;
    z-index: 100;
  }
  .nav-links.active { right: 0; }
  .nav-links a {
    display: block; padding: 1rem 24px;
    font-size: 1rem; border-bottom: 1px solid var(--border);
  }

  .hero-inner {
    grid-template-columns: 1fr;
    gap: 40px; padding-top: 32px; padding-bottom: 56px;
  }
  .hero-photo { order: -1; }
  .hero-photo img { height: 300px; }
  .hero-caption { bottom: -12px; left: -12px; }
  .hero-text h1 { font-size: 36px; }

  .about h2 { font-size: 28px; }
  .about-features { grid-template-columns: 1fr; gap: 28px; }

  .books-header { flex-direction: column; align-items: flex-start; gap: 16px; }
  .books-header h2 { font-size: 28px; }
  .spine-grid { grid-template-columns: repeat(3, 1fr); }
  .spine-card { height: 200px; }

  .events-section h2 { font-size: 28px; }

  .access-section .section-inner { grid-template-columns: 1fr; gap: 40px; }
  .access-section h2 { font-size: 28px; }

  .footer { padding: 40px 24px; }

  .books-section.is-loaded .books-table-wrap { display: none !important; }
  .books-section.is-loaded .books-cards { display: grid !important; }
}

@media (min-width: 769px) {
  .books-section.is-loaded .books-cards { display: none !important; }
}

@media (max-width: 480px) {
  .hero-text h1 { font-size: 30px; }
  .hero-btns { flex-direction: column; }
  .btn-primary, .btn-secondary { text-align: center; }
  .spine-grid { grid-template-columns: repeat(2, 1fr); }
  .spine-card { height: 180px; }
  .events-grid { grid-template-columns: 1fr; margin-inline: 12px; row-gap: 12px; }
  .event-cell { aspect-ratio: 1/1; height: auto; border-bottom: 1px solid var(--border); }
  .event-photo { aspect-ratio: 1/1; height: auto; }
  .access-photos { grid-template-columns: 1fr; margin-inline: 12px; gap: 12px; }
  .access-photos img { height: auto; aspect-ratio: 1/1; }
}
