:root {
  --bg: #111827;
  --panel: #1f2937;
  --panel-2: #273244;
  --text: #f9fafb;
  --muted: #9ca3af;
  --accent: #60a5fa;
  --danger: #f87171;
  --radius: 12px;
  --gap: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 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%;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--panel);
  border-bottom: 1px solid #374151;
}

.title { font-size: 18px; margin: 0; font-weight: 600; }
.topbar-actions { display: flex; gap: 8px; }

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--panel-2);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); color: #0b1220; }
.btn.ghost { background: transparent; border-color: #4b5563; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn[hidden] { display: none; }

.layout {
  display: grid;
  grid-template-columns: 1fr;
}

.filter-panel {
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid #374151;
}
.filter-panel[hidden] { display: none; }

.filter-form, .form { display: grid; gap: 10px; }
.form label, .filter-form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > label { flex: 1 1 140px; }
.row > .btn { flex: 1 1 auto; }

input, select, textarea {
  width: 100%;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid #4b5563;
  border-radius: 10px;
  padding: 9px 11px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.main { padding: 12px 16px calc(env(safe-area-inset-bottom) + 24px); }
.status { color: var(--muted); font-size: 13px; margin: 0 0 10px; min-height: 1.2em; }
.empty { color: var(--muted); text-align: center; margin-top: 60px; }

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

.card {
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid #374151;
  display: flex;
  flex-direction: column;
}
.card:focus-visible { outline: 2px solid var(--accent); }
.card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: #000;
}
.card .meta { padding: 8px 10px; display: grid; gap: 3px; }
.card .comment {
  font-size: 14px;
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  min-height: 1.35em;
}
.card .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet[hidden] { display: none; }
.sheet-body {
  width: 100%;
  max-width: 640px;
  max-height: 95dvh;
  overflow: auto;
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  padding: 14px 16px calc(env(safe-area-inset-bottom) + 20px);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sheet-head h2 { margin: 0; font-size: 17px; }
.preview {
  width: 100%;
  max-height: 40dvh;
  object-fit: contain;
  background: #000;
  border-radius: 10px;
  margin-bottom: 12px;
}
.preview.large { max-height: 55dvh; }
.hint { color: var(--muted); font-size: 12px; }
.check { display: flex !important; align-items: center; gap: 8px; color: var(--text) !important; font-size: 15px !important; }
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }

@media (min-width: 900px) {
  .layout { grid-template-columns: 300px 1fr; min-height: calc(100dvh - 61px); }
  .filter-panel { border-bottom: 0; border-right: 1px solid #374151; }
  .filter-panel[hidden] { display: block; }
  #btn-filter-toggle { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .sheet { align-items: center; }
  .sheet-body { border-radius: 18px; }
  .preview, .preview.large { max-height: 38dvh; }
}

/* ===== v0.3: auth / settings / quota ===== */
.topbar-actions { align-items: center; }
.btn.icon { padding: 9px 12px; font-size: 18px; }
.btn.small { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.album-select { width: auto; max-width: 40vw; padding: 8px 10px; font-size: 14px; }

.auth { display: flex; justify-content: center; padding: 24px 16px calc(env(safe-area-inset-bottom) + 24px); }
.auth-card { width: 100%; max-width: 460px; background: var(--panel); border: 1px solid #374151; border-radius: 16px; padding: 20px; }
.auth-form h2 { margin: 0 0 6px; font-size: 20px; }
.auth-form h3 { margin: 10px 0 0; font-size: 14px; color: var(--muted); font-weight: 600; }
.auth-links { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; margin-top: 4px; }
.auth-links a, .notice a { color: var(--accent); }
.form-error { color: var(--danger); font-size: 13px; margin: 0; }
.form-error[hidden] { display: none; }
.notice { background: #1e3a5f; border: 1px solid #2563eb; border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 0 0 14px; }
.banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; background: #3b2f0b; border: 1px solid #a16207; border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.banner[hidden] { display: none; }

.storage { display: grid; gap: 6px; margin-top: 4px; }
.storage-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.storage-bar { height: 8px; background: #374151; border-radius: 4px; overflow: hidden; }
.storage-bar > div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.storage-bar > div.warn { background: #f59e0b; }
.storage-bar > div.over { background: var(--danger); }

.settings-section { border-top: 1px solid #374151; padding: 14px 0; display: grid; gap: 10px; }
.settings-section:first-of-type { border-top: 0; }
.settings-section h3 { margin: 0; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.settings-section h4 { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #374151; color: var(--muted); font-weight: 600; }
.tag.on { background: #14532d; color: #86efac; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; word-break: break-all; user-select: all; margin: 0; }
.codes { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; line-height: 1.8; }
.qr { display: flex; justify-content: center; }
.qr canvas, .qr img { background: #fff; padding: 8px; border-radius: 8px; width: 200px; height: 200px; }
.member-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.member-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--panel-2); border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.member-list .who { display: grid; min-width: 0; }
.member-list .who small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body.modal { border-radius: 18px; margin: 16px; }
.sheet-body.modal h2 { margin: 0 0 10px; font-size: 18px; }

/* hidden 属性を display 指定より優先する(フィルタパネルは PC で常時表示のため除外) */
[hidden]:not(#filter-panel) { display: none !important; }

/* トップバー: スマホでは 2 段にする */
.btn { white-space: nowrap; }
.topbar { flex-wrap: wrap; }
.topbar-actions { flex: 1 1 auto; justify-content: flex-end; }
.album-select { flex: 1 1 120px; min-width: 0; max-width: none; }
@media (max-width: 640px) {
  .topbar { padding-bottom: 8px; }
  .topbar-actions { flex: 1 1 100%; }
  .title { font-size: 17px; }
}
@media (min-width: 641px) {
  .album-select { flex: 0 1 260px; }
}
@media (max-width: 640px) {
  .topbar-actions .btn { padding: 8px 10px; font-size: 14px; min-height: 36px; }
  .topbar-actions .btn.icon { padding: 8px 10px; font-size: 17px; }
  .album-select { flex: 1 1 80px; padding: 7px 8px; font-size: 14px; min-height: 36px; }
}
/* select は width 指定が無いと flex で縮まないため明示する */
.album-select { width: 0; text-overflow: ellipsis; }

/* ===== v0.5: フッターの撮影バー ===== */
.footbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  align-items: stretch;
  gap: 12px;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 10px);
  background: var(--panel);
  border-top: 1px solid #374151;
}
.footbar[hidden] { display: none; }
.footbar .foot-big { flex: 1 1 auto; min-height: 60px; font-size: 20px; border-radius: 14px; }
.footbar .foot-small { flex: 0 0 auto; width: 60px; min-height: 60px; padding: 0; font-size: 24px; border-radius: 14px; }
.main { padding-bottom: calc(env(safe-area-inset-bottom) + 96px); }

/* 招待経由の登録: 固定されたメールアドレス欄 */
input.locked { color: var(--muted); background: #1a2231; }

/* ===== v0.7: 動画 ===== */
.card .thumb { position: relative; }
.card .badge {
  position: absolute; right: 6px; bottom: 6px;
  padding: 2px 7px; border-radius: 6px;
  background: rgba(0,0,0,.65); color: #fff; font-size: 12px; font-weight: 600;
  pointer-events: none;
}
video.preview { display: block; }
video.preview[hidden], img.preview[hidden] { display: none; }
