/* 撮影PWAの見た目 */

:root {
  --bg: #111111;
  --panel: #1d1f21;
  --panel-2: #2a2d30;
  --line: #3c4043;
  --fg: #f3f4f5;
  --sub: #a9afb5;
  --accent: #ffb300;
  --accent-fg: #1a1300;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button:disabled { opacity: 0.35; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 700; }
button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }

input[type="text"], select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
}

.hint { color: var(--sub); font-size: 14px; margin: 6px 0; }
.warn { color: var(--accent); font-size: 14px; margin: 6px 0; }
.notice { background: #3a2c00; border: 1px solid var(--accent); border-radius: 10px; padding: 12px; font-size: 14px; line-height: 1.6; }

/* ---- 撮影画面 ---- */
#view-capture {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#boardCanvas {
  position: absolute;
  touch-action: none;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

#topBar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 10px 8px;
  background: linear-gradient(rgba(0, 0, 0, 0.6), transparent);
}
.top-button {
  background: rgba(0, 0, 0, 0.55);
  border-color: rgba(255, 255, 255, 0.35);
  padding: 8px 12px;
  font-size: 14px;
}
.top-button.send { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.badge {
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
  margin-left: 4px;
}

#shotLabel {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 64px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  border: 2px solid var(--accent);
  border-radius: 14px;
  padding: 10px 22px;
  text-align: center;
  pointer-events: none;
  white-space: nowrap;
}
.shot-room { font-size: 34px; font-weight: 800; letter-spacing: 1px; }
.shot-work { font-size: 22px; font-weight: 700; color: var(--accent); }
.shot-detail { font-size: 17px; font-weight: 700; margin-top: 2px; }

/* 撮れたことが分かるよう、一瞬白くする */
#shotFlash {
  position: absolute;
  inset: 0;
  background: #ffffff;
  opacity: 0;
  pointer-events: none;
}

/* ライト（暗い場所用）。看板と重なりにくい右下に置く */
#torch {
  position: absolute;
  right: 10px;
  bottom: 10px;
  background: rgba(0, 0, 0, 0.55);
  border-color: rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
}
#torch.on { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 700; }

#startPanel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  line-height: 1.7;
  background: rgba(0, 0, 0, 0.75);
  pointer-events: none;
}
#startPanel > * { pointer-events: auto; max-width: 360px; }

#bottomBar {
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 10px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* 操作パネルのつまみ。下にスライドすると隠れ、上にスライドすると戻る */
#bottomBar, #bottomBar button, #chipBar, .option-chips { touch-action: pan-x; }
#barHandle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  min-height: 0;
  margin: -6px 0 -4px;
  padding: 6px 0 4px;
  background: transparent;
  border: none;
  touch-action: none;
}
#barHandle .grip { width: 48px; height: 5px; border-radius: 999px; background: #747b82; }
#barSummary {
  display: none;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 15px;
  font-weight: 700;
}
#barBody { display: flex; flex-direction: column; gap: 8px; }
#bottomBar.collapsed #barBody { display: none; }
#bottomBar.collapsed #barSummary { display: block; }

/* 横向き（スマホ）では高さが足りないので、操作パネルを右側に置く */
@media (orientation: landscape) and (max-height: 500px) {
  #view-capture { flex-direction: row; }
  #bottomBar {
    flex: 0 0 auto;
    width: 340px;
    height: 100%;
    overflow-y: auto;
    justify-content: center;
    gap: 6px;
    border-top: none;
    border-left: 1px solid var(--line);
    padding: 8px calc(env(safe-area-inset-right) + 10px) 8px 10px;
  }
  #shutter { width: 60px; height: 60px; }
  #lastThumb, .small-button { width: 46px; height: 46px; }

  /* 操作パネルを隠したとき：映像を画面いっぱいにして、右端にシャッターだけを重ねる */
  #view-capture.bar-collapsed #topBar { display: none; }
  #view-capture.bar-collapsed #torch { right: auto; left: calc(env(safe-area-inset-left) + 10px); }
  #bottomBar.collapsed {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: auto;
    overflow: visible;
    align-items: center;
    gap: 14px;
    background: transparent;
    border: none;
    padding: 8px calc(env(safe-area-inset-right) + 14px) 8px 8px;
  }
  #bottomBar.collapsed #shutterRow { flex-direction: column; gap: 16px; padding: 0; }
  #bottomBar.collapsed #barSummary { display: none; }
  #bottomBar.collapsed #barHandle {
    width: auto;
    margin: 0;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 999px;
  }
  #bottomBar.collapsed #barHandle .grip { display: none; }
  #bottomBar.collapsed #barHandle::after { content: "操作を出す"; font-size: 12px; font-weight: 700; }
}

#roomListHint {
  min-height: 0;
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1.4;
  text-align: left;
  color: var(--accent);
  border-color: var(--accent);
  background: #3a2c00;
}

#roomRow {
  display: flex;
  align-items: stretch;
  gap: 6px;
}
#roomRow .arrow {
  flex: 0 0 46px;
  padding: 0;
  font-size: 18px;
}
#roomButton {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 6px;
  border-color: var(--accent);
}
#roomText { font-size: 22px; font-weight: 800; letter-spacing: 0.5px; }
#workText { font-size: 13px; color: var(--accent); }

#chipBar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding: 2px 0;
}
#chipBar::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 8px 16px;
  white-space: nowrap;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}
.chip.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  font-weight: 700;
}

/* 切り替え項目（状況・撮影箇所など）。1項目1行で、横にスクロールできる */
#optionRows { display: flex; flex-direction: column; gap: 6px; }
#optionRows:empty { display: none; }
.option-row { display: flex; align-items: center; gap: 8px; }
.option-label {
  flex: 0 0 auto;
  max-width: 5.5em;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 12px;
  color: var(--sub);
}
.option-chips {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.option-chips::-webkit-scrollbar { display: none; }
.option {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 4px 10px 4px 12px;
  border-radius: 10px;
  font-size: 15px;
  white-space: nowrap;
}
.option-count {
  min-width: 22px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}
/* まだ1枚も撮っていない項目は、点線の枠で目立たせる */
.option.empty { border-style: dashed; border-color: var(--danger); }
.option.empty .option-count { background: transparent; color: var(--danger); }
.option.selected {
  background: var(--accent);
  border-color: var(--accent);
  border-style: solid;
  color: var(--accent-fg);
  font-weight: 700;
}
.option.selected .option-count { background: rgba(0, 0, 0, 0.18); color: var(--accent-fg); }

#shutterRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
}
#lastThumb {
  position: relative;
  width: 56px;
  height: 56px;
  padding: 0;
  overflow: hidden;
  border-radius: 10px;
}
#savingCount {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.6;
  text-align: center;
}
#lastThumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
#shutter {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: #ffffff;
  border: 5px solid var(--panel);
  outline: 3px solid #ffffff;
  padding: 0;
}
#shutter:active { background: #cccccc; }
.small-button {
  width: 56px;
  height: 56px;
  padding: 0;
  font-size: 12px;
  line-height: 1.3;
}

/* ---- 続きを送れるときのお知らせ ---- */
#sendBanner {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 56px);
  left: 10px;
  right: 10px;
  z-index: 9;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  font-weight: 800;
  font-size: 17px;
  line-height: 1.4;
  padding: 12px 14px;
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
  animation: banner-in 0.25s ease-out;
}
@keyframes banner-in {
  from { transform: translateY(-140%); }
  to { transform: translateY(0); }
}

/* ---- 下から開くパネル ---- */
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  z-index: 10;
}
.sheet-body {
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px);
}
.sheet-body h2 { margin: 0 0 4px; font-size: 20px; }
.sheet-body h3 { margin: 14px 0 6px; font-size: 14px; color: var(--sub); }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions button { flex: 1; }

.room-input-row { display: flex; gap: 8px; }
#roomInput { flex: 1; font-size: 28px; font-weight: 800; letter-spacing: 1px; text-align: center; }
.key { flex: 0 0 56px; font-size: 22px; font-weight: 700; }

.pill-list { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { border-radius: 999px; padding: 8px 14px; min-height: 40px; }

/* 最近使った部屋は1行にして横にスクロールさせる（下の棟の表が隠れないように） */
#roomRecent { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
#roomRecent::-webkit-scrollbar { display: none; }
#roomRecent .pill { flex: 0 0 auto; }

/* 棟の表（階×号室）。数字は撮った枚数 */
#roomBuilding { margin-bottom: 8px; }
.room-grid-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
.room-grid { display: grid; gap: 6px; }
.room-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  padding: 4px 2px;
  border-radius: 8px;
  line-height: 1.25;
}
.room-cell-number { font-size: 17px; font-weight: 800; }
.room-cell-count { font-size: 11px; color: var(--sub); }
.room-cell.done { background: #1f4d3a; border-color: #3f8f6c; }
.room-cell.done .room-cell-count { color: #b9f0d3; font-weight: 700; }
.room-cell.current { border: 2px solid var(--accent); }

#viewerImage { width: 100%; max-height: 60vh; object-fit: contain; background: #000; border-radius: 10px; }
#viewerName { font-size: 14px; word-break: break-all; }

/* ---- 看板・一覧・設定のページ ---- */
.page {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.page-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.page-header h1 { flex: 1; margin: 0; font-size: 18px; }
.page-header .back { padding: 8px 12px; font-size: 14px; }
.page-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px calc(env(safe-area-inset-bottom) + 24px);
}
.page-body h2 { font-size: 16px; margin: 24px 0 6px; padding-top: 14px; border-top: 1px solid var(--line); }
.page-body h2:first-child { margin-top: 0; padding-top: 0; border-top: none; }

.button-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; }
.add-row { display: flex; gap: 8px; margin: 10px 0; }
.add-row input { flex: 1; }
.filter-row { display: flex; gap: 8px; }
.filter-row select { flex: 1; min-width: 0; padding: 10px 6px; }

.card-list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
.card.selected { border-color: var(--accent); }
.card-title { font-weight: 700; font-size: 17px; }
.card-sub { color: var(--sub); font-size: 13px; margin-top: 2px; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.card-actions button { padding: 6px 12px; min-height: 40px; font-size: 14px; }

#boardPreview {
  display: block;
  width: 100%;
  max-width: 420px;
  height: auto;
  margin: 0 auto 16px;
  border-radius: 4px;
}
#boardForm { display: flex; flex-direction: column; gap: 14px; }
#boardForm label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--sub); }
#boardForm input[type="text"], #boardForm select { color: var(--fg); font-size: 16px; }
#boardForm input[type="range"] { width: 100%; }
#boardForm fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 0; }
#boardForm legend { padding: 0 6px; font-size: 14px; color: var(--sub); }
#boardForm label.check { flex-direction: row; align-items: center; gap: 10px; min-height: 40px; color: var(--fg); font-size: 16px; }
#boardForm label.check input { width: 22px; height: 22px; }
.free-block { margin: 10px 0; padding-bottom: 10px; border-bottom: 1px dashed var(--line); }
.free-block:last-child { border-bottom: none; padding-bottom: 0; }
.free-row { display: flex; gap: 8px; margin: 8px 0; }
.free-row input:first-child { flex: 2; }
.free-row input:last-child { flex: 3; }

#photoGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.photo {
  position: relative;
  padding: 0;
  overflow: hidden;
  aspect-ratio: 1;
  border-radius: 8px;
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  font-size: 11px;
  padding: 3px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.photo-mark {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.75);
  color: var(--sub);
  border-radius: 6px;
  font-size: 10px;
  padding: 2px 5px;
}
.photo.exported img { opacity: 0.55; }
.photo.picked { outline: 4px solid var(--accent); outline-offset: -4px; }
.photo.picked::after {
  content: "✓";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 800;
  line-height: 24px;
  text-align: center;
}
#selectBar { margin: 10px 0; }
#selectSummary { margin: 0; font-weight: 700; }
