/* チェキスキャナ
   方向: 几帳面・静か・少し温かい。白いフチとアルバムのポケットページの世界。
   色は面をニュートラルに保ち、水色のアクセントは主操作・選択・番号（①②③）だけに使う。
   余白は 4px グリッド。 */

:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --raised: #eceff4;
  --line: rgba(17, 24, 39, 0.08);
  --line-strong: rgba(17, 24, 39, 0.14);
  --text: #111827;
  --text-2: #4b5565;
  --muted: #6b7487;
  --accent: #0b6fa8;
  --accent-press: #095d8d;
  --accent-soft: #e3f1fa;
  --accent-ink: #075985;
  --warn-soft: #fdf3e0;
  --warn-ink: #9a5b00;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --ok: #16a34a;
  --r-ctl: 10px;
  --r-card: 14px;
  --r-tag: 6px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-float: 0 8px 24px rgba(0, 0, 0, 0.08);
  --font: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 64px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 22px;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-ink); }
[hidden] { display: none !important; }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ 枠組み */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  height: 56px; padding: 0 16px;
  padding-top: env(safe-area-inset-top, 0px);
  box-sizing: content-box;
  background: rgba(245, 247, 250, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: saturate(1.2) blur(8px);
}
.topbar h1 { flex: 1; margin: 0; font-size: 17px; font-weight: 500; line-height: 24px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-meta { font-family: var(--mono); font-size: 12px; color: var(--muted); }

main {
  max-width: 1080px; margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + var(--safe-b) + 32px);
  outline: none;
}
body.no-tabbar main { padding-bottom: calc(var(--safe-b) + 32px); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-size: 12px; line-height: 16px; color: var(--muted); text-decoration: none;
  transition: color 160ms var(--ease);
}
.tabbar a[aria-current="page"] { color: var(--accent-ink); }
.tabbar .ico svg { width: 22px; height: 22px; }

/* ------------------------------------------------------------ 部品 */

.ico { display: inline-flex; width: 18px; height: 18px; flex: none; }
.ico svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px;
  border: 1px solid var(--line-strong); border-radius: var(--r-ctl);
  background: var(--card); color: var(--text);
  font-size: 15px; font-weight: 500; text-decoration: none; cursor: pointer;
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease), color 160ms var(--ease), transform 120ms var(--ease);
  -webkit-user-select: none; user-select: none;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-press); }
.btn.quiet { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn .ico { color: inherit; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; margin-left: -8px; padding: 0;
  border: 0; border-radius: var(--r-ctl); background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn .ico, .icon-btn .ico svg { width: 22px; height: 22px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card);
  box-shadow: var(--shadow-sm); padding: 20px;
}
.stack > * + * { margin-top: 12px; }
.section + .section { margin-top: 32px; }
.section-title { margin: 0 0 12px; font-size: 15px; font-weight: 500; line-height: 22px; color: var(--text-2); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.sub { color: var(--text-2); font-size: 14px; line-height: 20px; }
.meta { color: var(--muted); font-size: 12px; line-height: 16px; }
.lead { margin: 0 0 16px; color: var(--text-2); font-size: 14px; line-height: 20px; }

label.field { display: block; }
label.field > span, .field-label { display: block; margin-bottom: 8px; font-size: 13px; line-height: 20px; color: var(--text-2); }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--r-ctl);
  background: var(--card); font-size: 16px; line-height: 22px;
  transition: border-color 160ms var(--ease);
}
textarea.input { min-height: 72px; resize: vertical; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.low { border-color: #e7b766; background: var(--warn-soft); }

.seg { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 4px; gap: 4px; border-radius: 12px; background: var(--raised); }
.seg button {
  min-height: 40px; padding: 0 16px; border: 0; border-radius: 8px; background: transparent;
  font-size: 14px; font-weight: 500; color: var(--text-2); cursor: pointer;
  transition: background-color 160ms var(--ease), color 160ms var(--ease);
}
.seg button[aria-pressed="true"] { background: var(--card); color: var(--text); box-shadow: var(--shadow-sm); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: 20px; background: var(--card);
  font-size: 14px; cursor: pointer; color: var(--text);
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease), color 160ms var(--ease);
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.chip .conf { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.chip[aria-pressed="true"] .conf { color: var(--accent-ink); }
.chip.low:not([aria-pressed="true"]) { border-style: dashed; }

.tag-est {
  display: inline-flex; align-items: center; height: 20px; padding: 0 6px;
  border-radius: var(--r-tag); background: var(--warn-soft); color: var(--warn-ink);
  font-size: 12px; line-height: 16px; font-weight: 500;
}
.tag-ok { display: inline-flex; align-items: center; height: 20px; padding: 0 6px; border-radius: var(--r-tag); background: var(--raised); color: var(--text-2); font-size: 12px; }

.notice { display: flex; gap: 10px; padding: 12px 16px; border-radius: var(--r-ctl); background: var(--raised); color: var(--text-2); font-size: 14px; line-height: 20px; }
.notice.warn { background: var(--warn-soft); color: var(--warn-ink); }
.notice.err { background: var(--danger-soft); color: #a61b1b; }
.notice .ico { margin-top: 1px; }

/* シグネチャ: 丸囲み番号 */
.no {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; flex: none; border-radius: 14px;
  background: var(--accent); color: #fff;
  font-family: var(--mono); font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums;
}
.no.off { background: var(--raised); color: var(--muted); }

/* ------------------------------------------------------------ 撮影 */

.capture { display: flex; flex-direction: column; gap: 16px; }
.viewfinder {
  position: relative; overflow: hidden;
  aspect-ratio: 3 / 4; width: 100%; max-height: 62dvh; margin: 0 auto;
  border-radius: var(--r-card); background: #1b1e24;
}
.viewfinder video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform-origin: center; }
.viewfinder .guide {
  position: absolute; left: 50%; top: 50%; height: 84%; aspect-ratio: 54 / 86; transform: translate(-50%, -50%);
  border: 2px solid rgba(255, 255, 255, 0.9); border-radius: 6px;
  box-shadow: 0 0 0 9999px rgba(10, 14, 20, 0.35);
  pointer-events: none;
}
.viewfinder .guide::after { /* 画像面（46×62mm）の目安 */
  content: ""; position: absolute; left: 7.4%; right: 7.4%; top: 7%; bottom: 20.9%;
  border: 1px dashed rgba(255, 255, 255, 0.55); border-radius: 2px;
}
.viewfinder .vf-msg {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 24px; text-align: center; color: #d7dbe2; font-size: 14px; line-height: 20px;
}
.viewfinder .res { position: absolute; left: 12px; bottom: 12px; font-family: var(--mono); font-size: 12px; color: rgba(255, 255, 255, 0.8); }
.zoom { display: flex; align-items: center; gap: 12px; }
.zoom .seg button { min-width: 48px; padding: 0 8px; font-family: var(--mono); }
.zoom input[type="range"] { flex: 1; accent-color: var(--accent); }
.shutter-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; }
.shutter {
  width: 76px; height: 76px; border-radius: 38px; padding: 6px;
  border: 2px solid var(--accent); background: var(--card); cursor: pointer;
  transition: transform 120ms var(--ease);
}
.shutter::before { content: ""; display: block; width: 100%; height: 100%; border-radius: 50%; background: var(--accent); }
.shutter:active { transform: scale(0.96); }
.shutter:disabled { opacity: 0.4; }
.filepick { justify-self: start; }
.busy {
  display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 48px 16px; color: var(--text-2); text-align: center;
}
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--raised); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------ 検出確認 */

.overlay-wrap { position: relative; border-radius: var(--r-card); overflow: hidden; background: #1b1e24; touch-action: manipulation; }
.overlay-wrap img { width: 100%; height: auto; }
.overlay-wrap svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.overlay-wrap .q { fill: rgba(11, 111, 168, 0.12); stroke: #5cc0f0; stroke-width: 3; vector-effect: non-scaling-stroke; }
.overlay-wrap .q.off { fill: rgba(0, 0, 0, 0.35); stroke: rgba(255, 255, 255, 0.6); stroke-dasharray: 6 6; }
.overlay-wrap .fail { fill: rgba(220, 38, 38, 0.10); stroke: #ff7a7a; stroke-width: 2; stroke-dasharray: 8 6; vector-effect: non-scaling-stroke; }
.overlay-wrap .handle { fill: #fff; stroke: var(--accent); stroke-width: 3; vector-effect: non-scaling-stroke; cursor: grab; touch-action: none; }
.overlay-wrap .mq { fill: rgba(92, 192, 240, 0.18); stroke: #fff; stroke-width: 2; vector-effect: non-scaling-stroke; }
.overlay-label { position: absolute; transform: translate(-50%, -50%); pointer-events: none; }
.overlay-label .no { width: 32px; height: 32px; border-radius: 16px; font-size: 16px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); }
.overlay-label.fail-label .no { background: #c2410c; }

.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.crop {
  display: flex; flex-direction: column; gap: 8px; padding: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card);
}
.crop.off .thumb { opacity: 0.35; }
.thumb {
  position: relative; aspect-ratio: 54 / 86; border-radius: 6px; overflow: hidden; background: var(--raised);
  display: flex; align-items: center; justify-content: center;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; transition: transform 300ms var(--ease); }
.thumb img.r90, .thumb img.r270 { transform-origin: center; }
.thumb .no { position: absolute; left: 6px; top: 6px; }
.crop-head { display: flex; align-items: center; gap: 6px; min-height: 20px; }
.crop-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.crop-actions .btn { min-height: 40px; padding: 0 6px; font-size: 13px; gap: 4px; }
.crop-actions .btn .ico, .crop-actions .btn .ico svg { width: 16px; height: 16px; }

.sticky-actions {
  position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-b) + 8px); z-index: 10;
  display: flex; gap: 8px; margin-top: 24px; padding: 12px;
  background: rgba(255, 255, 255, 0.96); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow-float);
}
body.no-tabbar .sticky-actions { bottom: calc(var(--safe-b) + 8px); }
.sticky-actions .btn.primary { flex: 1; }

/* ------------------------------------------------------------ 情報確認 */

.info-card { display: grid; grid-template-columns: 112px 1fr; gap: 16px; align-items: start; }
.info-card .thumb { width: 112px; }
.info-card .fields > * + * { margin-top: 16px; }
.info-card + .info-card { margin-top: 16px; }
.field-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; line-height: 20px; color: var(--text-2); }
.date-cands { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.date-cands .chip { min-height: 36px; font-family: var(--mono); font-size: 13px; }
.date-cands .chip .src { font-family: var(--font); font-size: 12px; color: var(--muted); }
details.ocr summary { cursor: pointer; font-size: 13px; color: var(--muted); }
details.ocr p { margin: 8px 0 0; font-family: var(--mono); font-size: 12px; line-height: 18px; color: var(--text-2); word-break: break-all; }
.progress { height: 4px; border-radius: 2px; background: var(--raised); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: transform 300ms var(--ease); transform-origin: left; }

@media (max-width: 520px) {
  .info-card { grid-template-columns: 1fr; }
  .info-card .thumb { width: 132px; }
}

/* ------------------------------------------------------------ 一覧 */

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.filters .wide { grid-column: 1 / -1; }
.search { position: relative; }
.search .ico { position: absolute; left: 12px; top: 13px; color: var(--muted); }
.search .input { padding-left: 40px; }
.counts { display: flex; gap: 16px; overflow-x: auto; padding: 4px 0 8px; margin-top: 12px; scrollbar-width: none; }
.counts button {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; flex: none;
  min-width: 64px; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--r-ctl);
  background: var(--card); cursor: pointer; text-align: left;
}
.counts button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.counts .n { font-family: var(--mono); font-size: 18px; line-height: 24px; font-variant-numeric: tabular-nums; }
.counts .l { font-size: 12px; line-height: 16px; color: var(--text-2); }
.month { margin: 24px 0 8px; font-size: 14px; font-weight: 500; color: var(--text-2); }
.month .num { margin-left: 8px; font-size: 12px; color: var(--muted); font-weight: 400; }
.album { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 12px; }
.album a { display: block; color: inherit; text-decoration: none; }
.album .thumb { box-shadow: var(--shadow-sm); border: 1px solid var(--line); background: var(--card); }
.album .cap { margin-top: 6px; font-size: 12px; line-height: 16px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.album .cap .num { color: var(--muted); }
.empty { padding: 48px 16px; text-align: center; color: var(--text-2); }
.empty p { margin: 0 0 16px; }

/* ------------------------------------------------------------ 詳細 */

.detail { display: grid; grid-template-columns: minmax(0, 420px) 1fr; gap: 24px; align-items: start; }
.detail .big { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); padding: 12px; }
.detail .big img { width: 100%; border-radius: 4px; }
.faces { display: flex; gap: 12px; flex-wrap: wrap; }
.face {
  width: 96px; display: flex; flex-direction: column; gap: 6px;
}
.face .crop-img { width: 96px; height: 96px; border-radius: var(--r-ctl); background-repeat: no-repeat; background-color: var(--raised); border: 1px solid var(--line); }
.face select { min-height: 36px; padding: 4px 8px; font-size: 13px; }
@media (max-width: 760px) { .detail { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------ 管理 */

.member-row { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.member-row:last-child { border-bottom: 0; }
.member-row .name { flex: 1; min-width: 0; }
.member-row .name b { font-weight: 500; }
.teacher-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; margin: 8px 0 16px; }
.teacher-grid figure { position: relative; margin: 0; }
.teacher-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.teacher-grid button { position: absolute; right: 4px; top: 4px; width: 28px; height: 28px; border-radius: 14px; border: 0; background: rgba(255, 255, 255, 0.92); color: var(--text-2); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.teacher-grid button .ico, .teacher-grid button svg { width: 14px; height: 14px; }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--text-2); }
dl.kv dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ ログイン */

.login { max-width: 360px; margin: 12dvh auto 0; }
.login h2 { margin: 0 0 4px; font-size: 22px; font-weight: 500; line-height: 30px; }

/* ------------------------------------------------------------ トースト・ダイアログ */

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); z-index: 50;
  max-width: calc(100% - 32px); padding: 12px 16px; transform: translateX(-50%);
  border-radius: var(--r-ctl); background: #1f2937; color: #f3f4f6; font-size: 14px; line-height: 20px;
  box-shadow: var(--shadow-float);
  animation: rise 300ms var(--ease);
}
.toast.err { background: #7f1d1d; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
dialog {
  width: min(420px, calc(100% - 32px)); padding: 24px; border: 0; border-radius: 16px;
  background: var(--card); color: var(--text); box-shadow: var(--shadow-float);
}
dialog::backdrop { background: rgba(15, 20, 28, 0.4); }
dialog h3 { margin: 0 0 8px; font-size: 17px; font-weight: 500; }
dialog p { margin: 0 0 16px; color: var(--text-2); font-size: 14px; line-height: 20px; }
dialog .row.end { margin-top: 20px; }
.check { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; line-height: 20px; color: var(--text-2); }
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); flex: none; }

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

/* ------------------------------------------------------------ 補足（app.js 用） */
.tag-add { margin-top: 8px; flex-wrap: nowrap; }
.tag-add .input { flex: 1; min-width: 0; }
.member-row-wrap { border-bottom: 1px solid var(--line); }
.member-row-wrap .member-row { border-bottom: 0; }
.teacher { padding: 0 0 16px; }
.overlay-wrap polygon.q { cursor: pointer; }
.zoom .seg { flex: none; }
