:root {
  --bg: #0e1013;
  --panel: #171a1f;
  --line: #2a2f37;
  --text: #f2f4f7;
  --muted: #9aa4b2;
  --accent: #4da3ff;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }

header.bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(14, 16, 19, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

header.bar .title {
  font-size: 17px;
  font-weight: 700;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

header.bar .who { color: var(--muted); font-size: 13px; }

main { padding: 16px; max-width: 1100px; margin: 0 auto; }

button {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
}
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 700; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button:disabled { opacity: 0.5; cursor: default; }

input, textarea {
  font: inherit;
  width: 100%;
  color: var(--text);
  background: #0b0d10;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

label { display: block; margin: 12px 0 6px; font-size: 13px; color: var(--muted); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}

.msg { margin: 12px 0; padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.msg.error { background: rgba(255, 107, 107, 0.12); color: #ffb4b4; }
.msg.ok { background: rgba(77, 163, 255, 0.12); color: #b6d9ff; }

/* ログイン画面 */
.auth-wrap { max-width: 420px; margin: 8vh auto; padding: 0 16px; }
.auth-wrap h1 { font-size: 22px; margin: 0 0 4px; }
.auth-wrap p.lead { color: var(--muted); font-size: 14px; margin: 0 0 20px; line-height: 1.6; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tabs button { flex: 1; }
.tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 700; }
.auth-wrap form button[type="submit"] { width: 100%; margin-top: 18px; padding: 13px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.5; }

/* アルバム一覧 */
.albums { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.album-card {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.album-card .cover { aspect-ratio: 3 / 2; background: #0b0d10 center/cover no-repeat; display: grid; place-items: center; color: var(--muted); font-size: 28px; }
.album-card .body { padding: 12px 14px 14px; }
.album-card .name { font-weight: 700; margin-bottom: 4px; }
.album-card .meta { font-size: 12px; color: var(--muted); }

.section-head { display: flex; align-items: center; gap: 10px; margin: 4px 0 14px; }
.section-head h2 { font-size: 15px; margin: 0; flex: 1; color: var(--muted); font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; line-height: 1.8; }

/* 写真グリッド */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; } }
.tile { position: relative; aspect-ratio: 1; border: 0; padding: 0; border-radius: 8px; overflow: hidden; background: #0b0d10; cursor: pointer; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.pending { display: grid; place-items: center; color: var(--muted); font-size: 12px; }

.uploading { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 40;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 10px 18px; font-size: 14px; }

/* ライトボックス。
   画面の縦横比がどうであれ「写真の全体が入る」ことを最優先にしている。
   dvh を使うのは、スマホのアドレスバーが伸縮すると 100vh が実際の表示領域より大きくなり、
   下の帯がはみ出して写真の下が切れるため（dvh 非対応の端末のために inset:0 も残す） */
.lightbox { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column;
  height: 100dvh; max-height: 100dvh; overflow: hidden; }
/* display 指定はブラウザ既定の [hidden]{display:none} より強いので、明示的に打ち消す（閉じられなくなる） */
.lightbox[hidden] { display: none; }
/* min-height:0 が要（flexの既定 min-height:auto だと、縦長の写真が縮まずに下の帯を画面外へ押し出す） */
/* grid のトラックを minmax(0,1fr) で「はっきりした高さ」にしておくのが要。
   auto のままだと写真側の max-height:100% が解決されず（基準が不定）、縦長写真が画面をはみ出す */
.lightbox .stage { flex: 1 1 auto; min-height: 0; min-width: 0;
  display: grid; grid-template-rows: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr);
  place-items: center; overflow: hidden; padding: 4px; }
.lightbox .stage img { max-width: 100%; max-height: 100%; width: auto; height: auto;
  object-fit: contain; position: relative; z-index: 1; }
.lightbox .lb-bar { flex: none; display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  background: #0b0d10; border-bottom: 1px solid var(--line); padding-top: calc(10px + env(safe-area-inset-top)); }
.lightbox .lb-bar .info { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 説明やタグが多い写真でも、足元が伸びて写真を圧迫しないように上限を決めてスクロールさせる */
.lightbox .lb-foot { flex: none; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  max-height: 30dvh; overflow-y: auto; padding: 10px 12px; background: #0b0d10; border-top: 1px solid var(--line);
  padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
.lightbox .lb-foot .caption { flex: 1 1 100%; min-width: 0; font-size: 14px; }
/* QRを開いている間は足元を広げる（そのままだと画面外に出て気づけない） */
.lightbox .lb-foot.expanded { max-height: 72dvh; }
/* 横向きのスマホなど、縦が短い画面では帯を薄くして写真に高さを回す */
@media (max-height: 520px) {
  .lightbox .lb-bar, .lightbox .lb-foot { padding-top: 4px; padding-bottom: 4px; gap: 6px; }
  .lightbox .lb-foot { max-height: 34dvh; }
  .lightbox .lb-foot .caption { font-size: 12px; }
  .lightbox .lb-bar .info { font-size: 12px; }
  .nav-btn { padding: 4px 14px; }
}
/* 前後の移動。写真に重ねると隠れて押せない端末があったため上部バーに置いている（実機テストで検出） */
.nav-btn { font-size: 22px; line-height: 1; padding: 8px 16px; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
/* display 指定はブラウザ既定の [hidden]{display:none} より強い。
   打ち消しておかないと hidden を付けても消えない（ライトボックスで同じ穴を踏んでいる） */
.row[hidden] { display: none; }
.spacer { flex: 1; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.08em; }

/* 絞り込みチップ（横スクロール） */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip { white-space: nowrap; border-radius: 999px; padding: 7px 14px; font-size: 14px; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 700; }

/* 参加者一覧 */
/* 参加者の行。ボタンが2つ並ぶと狭い画面では名前が1文字ずつに潰れるので、入らなければ折り返す */
.user-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line);
  font-size: 14px; flex-wrap: wrap; }
.user-row:first-of-type { border-top: 0; }
.user-row .who-name { flex: 1 1 200px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.user-row .row { margin-left: auto; }

/* 動画のタイル */
.tile-badge { position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,0.62); border-radius: 999px;
  font-size: 11px; line-height: 1; padding: 5px 8px; pointer-events: none; }
.tile-fallback { position: absolute; inset: 0; display: grid; place-items: center; font-size: 26px; color: var(--muted); }
.lightbox .stage video { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; }

/* 投稿者のあとから修正（管理者のみ）。付け替える前に必ず見せる一覧 */
.recredit-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px;
  max-height: 320px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.recredit-row { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); margin: 0; }
.recredit-row img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; background: #0b0d10; flex: none; }
.recredit-row span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 共有シートの押す場所の案内（写真アプリに保存できる端末でのみ出す） */
.lightbox .lb-foot .share-hint { flex: 1 1 100%; font-size: 12px; color: var(--muted); line-height: 1.5; }

/* 公開リンクの画面（ログイン不要で写真1枚だけを見せる） */
.share-page { position: fixed; inset: 0; height: 100dvh; display: flex; flex-direction: column; background: #000; }
.share-stage { flex: 1 1 auto; min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr); place-items: center; overflow: hidden; padding: 8px; }
.share-stage img, .share-stage video { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; }
.share-message { text-align: center; color: var(--muted); padding: 24px; line-height: 1.8; }
.share-foot { flex: none; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 12px; background: #0b0d10; border-top: 1px solid var(--line);
  padding-bottom: calc(12px + env(safe-area-inset-bottom)); }

/* 共有リンクの発行（管理者が見るパネル） */
.share-box { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; flex: 1 1 100%; }
.share-qr { width: 190px; max-width: 60vw; background: #fff; padding: 8px; border-radius: 8px; }
.share-qr svg { display: block; width: 100%; height: auto; }
.share-url { font-size: 12px; color: var(--muted); word-break: break-all; line-height: 1.6; }

/* 共有中の印（管理者だけに出る）。動画の▶は右下なので、こちらは左上に置く */
.tile-share { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,0.62); border-radius: 999px;
  font-size: 11px; line-height: 1; padding: 5px 7px; pointer-events: none; }
