:root {
  color-scheme: dark;
  --ink: #253238;
  --muted: #7b8583;
  --paper: #f7f2ea;
  --card: #fffdf9;
  --line: rgba(37, 50, 56, 0.12);
  --sage: #9cab8a;
  --sage-dark: #62745c;
  --terracotta: #c77e64;
  --shadow: 0 16px 40px rgba(50, 55, 48, 0.08);
  /* 端末のセーフエリア（ノッチ・ホームバー）を避けるための余白 */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Avenir Next", "Hiragino Sans", "Yu Gothic", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: #000;
  color: #fff;
  overscroll-behavior: none;
  /* カメラアプリのように、本体は動かさずシートだけを動かします */
  overflow: hidden;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }

/* ══ カメラ画面（全画面） ══════════════════════ */

.camera-screen {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #000;
}
.camera-screen video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* 画面いっぱいに映すため、はみ出す分は切り取ります */
  object-fit: cover;
  opacity: 0;
  transition: opacity .35s ease;
}
.camera-screen video.is-live { opacity: 1; }
.camera-screen video.is-mirrored { transform: scaleX(-1); }
#cameraCanvas { display: none; }

/* 起動前の案内 */
.camera-idle {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 24px;
  text-align: center;
  background: radial-gradient(circle at 50% 42%, #223034, #0d1416 78%);
  transition: opacity .3s ease;
}
.camera-idle.is-hidden { opacity: 0; pointer-events: none; }
.camera-idle .camera-icon { color: rgba(255,255,255,.5); font-size: 34px; }
.camera-idle strong { font-size: 16px; font-weight: 600; }
.camera-idle small { color: rgba(255,255,255,.55); font-size: 12px; }
.idle-button {
  margin-top: 14px;
  padding: 13px 26px;
  border: 0;
  border-radius: 999px;
  background: #fff;
  color: #11201f;
  font-size: 13px;
  font-weight: 800;
}

/* ── 上部バー ─────────────────────────────── */

.top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(var(--safe-top) + 12px) 14px 30px;
  background: linear-gradient(rgba(0,0,0,.55), transparent);
  pointer-events: none;
}
.top-bar > * { pointer-events: auto; }

.icon-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(0,0,0,.4);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  backdrop-filter: blur(6px);
}
.icon-button.is-dark {
  background: rgba(37,50,56,.08);
  color: var(--ink);
  font-size: 17px;
  font-weight: 500;
  backdrop-filter: none;
}

.event-switcher {
  display: flex;
  gap: 3px;
  padding: 3px;
  border-radius: 999px;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(6px);
}
.event-tab {
  padding: 7px 15px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: rgba(255,255,255,.62);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  transition: background .18s, color .18s;
}
.event-tab.is-active { background: #fff; color: #11201f; }

.status-pill {
  position: absolute;
  top: calc(var(--safe-top) + 62px);
  left: 50%;
  z-index: 3;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0,0,0,.42);
  color: rgba(255,255,255,.9);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  backdrop-filter: blur(6px);
}

/* ── 下部の操作系 ─────────────────────────── */

.bottom-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  padding: 52px 14px calc(var(--safe-bottom) + 16px);
  background: linear-gradient(transparent, rgba(0,0,0,.62) 38%);
}

.shutter-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  justify-items: center;
  gap: 14px;
  margin-bottom: 4px;
}
.side-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.16);
  color: #fff;
  font-size: 17px;
  backdrop-filter: blur(6px);
}
/* アイコンだけでは何のボタンか伝わらないため、小さく名前を添えます */
.side-button em { font-size: 8px; font-style: normal; font-weight: 700; letter-spacing: .02em; }
.side-button:disabled { opacity: .35; cursor: not-allowed; }
.side-button span { display: block; transition: transform .35s ease; }
.side-button.is-flipping span { transform: rotate(180deg); }
.file-button { cursor: pointer; }
.file-button input { display: none; }

.shutter-button {
  display: grid;
  place-items: center;
  width: 74px;
  height: 74px;
  padding: 4px;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.28);
  transition: transform .12s ease;
}
.shutter-button span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #fff;
  transition: transform .12s ease;
}
.shutter-button:active:not(:disabled) span { transform: scale(.88); }
.shutter-button:disabled { opacity: .4; cursor: not-allowed; }

/* みんなの写真を開くボタン */
.album-button {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  margin-top: 16px;
  padding: 9px 13px 9px 9px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 16px;
  background: rgba(0,0,0,.4);
  color: #fff;
  text-align: left;
  backdrop-filter: blur(10px);
}
.album-thumb {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: rgba(255,255,255,.14) center / cover no-repeat;
}
.album-label { flex: 1; font-size: 13px; font-weight: 700; line-height: 1.3; }
.album-label small { display: block; margin-top: 2px; color: rgba(255,255,255,.55); font-size: 10px; font-weight: 600; }
.album-arrow { color: rgba(255,255,255,.5); font-size: 19px; }

/* ══ 写真一覧シート ════════════════════════ */

.album-sheet { position: fixed; inset: 0; z-index: 20; }
.album-sheet[hidden] { display: none; }
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 12, 12, .58);
  animation: fade-in .22s ease;
}
.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 88vh;
  padding: 8px 18px calc(var(--safe-bottom) + 18px);
  border-radius: 22px 22px 0 0;
  background: var(--paper);
  color: var(--ink);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: slide-up .28s cubic-bezier(.22, .9, .28, 1);
}
@keyframes fade-in { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(100%); } }

.sheet-grip {
  width: 38px;
  height: 4px;
  margin: 0 auto 14px;
  border-radius: 99px;
  background: rgba(37,50,56,.18);
}
.sheet-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  background: var(--paper);
}
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-sub { margin: 3px 0 0; color: var(--muted); font-size: 11px; font-weight: 700; }
.sheet-tools { display: flex; align-items: center; gap: 7px; }
.text-button {
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--card);
  color: var(--sage-dark);
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}
.text-button:disabled { opacity: .45; cursor: not-allowed; }
.sheet-foot { margin: 18px 0 0; color: var(--muted); text-align: center; font-size: 9px; font-weight: 700; letter-spacing: .1em; }

.sync-status { min-height: 15px; margin: 0 0 10px; color: var(--muted); font-size: 10px; }
.sync-status.is-error { color: var(--terracotta); font-weight: 700; }

/* ── 写真グリッド ─────────────────────────── */

.gallery-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.photo-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  box-shadow: 0 6px 20px rgba(50,55,48,.04);
}
.photo-card.is-pending { opacity: .62; }
.photo-button { display: block; width: 100%; padding: 0; border: 0; background: transparent; cursor: zoom-in; }
.photo-image-wrap { position: relative; aspect-ratio: 1 / 1.05; overflow: hidden; background: #e6e1d7; }
.photo-image { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-image-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(transparent 60%, rgba(17,28,27,.28));
  pointer-events: none;
}
.photo-meta { padding: 10px 11px 11px; }
.photo-author { margin: 0 0 4px; font-size: 11px; font-weight: 800; }
.photo-time { color: var(--muted); font-size: 9px; }
.photo-comment { margin: 8px 0 0; color: #5d6a66; font-size: 11px; line-height: 1.45; }
.photo-status {
  display: inline-block;
  margin-top: 7px;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(199,126,100,.14);
  color: var(--terracotta);
  font-size: 9px;
  font-weight: 800;
}
.comment-button {
  margin-top: 9px;
  padding: 0;
  border: 0;
  color: var(--sage-dark);
  background: transparent;
  font-size: 10px;
  font-weight: 800;
}
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 150px;
  border: 1px dashed rgba(98,116,92,.35);
  border-radius: 18px;
  color: var(--muted);
  text-align: center;
}
.empty-state span { color: var(--sage); font-size: 25px; }
.empty-state p { margin: 8px 0 0; font-size: 12px; line-height: 1.7; }

/* ══ ダイアログ共通 ══════════════════════════ */

.sheet-dialog {
  width: min(100%, 440px);
  padding: 24px 22px 22px;
  border: 0;
  border-radius: 20px;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.sheet-dialog::backdrop { background: rgba(6, 12, 12, .6); }
.sheet-dialog h2 { margin: 6px 0 0; font-size: 19px; }
.eyebrow { margin: 0; color: var(--sage-dark); font-size: 10px; font-weight: 800; letter-spacing: .16em; }
.dialog-close { position: absolute; top: 16px; right: 16px; }
.dialog-copy { margin: 9px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.field-label { display: block; margin: 18px 0 7px; font-size: 11px; font-weight: 800; }
.text-input, .comment-input {
  width: 100%;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fbfaf6;
  color: var(--ink);
}
.comment-input { min-height: 96px; margin-top: 14px; resize: vertical; }
.primary-button {
  width: 100%;
  margin-top: 16px;
  padding: 14px;
  border: 0;
  border-radius: 12px;
  background: var(--sage-dark);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

/* ── 使い方 ───────────────────────────────── */

.guide-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.guide-head h2 { margin: 5px 0 0; }
.os-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 18px 0 14px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255,255,255,.6);
}
.os-tab { padding: 9px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 800; }
.os-tab.is-active { background: var(--card); color: var(--ink); box-shadow: 0 3px 12px rgba(0,0,0,.06); }
.guide-steps { display: flex; flex-direction: column; gap: 22px; max-height: 56vh; overflow-y: auto; padding-right: 4px; }
.guide-step { display: grid; grid-template-columns: 26px 1fr; gap: 11px; align-items: start; }
.step-number { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--sage-dark); color: #fff; font-size: 12px; font-weight: 800; }
.step-body h3 { margin: 3px 0 5px; font-size: 13px; }
.step-body p { margin: 0; color: #5d6a66; font-size: 12px; line-height: 1.6; }
/* ── iPhoneモック ─────────────────────────── */
/* スクリーンショットを実機の外観に収めて見せます */

.phone-mock { display: flex; justify-content: center; margin-top: 12px; }

.phone-frame {
  position: relative;
  width: 190px;
  padding: 8px;
  border-radius: 30px;
  /* チタンフレームの光沢を、角度のあるグラデーションで表現します */
  background: linear-gradient(145deg, #d8d5d0 0%, #8e8b87 18%, #45423f 42%, #6f6c68 58%, #c9c6c1 82%, #7d7a76 100%);
  box-shadow:
    0 1px 2px rgba(255,255,255,.5) inset,
    0 14px 30px rgba(24, 30, 32, .28),
    0 3px 8px rgba(24, 30, 32, .16);
}
.phone-screen {
  position: relative;
  overflow: hidden;
  border-radius: 23px;
  background: #000;
  /* 画面の内側の縁を締めて、ガラス面らしく見せます */
  box-shadow: 0 0 0 1.5px #16181a inset;
}
.phone-screen img { display: block; width: 100%; height: auto; }

/* Dynamic Island。実写のキャプチャには元から写っているため、
   画像が無いプレースホルダ側でのみ表示します。 */
.phone-island {
  position: absolute;
  top: 17px;
  left: 50%;
  width: 54px;
  height: 15px;
  transform: translateX(-50%);
  border-radius: 99px;
  background: #000;
  pointer-events: none;
}

/* サイドボタン */
.phone-btn {
  position: absolute;
  width: 2px;
  border-radius: 2px;
  background: linear-gradient(#b6b3ae, #6d6a66);
  pointer-events: none;
}
.phone-btn-silent { left: -2px; top: 82px; height: 22px; }
.phone-btn-up     { left: -2px; top: 116px; height: 34px; }
.phone-btn-down   { left: -2px; top: 158px; height: 34px; }
.phone-btn-power  { right: -2px; top: 128px; height: 52px; }

/* 画像がまだ無い手順 */
.phone-frame.is-empty {
  background: linear-gradient(145deg, #ddd9d3, #b3afa9);
  box-shadow: 0 6px 16px rgba(24, 30, 32, .14);
}
.phone-frame.is-empty .phone-screen {
  display: grid;
  place-items: center;
  min-height: 210px;
  background: #efece5;
  box-shadow: 0 0 0 1.5px rgba(37,50,56,.1) inset;
}
.phone-empty-text {
  margin: 0;
  padding: 16px;
  color: var(--muted);
  font-size: 10px;
  text-align: center;
  line-height: 1.7;
}
.guide-skip { display: flex; align-items: center; gap: 7px; margin: 16px 0 12px; color: var(--muted); font-size: 11px; }
.guide-skip input { width: 15px; height: 15px; accent-color: var(--sage-dark); }

/* ── 拡大表示 ─────────────────────────────── */

.viewer-dialog {
  width: min(100%, 900px);
  max-width: 100%;
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: #11201f;
  color: #fff;
}
.viewer-dialog::backdrop { background: rgba(6, 12, 12, .85); }
.viewer-image { display: block; width: 100%; max-height: 72vh; object-fit: contain; background: #0b1413; }
.viewer-meta { padding: 14px 16px 18px; }
.viewer-author { margin: 0; font-size: 12px; font-weight: 800; }
.viewer-comment { margin: 6px 0 0; color: rgba(255,255,255,.72); font-size: 12px; line-height: 1.5; }
.viewer-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: rgba(0,0,0,.45);
  color: #fff;
  font-size: 19px;
  line-height: 1;
}

/* ── トースト ─────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 132px);
  z-index: 40;
  padding: 12px 16px;
  border-radius: 11px;
  background: rgba(20, 30, 29, .94);
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.is-visible { transform: translate(-50%, 0); opacity: 1; }

/* ── 画面が広い場合 ───────────────────────── */

@media (min-width: 620px) {
  .gallery-grid { grid-template-columns: repeat(3, 1fr); }
  .bottom-bar, .top-bar { padding-left: 24px; padding-right: 24px; }
  .album-button { max-width: 340px; }
  .sheet-panel { left: 50%; width: min(100%, 720px); transform: translateX(-50%); }
}

@media (prefers-reduced-motion: reduce) {
  .sheet-panel, .sheet-backdrop { animation: none; }
  * { transition-duration: .01ms !important; }
}

/* 撮影時のフラッシュ。全画面カメラだと撮れた実感が薄いため、白く一瞬光らせます */
.shutter-flash {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}
.shutter-flash.is-firing { animation: flash .32s ease-out; }
@keyframes flash {
  0% { opacity: .85; }
  100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .shutter-flash.is-firing { animation: none; }
}

/* ── 確認ダイアログ ───────────────────────── */

.sheet-dialog.is-compact { width: min(100%, 340px); padding: 22px 20px 20px; }
.sheet-dialog.is-compact h2 { margin: 0; font-size: 16px; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 18px; }
.ghost-button {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}
.danger-button {
  padding: 13px;
  border: 0;
  border-radius: 12px;
  background: var(--terracotta);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

/* 写真カードの削除ボタン */
.photo-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 9px; }
.delete-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--terracotta);
  font-size: 10px;
  font-weight: 800;
}
.viewer-delete {
  margin-top: 12px;
  padding: 9px 14px;
  border: 1px solid rgba(255,255,255,.24);
  border-radius: 10px;
  background: rgba(199,126,100,.18);
  color: #f0b8a4;
  font-size: 11px;
  font-weight: 800;
}

/* Androidのフレーム。iPhoneより角が控えめで、ボタンは右側に集まっています */
.phone-frame.is-android { border-radius: 24px; padding: 7px; background: linear-gradient(145deg, #cfcdc9 0%, #83817d 20%, #3d3b39 45%, #6a6866 62%, #bfbdb9 85%, #74726f 100%); }
.phone-frame.is-android .phone-screen { border-radius: 18px; }
.phone-btn-a-power { right: -2px; top: 96px; height: 30px; }
.phone-btn-a-vol { right: -2px; top: 134px; height: 46px; }

/* ── 管理者モード ─────────────────────────── */

.admin-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 11px 13px;
  border: 1px solid rgba(199,126,100,.34);
  border-radius: 12px;
  background: rgba(199,126,100,.1);
}
.admin-bar[hidden] { display: none; }
.admin-note strong { display: block; color: var(--terracotta); font-size: 11px; font-weight: 800; }
.admin-note small { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }
.admin-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.admin-button {
  padding: 7px 10px;
  border: 0;
  border-radius: 8px;
  background: var(--terracotta);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}
.admin-button.is-ghost { background: var(--card); border: 1px solid var(--line); color: var(--muted); }
.admin-button:disabled { opacity: .5; cursor: not-allowed; }

/* 管理者モードのときは、上部の名前ボタンで気づけるようにします */
body.is-admin .icon-button#profileButton { background: var(--terracotta); }

/* 端末に保存 */
.viewer-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.viewer-save {
  padding: 9px 14px;
  border: 1px solid rgba(255,255,255,.24);
  border-radius: 10px;
  background: rgba(255,255,255,.12);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
}
.viewer-save:disabled { opacity: .5; cursor: not-allowed; }
.viewer-actions .viewer-delete { margin-top: 0; }
.save-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--sage-dark);
  font-size: 10px;
  font-weight: 800;
}
.photo-action-right { display: flex; align-items: center; gap: 10px; }

/* ── ホーム画面への追加をすすめるバナー ─────── */

.install-hint {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--safe-bottom) + 200px);
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 14px;
  background: rgba(20, 30, 29, .92);
  color: #fff;
  backdrop-filter: blur(10px);
  animation: hint-in .3s ease;
}
.install-hint[hidden] { display: none; }
@keyframes hint-in { from { opacity: 0; transform: translateY(8px); } }
.install-text { flex: 1; min-width: 0; }
.install-text strong { display: block; font-size: 12px; font-weight: 700; }
.install-text small { display: block; margin-top: 2px; color: rgba(255,255,255,.6); font-size: 10px; }
.install-how {
  flex: 0 0 auto;
  padding: 7px 12px;
  border: 0;
  border-radius: 8px;
  background: #fff;
  color: #11201f;
  font-size: 11px;
  font-weight: 800;
}
.install-close {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.14);
  color: rgba(255,255,255,.8);
  font-size: 15px;
  line-height: 1;
}
