/* 和柄UI（§8）
   ダーク一択。ビューファインダーが黒である以上、明るい面は撮影中に眩しい。 */

:root {
  /* 和色パレット（§8.2） */
  --sumi:      #14161C;  /* 墨 — 背景 */
  --konnezu:   #1C2029;  /* 濃紺鼠 — 面 */
  --ainezu:    #2A3140;  /* 藍鼠 — 罫線 */
  --kinari:    #F3EFE6;  /* 生成り — 主文字 */
  --shironezu: #9AA0AC;  /* 白鼠 — 副文字 */
  --shu:       #D9433F;  /* 朱 — 差し色。面と図形にのみ使う */
  --wakatake:  #6FA88B;  /* 若竹 — 成功 */
  --yamabuki:  #D9A62E;  /* 山吹 — 注意 */
  --kincha:    #B8893B;  /* 金茶 — 装飾線 */

  --font-display: "Hiragino Mincho ProN", "Yu Mincho", YuMincho, "Noto Serif JP", serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;

  --gap: 12px;
  --pad: 16px;
  --radius: 2px;  /* 和の意匠は直線と円が基調。強い角丸は洋風に寄る（§8.6） */
}

* { box-sizing: border-box; }

/* display を持つセレクタに負けないよう、hidden は最優先で効かせる */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--sumi);
  color: var(--kinari);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  overscroll-behavior: none;          /* 引っ張って更新されない（§7.6） */
  touch-action: manipulation;         /* ダブルタップでズームしない */
  -webkit-text-size-adjust: 100%;
}

button, .icon { font-family: inherit; }

/* ------------------------------------------------------------- レイアウト */

body.shoot {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100dvh;                     /* 100vh ではなく dvh（§7.6） */
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: var(--pad);
  background-color: var(--konnezu);
  background-repeat: repeat;
  position: relative;
}

/* 文様は「地」として敷く。不透明度 4〜8%（§8.1, §8.3） */
.bar::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: var(--pattern-asanoha);
  opacity: 0.06;
}

.bar--top { border-bottom: 1px solid var(--kincha); }

/* ライトが使えない端末ではボタンごと消える。3列固定にして撮影ボタンの中心を保つ。 */
.bar--bottom {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  justify-items: center;
  border-top: 1px solid var(--kincha);
  padding-bottom: calc(var(--pad) + env(safe-area-inset-bottom));
}
.bar--bottom::before {
  background-image: var(--pattern-seigaiha);
  opacity: 0.05;
}

.bar > * { position: relative; z-index: 1; }

.bar--bottom > .shutter { grid-column: 2; }
.bar--bottom > #btnTorch { grid-column: 3; }

/* --------------------------------------------------------------- 現場名 */

.site {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-family: var(--font-display);   /* 明朝体は見出しだけ（§8.1） */
  font-size: 17px;
  font-weight: 400;
  letter-spacing: 0.12em;
}

/* 朱の細い縦罫。縦書きは使わず、罫だけで縦の意識を作る（§8.4） */
.site__rule {
  width: 2px;
  height: 1.2em;
  background: var(--shu);
  flex: none;
}

.bar__actions { display: flex; gap: 8px; }

.icon {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  border: 1px solid var(--ainezu);
  border-radius: var(--radius);
  background: transparent;
  color: var(--kinari);
  font-size: 13px;
  text-decoration: none;
  -webkit-touch-callout: none;
  user-select: none;
}
.icon[aria-pressed="true"] { background: var(--shu); border-color: var(--shu); }

/* ---------------------------------------------------- ビューファインダー */

.stage {
  position: relative;
  background: #000;
  overflow: hidden;
}

.viewfinder {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* 障子越しの光。白の点滅ではなく生成り色をフェードさせる（§8.5） */
.shoji {
  position: absolute;
  inset: 0;
  background: var(--kinari);
  opacity: 0;
  pointer-events: none;
}
.shoji.is-lit { animation: shoji 180ms ease-out; }
@keyframes shoji {
  from { opacity: 0.55; }
  to   { opacity: 0; }
}

/* 通知もオーバーレイの積み重ねに入れる（キューと位置が重ならないように） */
.notice {
  margin: 0 var(--pad) 8px;
  padding: 10px 12px;
  border-left: 2px solid var(--yamabuki);
  background: rgba(20, 22, 28, 0.88);
  backdrop-filter: blur(6px);
  font-size: 13px;
}
.notice[data-kind="warn"] { border-left-color: var(--yamabuki); }

.fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: var(--gap);
  padding: 24px;
  text-align: center;
  color: var(--shironezu);
}

/* --------------------------------------------------------------- 撮影ボタン */

/* 日の丸／判子。押下で沈み、離すと朱の波紋が一度だけ広がる（§8.5） */
.shutter {
  position: relative;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: none;
  background: var(--kinari);
  transition: transform 120ms ease-out;
  -webkit-touch-callout: none;
  user-select: none;
}
.shutter.is-pressed { transform: scale(0.92); }

.shutter__ring {
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  border: 2px solid var(--shu);
}

.shutter__ripple {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--shu);
  opacity: 0;
}
.shutter.is-pressed .shutter__ripple,
.shutter:active .shutter__ripple { animation: ripple 300ms ease-out; }
@keyframes ripple {
  from { transform: scale(1);   opacity: 0.8; }
  to   { transform: scale(1.6); opacity: 0; }
}

/* ------------------------------------------------------------------ キュー */

/* 送信キューは映像の上に重ねる。行を占有しないのでビューファインダーが縮まない。 */
.overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  gap: 1px;
  pointer-events: none;              /* 隙間は映像側のタップを通す */
}
.overlay > * { pointer-events: auto; }

.queue {
  display: grid;
  gap: 1px;
  max-height: 34dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.queue:empty { display: none; }

.card {
  position: relative;
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: var(--gap);
  padding: 10px var(--pad);
  background-color: rgba(28, 32, 41, 0.86);
  border-top: 1px solid var(--ainezu);
  backdrop-filter: blur(6px);
  animation: rise 220ms ease-out;     /* 下から 8px。バウンスさせない（§8.5） */
}
.card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: var(--pattern-washi);
  opacity: 0.03;
}
.card > * { position: relative; z-index: 1; }

@keyframes rise {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.card__thumb {
  width: 56px;
  height: 56px;
  border-radius: var(--radius);
  overflow: hidden;
}
.card__thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.card__body { min-width: 0; }

.card__status {
  margin: 0;
  font-size: 13px;
  font-variant-numeric: tabular-nums; /* 数字を揺らさない（§8.4） */
}
.card[data-state="error"] .card__status { color: var(--yamabuki); }

.meter {
  height: 2px;
  margin-top: 6px;
  background: var(--ainezu);
}
.meter span {
  display: block;
  height: 100%;
  background: var(--shu);
  transition: width 200ms ease-out;
}

/* 完了後は進捗の朱線を残さない（差し色は「今」を示すためだけに使う） */
.card[data-state="done"] .meter,
.card[data-state="error"] .meter { display: none; }

.card__badges { display: flex; gap: 6px; margin: 6px 0 0; }

.badge {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid currentColor;
  border-radius: var(--radius);
  font-size: 11px;
  animation: stamp 200ms ease-out;    /* 朱の丸印がスタンプされる（§8.5） */
}
.badge--ok { color: var(--wakatake); }
.badge--muted { color: var(--shironezu); }

@keyframes stamp {
  from { transform: scale(1.25); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

/* ------------------------------------------------------------ まとめて保存 */

.bulkbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 10px var(--pad);
  background: rgba(20, 22, 28, 0.9);
  border-top: 1px solid var(--kincha);
  backdrop-filter: blur(6px);
  font-size: 13px;
}

.btn {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--ainezu);
  border-radius: var(--radius);
  background: var(--shu);            /* 朱は面にのみ使う（§8.6） */
  color: var(--kinari);
  font-size: 14px;
}
.btn--ghost { background: transparent; border-color: var(--kincha); }

/* --------------------------------------------------------------- 設定シート */

.sheet {
  width: min(420px, 92vw);
  border: 1px solid var(--kincha);
  border-radius: var(--radius);
  background: var(--konnezu);
  color: var(--kinari);
  padding: 20px;
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.6); }
.sheet h2 {
  margin: 0 0 var(--pad);
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.12em;
  font-size: 18px;
}

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px var(--gap); margin: 0 0 var(--pad); font-size: 13px; }
.kv dt { color: var(--shironezu); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.switch { display: flex; gap: 10px; align-items: center; font-size: 14px; }
.hint { color: var(--shironezu); font-size: 12px; margin: 6px 0 var(--pad); }

/* ------------------------------------------------------------- ギャラリー */

body.gallery { display: block; min-height: 100dvh; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 2px;
  padding: 2px;
}

.tile {
  position: relative;
  display: block;
  border: none;
  padding: 0;
  background: var(--ainezu);
  aspect-ratio: var(--ar, 4 / 3);
  content-visibility: auto;           /* 画面外の描画をスキップ（§9） */
  contain-intrinsic-size: 0 180px;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }

.sentinel { height: 1px; }

.lightbox {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  background: rgba(20, 22, 28, 0.97);
  z-index: 10;
}
.lightbox[hidden] { display: none; }
.lightbox img { width: 100%; height: 100%; object-fit: contain; min-height: 0; }
.lightbox__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: var(--pad);
  padding-bottom: calc(var(--pad) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--kincha);
  font-size: 13px;
}

.empty { padding: 48px var(--pad); text-align: center; color: var(--shironezu); }

/* ------------------------------------------------------- モーションの停止 */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0ms !important;
  }
}

/* --------------------------------------------------------------- 合言葉 */

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

body.login { display: grid; place-items: center; min-height: 100dvh; }

.gate {
  width: min(420px, 90vw);
  padding: 28px var(--pad);
  background-color: var(--konnezu);
  border: 1px solid var(--kincha);
  border-radius: var(--radius);
  position: relative;
}
.gate::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: var(--pattern-asanoha);
  opacity: 0.06;
}
.gate > * { position: relative; z-index: 1; }

.gate__title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 20px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 19px;
  letter-spacing: 0.12em;
}

.gate__form { display: grid; gap: var(--gap); }
.gate__question { margin: 0; font-size: 15px; line-height: 1.8; }

.gate__field input {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  background: var(--sumi);
  border: 1px solid var(--ainezu);
  border-radius: var(--radius);
  color: var(--kinari);
  font-family: inherit;
  font-size: 17px;   /* iOS で自動ズームさせない下限 */
}
.gate__field input:focus-visible { outline: 2px solid var(--kincha); outline-offset: 1px; }

.gate__error { margin: 0; color: var(--yamabuki); font-size: 13px; }
.gate__note { margin: 20px 0 0; color: var(--shironezu); font-size: 12px; }
.gate__note a { color: var(--kinari); }

/* ---------------------------------------------------------- スライドショー */

body.slideshow {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100dvh;
  background: #000;
  overflow: hidden;
}

.stagelight { position: relative; overflow: hidden; }

.slide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  /* 障子越しの光のように、跳ねずに溶けて入れ替わる（§8.5） */
  transition: opacity 700ms ease-out;
}
.slide.is-front { opacity: 1; }

.stagelight__empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  margin: 0;
  color: var(--shironezu);
  font-size: 14px;
}

.controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--gap);
  padding: 10px var(--pad);
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background-color: var(--konnezu);
  border-top: 1px solid var(--kincha);
  position: relative;
  transition: opacity 220ms ease-out;
}
.controls::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: var(--pattern-seigaiha);
  opacity: 0.05;
}
.controls > * { position: relative; z-index: 1; }

.controls__left, .controls__center, .controls__right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.controls__right { justify-content: flex-end; }

.icon--wide { min-width: 72px; }

.counter {
  color: var(--shironezu);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.interval select {
  min-height: 44px;
  padding: 0 8px;
  background: transparent;
  color: var(--kinari);
  border: 1px solid var(--ainezu);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13px;
}

/* 画面をタップすると操作バーを隠して写真だけにする */
body.is-bare .controls { opacity: 0; pointer-events: none; }

/* 狭い画面では操作バーを1列に畳む。iPhone の 390px でも見切れないようにする。 */
@media (max-width: 560px) {
  .controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    padding-left: 8px;
    padding-right: 8px;
  }
  .controls__left, .controls__center, .controls__right { gap: 6px; }

  .controls .icon {
    min-width: 40px;
    padding: 0 8px;
    font-size: 12px;
    white-space: nowrap;   /* 「一覧」「全画面」を折り返さない */
  }
  .icon--wide { min-width: 60px; }

  /* 枚数はバーの上に薄く重ねる。操作の邪魔をしない。 */
  .controls__left { order: -1; width: 100%; justify-content: center; }
  .counter { font-size: 11px; }

  .interval select { min-height: 40px; font-size: 12px; }
}
