/*
 * フレーム廃止用 共通レイアウト
 *   旧: <frameset cols="200,*"> 左=topmenu/menu.html / 右=各ページ
 *   新: 左200pxを固定メニュー (#site-menu, js/layout.js が挿入) にし、本文を右にずらす
 */
:root {
  --menu-w: 200px;
  --menu-bg: #e7ebd8;
}

/* 本文をメニュー幅だけ右へ（body の余白は各ページの指定のまま残す） */
html {
  padding-left: var(--menu-w);
}

/* <body background="..."> の模様の開始位置を旧フレーム時（左端=メニューの右）に合わせる */
body[background] {
  background-position: var(--menu-w) 0;
}

/* JS がメニューを挿入するまでの間もメニュー欄の背景だけ先に表示しておく */
html::before {
  content: "";
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--menu-w);
  background: var(--menu-bg);
  z-index: 9998;
}

/* ---------- 左メニュー ---------- */
/* 各ページ固有の CSS (黒背景ページ等) の影響を受けないよう、主要な値を明示しておく */
#site-menu {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--menu-w);
  height: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 8px;               /* 旧メニュー body の既定余白 */
  overflow-x: hidden;
  overflow-y: auto;           /* 画面が低い時だけスクロール（旧は scrolling="no"） */
  scrollbar-width: none;
  background: var(--menu-bg);
  color: #000022;
  font-family: initial;       /* 旧メニュー同様ブラウザ既定のフォント */
  font-size: 16px;
  font-weight: normal;
  font-style: normal;
  line-height: 1.5;
  letter-spacing: normal;
  text-align: center;
  z-index: 9999;
}
#site-menu::-webkit-scrollbar {
  display: none;
}
#site-menu * {
  box-sizing: content-box;
  font-family: inherit;
  line-height: inherit;
  letter-spacing: inherit;
  float: none;
}
#site-menu .sm-inner {
  position: relative;
  font-size: 14px;
}
#site-menu div {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  width: auto;
}
#site-menu p {
  margin: 1em 0;
  padding: 0;
}
#site-menu b {
  font-weight: bold;
}
#site-menu a,
#site-menu a:visited,
#site-menu a:hover {
  color: #000022;
  background: none;
  text-decoration: underline;
}
/* E-Mail ボタン（css/style.css の a[href*="mailto"] と同じ見た目） */
#site-menu a.sm-mail,
#site-menu a.sm-mail:visited {
  display: inline-block;
  border: ridge 2px #4a7749;
  border-radius: 5px;
  padding: 3px 0;
  width: 100px;
  background: #175416;
  color: #fff;
  font-size: 14px;
  font-family: serif;
  text-align: center;
}
#site-menu a.sm-mail:hover {
  border: ridge 2px #175416;
  background: #4a7749;
  color: #fff;
}
#site-menu img {
  display: inline;
  vertical-align: baseline;
  max-width: none;
  margin: 0;
  padding: 0;
  border: 0;
}
#site-menu .sm-note {
  margin-top: 8px;
  font-size: 12px;
}
#site-menu .sm-item {
  margin-top: 8px;
}

/* 舞い落ちる花びら */
#site-menu .sm-petal {
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(15px, 15px);
  pointer-events: none;
  will-change: transform;
}

/* ---------- レイアウトテーブル（tools/tables.py が <table> から変換したもの） ---------- */
/* ブラウザ既定の table / td の表示を再現する。
   :where() で優先度を 0 にして、各ページの CSS が必ず勝つようにする（ブラウザ既定のスタイルと同じ扱い） */
:where(.lt) {
  display: grid;
  box-sizing: border-box;
  width: fit-content;
  min-width: min-content;
  text-indent: 0;
  text-align: start;   /* align属性由来の中央寄せは table に引き継がれない */
  border: 0 outset gray;
}
:where(.lt.ti) {
  text-align: inherit; /* CSS の text-align は引き継がれる */
}
:where(.lt > .c) {
  box-sizing: content-box;
  padding: var(--p, 0);
}
:where(.lt.bd > .c) {
  border: 1px inset gray;
}
/* 互換モード (DOCTYPE なし) のページでは table が文字サイズ等を継承しない */
:where(.lt.q) {
  white-space: normal;
  line-height: normal;
  font-weight: normal;
  font-size: medium;
  font-variant: normal;
  font-style: normal;
  text-align: start;
}
/* 互換モードでセルの先頭・末尾の要素の既定マージンが無視される挙動（tables.py が qt / qb を付ける） */
:where(.lt.q > .c .qt) { margin-top: 0; }
:where(.lt.q > .c .qb) { margin-bottom: 0; }
/* align 属性（ブロック要素も中央寄せになるブラウザ独自値を併記） */
:where(.lt > .ac) { text-align: center; text-align: -moz-center; text-align: -webkit-center; }
:where(.lt > .ar) { text-align: right; text-align: -moz-right; text-align: -webkit-right; }
:where(.lt > .al) { text-align: left; text-align: -moz-left; text-align: -webkit-left; }
/* valign 属性（td の既定は中央） */
:where(.lt > .vm), :where(.lt > .vb) { display: flex; flex-direction: column; justify-content: center; }
:where(.lt > .vb) { justify-content: flex-end; }
:where(.lt > .nw) { white-space: nowrap; }

/* ---------- ページの先頭に戻るボタン（layout.js が挿入。少しスクロールすると表示） ---------- */
#to-top {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9997;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 2px solid #4a7749;
  border-radius: 50%;
  background: #175416;
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .3);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s, visibility .2s, background-color .2s;
}
#to-top.show {
  opacity: .85;
  visibility: visible;
  transform: none;
}
#to-top:hover,
#to-top:focus-visible {
  opacity: 1;
  background: #4a7749;
}
#to-top:focus-visible {
  outline: 2px solid #000022;
  outline-offset: 2px;
}
@media print {
  #to-top { display: none; }
}

/* ---------- スマートフォン（幅 767px 以下） ---------- */
/* パソコンでの見た目は変えない。ここから下は狭い画面だけに効く */
#site-bar,
#site-overlay {
  display: none;
}

/* 過去の記録（history*.html）: 各年へ移動するプルダウン（tools/history.py が各年のリンク一覧の代わりに入れる） */
.yr-select {
  margin: 10px auto 14px;
  text-align: center;
}
.yr-select:empty {
  display: none;   /* スクリプトがプルダウンを入れるまで（入らなければ）場所を取らない */
}
.yr-select select {
  min-width: 240px;
  max-width: 100%;
  padding: 6px 10px;
  font-size: 15px;
  border: 1px solid #b9a98f;
  border-radius: 6px;
  background: #fff;
  color: #000022;
  cursor: pointer;
}
@media (max-width: 767px) {
  :root {
    --bar-h: 48px;
  }
  html {
    padding-left: 0;
    padding-top: var(--bar-h);
  }
  body[background] {
    background-position: 0 0;
  }
  /* JS がバーを挿入するまでの間もバーの背景を先に表示 */
  html::before {
    right: 0;
    bottom: auto;
    width: auto;
    height: var(--bar-h);
  }

  /* 上部バー（ロゴとメニューボタン） */
  #site-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--bar-h);
    box-sizing: border-box;
    padding: 0 12px;
    background: var(--menu-bg);
    border-bottom: 1px solid #c9cfb4;
    z-index: 10000;
  }
  #site-bar a,
  #site-bar img {
    display: block;
    border: 0;
  }
  #site-menu-btn {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 40px;
    height: 40px;
    margin: 0;
    padding: 8px;
    box-sizing: border-box;
    border: 0;
    border-radius: 4px;
    background: none;
    cursor: pointer;
  }
  #site-menu-btn span {
    display: block;
    height: 3px;
    border-radius: 2px;
    background: #000022;
    transition: transform .2s, opacity .2s;
  }
  html.sm-open #site-menu-btn span:nth-child(1) { transform: translateY(8px) rotate(45deg); }
  html.sm-open #site-menu-btn span:nth-child(2) { opacity: 0; }
  html.sm-open #site-menu-btn span:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }

  /* 左メニューは左から出てくるパネルにする */
  #site-menu {
    top: var(--bar-h);
    height: calc(100% - var(--bar-h));
    width: min(280px, 85vw);
    transform: translateX(-105%);
    transition: transform .25s ease;
    box-shadow: 2px 0 8px rgba(0, 0, 0, .25);
  }
  html.sm-open #site-menu {
    transform: none;
  }
  #site-overlay {
    position: fixed;
    inset: var(--bar-h) 0 0 0;
    background: rgba(0, 0, 0, .35);
    z-index: 9998;
  }
  html.sm-open #site-overlay {
    display: block;
  }
  #to-top {
    right: 14px;
    bottom: 14px;
  }

  /* 本文: 画面幅に収める */
  body {
    min-width: 0 !important;
    padding-left: 8px;
    padding-right: 8px;
  }
  /* 横にはみ出さないように（行末の全角スペースなどで画面が広がるのを防ぐ最後の安全策） */
  html,
  body {
    overflow-x: clip;
  }
  /* ページの CSS で左右に余白を付けた写真（toyfair レポートの .photo）は、余白を外して画面幅に収める */
  img.photo {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  body * {
    max-width: 100%;
  }
  /* スライダー（bxSlider）のスライドを並べる帯は画面より広い必要がある（縮めると縦に積まれて動かない） */
  .bx-viewport > * {
    max-width: none;
  }
  img, video, iframe, embed, object {
    height: auto;
  }
  /* レイアウト用の div（旧テーブル）は、セルを横に並べられるだけ並べて折り返す
     （小さい画像は横並びのまま、長い文章や大きい画像は 1 行に 1 つ） */
  .lt {
    display: flex !important;
    flex-wrap: wrap;
    justify-content: center;
    width: auto !important;
    min-width: 0 !important;
    box-sizing: border-box;
  }
  .lt > .c {
    display: block !important;
    flex: 1 1 auto;
    width: auto !important;
    min-width: 0;
    box-sizing: border-box;
  }
  /* 1 列だけの表は、元どおりセルごとに改行する */
  .lt:not([style*="grid-template-columns"]) > .c {
    flex-basis: 100%;
  }
  /* div に変換しなかったレイアウト用の表（class="ltk"）も、行ごとにセルを並べて折り返す */
  table.ltk,
  table.ltk > tbody,
  table.ltk > thead,
  table.ltk > tfoot {
    display: block;
    width: auto !important;
    height: auto !important;
  }
  table.ltk > * > tr {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    height: auto !important;
  }
  table.ltk > * > tr > td {
    display: block;
    flex: 1 1 auto;
    width: auto !important;
    height: auto !important;
    min-width: 0;
    box-sizing: border-box;
  }
  table.ltk > * > tr > td:only-child {
    flex-basis: 100%;
  }
  /* 残したテーブル（一覧表など）も画面幅に縮める */
  table {
    width: auto !important;
    max-width: 100%;
  }
  td[width], th[width] {
    width: auto;
  }
  /* style.css などの固定幅（600px など）も画面幅まで縮める */
  .wrapper, .event, #footer-navi, #footer-navi2 {
    width: auto !important;
  }
  .yr-select select {
    width: 100%;
    max-width: 320px;
    padding: 8px 10px;
    font-size: 16px;
  }
  /* 催事ページの写真と説明文（パソコンでは左右に並ぶ）は、縦に並べて中央に置く */
  .event .img,
  .event .txt {
    float: none !important;
    width: auto !important;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
  }
}

@media print {
  html { padding-left: 0; }
  html::before, #site-menu { display: none; }
}
