:root {
  --font-base: 1.125rem;
  --font-large: 1.35rem;
  --font-title: clamp(1.5rem, 4vw, 2.25rem);
  --line: 1.7;
  --ink: #1f2328;
  --muted-ink: #4d5560;
  --rule: #d7d2c8;
  --paper: #fffdf8;
  --surface: #ffffff;
  --surface-soft: #f7f6f1;
  --accent: #23384f;
  --accent-soft: #e8edf2;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  font-size: var(--font-base);
  line-height: var(--line);
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
}

main {
  max-width: 75rem;
  margin: 0 auto;
  padding: 0.35rem 0.6rem 1.5rem;
  min-height: 100vh;
  box-sizing: border-box;
}

.layout {
  display: grid;
  grid-template-columns: minmax(13rem, 16rem) minmax(0, 1fr);
  gap: 0.5rem;
  align-items: start;
  min-height: calc(100vh - 0.7rem);
}

.content-area {
  min-width: 0;
}

.toc-mobile-toggle {
  display: none;
}

.toc-backdrop {
  display: none;
}

.toc-panel {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  max-height: 100vh;
  background: var(--surface);
  border: 1px solid var(--rule);
  box-shadow: none;
  padding: 0.35rem 0.45rem 0.45rem;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.toc-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.25rem;
  font-size: 0.78rem;
  flex-shrink: 0;
}

.toc-close {
  display: none;
  font-size: 0.72rem;
  padding: 0.25rem 0.45rem;
}

.toc-list {
  margin: 0.2rem 0 0;
  padding: 0;
  list-style: none;
}

.toc-list li + li {
  margin-top: 0.15rem;
}

.toc-item {
  margin-bottom: 0.45rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid #e8e8e8;
}

.toc-item:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.toc-section-hit {
  cursor: pointer;
  padding: 0.28rem 0.3rem;
  border-radius: 2px;
  outline: none;
}

.toc-section-hit:hover,
.toc-section-hit:focus-visible {
  background: var(--accent-soft);
}

.toc-meta-label {
  font-size: 0.58rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted-ink);
  margin: 0.2rem 0 0.08rem;
}

.toc-meta-label:first-child {
  margin-top: 0;
}

.toc-item-title {
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.3;
}

.toc-item-subtitle {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--muted-ink);
  line-height: 1.35;
}

.toc-item-body {
  font-size: 0.72rem;
  font-weight: 400;
  line-height: 1.38;
  color: var(--muted-ink);
}

.toc-item-body :first-child {
  margin-top: 0;
}

.toc-item-body :last-child {
  margin-bottom: 0;
}

.toc-files {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-top: 0.25rem;
}

.toc-file-link {
  display: block;
  width: 100%;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.22rem 0.3rem;
  line-height: 1.3;
  border: 1px solid #b8b2a8;
  border-radius: 2px;
  background: var(--surface-soft);
  cursor: pointer;
}

.toc-file-link:hover {
  background: var(--accent);
  color: #fff;
  border-style: solid;
  border-color: var(--accent);
}

.toc-file-muted {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.22rem 0.3rem;
  color: #888;
  line-height: 1.3;
}

.toc-link {
  display: block;
  width: 100%;
  text-align: left;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.32rem 0.45rem;
  border: 1px solid var(--accent);
  border-radius: 2px;
  background: var(--surface);
}

.toc-link.is-active {
  background: var(--accent);
  color: #fff;
}

.toc-section-hit.is-active {
  background: var(--accent);
  color: #fff;
}

.toc-section-hit.is-active .toc-meta-label {
  color: rgba(255, 255, 255, 0.72);
}

.toc-section-hit.is-active .toc-item-title,
.toc-section-hit.is-active .toc-item-subtitle {
  color: #fff;
}

.toc-section-hit.is-active .toc-item-body {
  color: rgba(255, 255, 255, 0.92);
}

.toc-section-hit.is-active:hover,
.toc-section-hit.is-active:focus-visible {
  background: var(--accent);
}

h1 {
  font-size: var(--font-title);
  font-weight: 700;
  margin: 0 0 1rem;
  letter-spacing: 0.02em;
  color: var(--accent);
}

h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 0.75rem;
}

.slide-subtitle {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted-ink);
  margin: 0 0 0.75rem;
  line-height: 1.45;
}

.attachment-block {
  scroll-margin-top: 0.75rem;
}

p {
  margin: 0 0 1rem;
}

strong,
b {
  font-weight: 700;
}

.landing-lead {
  max-width: 58rem;
  padding: 1rem 1.1rem 0.1rem;
  border: 1px solid var(--rule);
  border-left: 4px solid var(--accent);
  background: #fffefa;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.9;
}

.landing-lead p {
  margin-bottom: 0.95rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin: 1.5rem 0;
}

#slideshow .controls {
  margin: 0.65rem 0 0.5rem;
}

button {
  font: inherit;
  font-weight: 700;
  padding: 0.6rem 1.1rem;
  border: 1px solid var(--accent);
  background: var(--surface);
  cursor: pointer;
  border-radius: 2px;
}

button:hover {
  background: var(--accent);
  color: #fff;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.progress {
  font-weight: 700;
  font-size: 0.95rem;
}

.slide-panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  padding: 1.25rem 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: none;
}

.slide-body {
  font-size: var(--font-base);
}

.slide-body.large {
  font-size: var(--font-large);
}

.attachments {
  margin-top: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.attachments figure {
  margin: 0;
}

.attachments img {
  max-width: 100%;
  height: auto;
  border: 1px solid #ddd;
}

.attach-label {
  font-weight: 700;
  font-size: 0.82rem;
  margin-bottom: 0.25rem;
}

.attachment-block--pdf {
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin: 0 -1.2rem;
  width: calc(100% + 2.4rem);
  max-width: none;
}

.pdf-frame {
  display: block;
  width: 100%;
  min-height: 58vh;
  height: clamp(58vh, calc(100vh - 6.5rem), 92vh);
  border: none;
  background: #ddd;
}

.pdf-fallback {
  font-size: 0.75rem;
  font-weight: 600;
  color: #555;
  margin: 0.35rem 0 0;
}

.audio-row audio {
  width: 100%;
  max-width: 28rem;
}

/* 全画面ファイルビューア（横: ファイル切替 / 縦: 内容スクロール） */
html.viewer-lock,
body.viewer-lock {
  overflow: hidden;
}

.file-viewer-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: #1a1a1a;
  box-sizing: border-box;
}

.file-viewer-topbar {
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.4rem 3rem 0.4rem 0.75rem;
  background: #111;
  color: #fff;
  border-bottom: 1px solid #333;
}

.file-viewer-title {
  flex: 1;
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.35;
}

.file-viewer-index {
  font-size: 0.72rem;
  opacity: 0.9;
  white-space: nowrap;
  padding-top: 0.05rem;
}

.file-viewer-close {
  position: absolute;
  top: 0.2rem;
  right: 0.35rem;
  min-width: 2.25rem;
  min-height: 2.25rem;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  font-weight: 700;
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
}

.file-viewer-close:hover {
  background: rgba(255, 255, 255, 0.15);
}

.file-viewer-strip {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-color: #888 #2a2a2a;
}

.viewer-panel {
  flex: 0 0 100%;
  width: 100%;
  max-width: 100%;
  min-height: 0;
  height: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  overflow: hidden;
  box-sizing: border-box;
  background: #2a2a2a;
  display: flex;
  flex-direction: column;
}

.viewer-panel-inner {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0.35rem 0.65rem 0.75rem;
  box-sizing: border-box;
}

.viewer-pdf-pages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-color: rgba(255, 255, 255, 0.35) #2a2a2a;
}

.viewer-pdf-status {
  margin: 0.5rem 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: #cfcfcf;
}

.viewer-pdf-page-canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  margin: 0 auto 1rem auto;
  background: #fff;
  border-radius: 2px;
  box-sizing: border-box;
}

.viewer-attach-label {
  color: #eee;
  margin-bottom: 0.4rem;
}

.viewer-img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

.viewer-pdf-frame {
  display: block;
  width: 100%;
  min-height: 70dvh;
  height: calc(100dvh - 5.5rem);
  border: none;
  background: #3d3d3d;
}

.viewer-pdf-frame--fallback {
  flex-shrink: 0;
}

.viewer-pdf-fallback {
  font-size: 0.72rem;
  font-weight: 600;
  color: #ccc;
  margin: 0.45rem 0 0;
}

.viewer-pdf-fallback a {
  color: #9cecff;
}

.viewer-audio-row audio {
  width: 100%;
  max-width: 100%;
}

.file-viewer-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2001;
  font-size: 1.2rem;
  font-weight: 700;
  width: 2.5rem;
  height: 2.65rem;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1;
}

.file-viewer-nav:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.2);
}

.file-viewer-nav:disabled {
  opacity: 0.28;
  cursor: not-allowed;
}

.file-viewer-prev {
  left: 0.35rem;
}

.file-viewer-next {
  right: 0.35rem;
}

.file-viewer-hint {
  position: fixed;
  bottom: 0.35rem;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 0 0.5rem;
  font-size: 0.62rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.5);
  text-align: center;
  max-width: 92vw;
  pointer-events: none;
}

.attachment-teaser {
  border: 1px solid var(--rule);
  padding: 0.55rem 0.75rem;
  border-radius: 2px;
  background: var(--surface-soft);
}

.attachment-teaser-open {
  margin-top: 0.45rem;
  font: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--accent);
  background: var(--surface);
  cursor: pointer;
  border-radius: 2px;
}

.attachment-teaser-open:hover {
  background: var(--accent);
  color: #fff;
}

.attachment-teaser--private {
  background: #eeece5;
  border-style: dashed;
}

.attach-label--private {
  color: #888;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.font-tools {
  margin: 1rem 0 0;
  padding: 0.75rem 0 0;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.9rem;
  font-weight: 700;
}

.font-tools label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

footer {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted-ink);
}

/* パスワードゲート（gate-home.js / gate-admin.js） */
.gate-screen {
  max-width: 22rem;
  margin: 3rem auto;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  box-shadow: none;
}

.gate-screen .gate-title {
  font-weight: 700;
  font-size: 1.05rem;
  margin: 0 0 1rem;
}

.gate-screen input[type="password"] {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.5rem;
  margin-bottom: 0.75rem;
  border: 1px solid var(--accent);
}

.gate-screen button {
  font: inherit;
  font-weight: 700;
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.gate-screen button:hover {
  background: var(--surface);
  color: var(--accent);
}

.gate-error {
  color: #a00;
  font-weight: 700;
  font-size: 0.9rem;
  margin: 0.5rem 0 0;
}

@media (max-width: 1023px) {
  body.toc-lock {
    overflow: hidden;
  }

  .layout {
    display: block;
  }

  .toc-mobile-toggle {
    display: inline-block;
    margin: 0 0 0.75rem;
  }

  .toc-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 20;
  }

  .toc-backdrop.open {
    display: block;
  }

  .toc-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: min(84vw, 19rem);
    height: 100vh;
    max-height: 100vh;
    border-right: 1px solid #aaa;
    border-top: none;
    border-left: none;
    border-bottom: none;
    z-index: 30;
    transform: translateX(-105%);
    transition: transform 0.2s ease-out;
    box-shadow: 6px 0 18px rgba(0, 0, 0, 0.2);
  }

  .toc-panel.open {
    transform: translateX(0);
  }

  .toc-close {
    display: inline-block;
  }
}
