:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --ink: #2b2f2c;
  --muted: #6b716c;
  --line: #e2e0d8;
  --accent: #5f7f6e;
  --accent-ink: #ffffff;
  --accent-soft: #e6eee9;
  --accent-deep: #33503f;
  --warn: #b5482e;
  --warn-soft: #fbe9e4;
  --caution: #7d5a10;
  --caution-soft: #fdf3dc;
  --guide: #ff4d6d;
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 17px;
  line-height: 1.6;
}
body.no-scroll { overflow: hidden; }
a { color: var(--accent); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 20px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 20px; color: var(--ink); text-decoration: none; letter-spacing: .05em; }
.topbar nav a { text-decoration: none; font-weight: 600; }

main { max-width: 960px; margin: 0 auto; padding: 20px 16px 40px; }
h1 { font-size: 26px; line-height: 1.3; margin: 4px 0 16px; }
h1 small { font-size: 16px; font-weight: 400; }
h2 { font-size: 19px; margin: 0 0 12px; }
h3 { font-size: 16px; margin: 18px 0 8px; color: var(--muted); }
p { margin: 0 0 10px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.muted { color: var(--muted); font-size: 15px; }
.center { text-align: center; }
.pre { white-space: pre-wrap; }
.warn-text { color: var(--warn); font-weight: 600; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.head-row { margin-bottom: 12px; }
.head-row h1 { margin: 0; }
.back-link { margin-bottom: 8px; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }

.btn {
  appearance: none; -webkit-appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 18px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  position: relative;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--warn); border-color: #e7c3b8; }
.btn.small { min-height: 36px; padding: 6px 14px; font-size: 15px; }
.btn:disabled { opacity: .5; }
.linkish { background: none; border: 0; color: var(--accent); font: inherit; font-size: 14px; text-decoration: underline; cursor: pointer; padding: 4px 6px; position: relative; }

input[type=text], input[type=search], input[type=date], textarea, select {
  font: inherit; width: 100%;
  padding: 10px 12px; min-height: 44px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink);
}
select { width: auto; }
textarea { min-height: 72px; resize: vertical; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; opacity: 0; }

.field { display: block; margin-bottom: 16px; }
.field > span, .label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 15px; }
.field.narrow { max-width: 240px; }
.field.narrow-wide { max-width: 360px; }
input[type=password] { font: inherit; width: 100%; padding: 10px 12px; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); }
.consent-text { background: #fbfaf7; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; font-size: 15px; margin-bottom: 8px; }
.label-sm { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.grow { flex: 1; min-width: 180px; width: auto !important; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 40px; padding: 6px 14px;
  border: 1px solid var(--line); border-radius: 999px; background: #fff;
  font-size: 15px; cursor: pointer; user-select: none; -webkit-user-select: none;
}
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.chips.scale .chip span { min-width: 46px; padding: 6px 8px; }

.check { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.check:last-of-type { border-bottom: 0; }
.check.plain { border-bottom: 0; padding: 4px 0 10px; }
.check input { width: 22px; height: 22px; margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.redflags .check input { accent-color: var(--warn); }
.toggle { display: inline-flex; gap: 8px; align-items: center; font-weight: 600; cursor: pointer; }
.toggle input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); }

.alert { border-radius: 12px; padding: 12px 14px; margin: 12px 0; font-size: 15px; }
.alert.warn { background: var(--warn-soft); color: var(--warn); border: 1px solid #f0c6b9; font-weight: 600; }
.alert.caution { background: var(--caution-soft); color: var(--caution); border: 1px solid #f0dca8; }
.alert.info { background: var(--accent-soft); color: var(--accent-deep); }

/* 一覧 */
.search { margin-bottom: 12px; }
.list { display: flex; flex-direction: column; gap: 10px; }
.list-item {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 18px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--ink); text-decoration: none;
}
.li-title { font-weight: 700; font-size: 18px; }
.li-meta { text-align: right; white-space: nowrap; }

/* お客さんページ */
dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dt { color: var(--muted); font-size: 15px; }
dd { margin: 0; }
.actions { margin: 4px 0 24px; }
.session-card { display: block; color: var(--ink); text-decoration: none; }
.sc-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.badge { font-size: 13px; padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-deep); font-weight: 600; }
.badge.full { background: #e9e4f3; color: #4d3f73; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.sc-thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; max-width: 420px; }
.sc-thumbs img, .sc-thumbs .noimg { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 8px; background: #eeece5; display: block; }
.sc-thumbs .noimg { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }

/* 記録フォーム */
.is-quick .full-only { display: none; }
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 10px; }
.slot { border: 1px dashed var(--line); border-radius: 12px; padding: 10px; text-align: center; background: #fbfaf7; }
.slot-title { font-weight: 700; margin-bottom: 6px; }
.ph {
  position: relative; aspect-ratio: 3 / 4; margin-bottom: 8px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: #eeece5; border-radius: 8px; color: var(--muted); font-size: 14px;
}
.ph img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #222; }
.slot-sub { display: flex; justify-content: center; gap: 8px; margin-top: 6px; }
.refline { position: absolute; left: 50%; top: 0; bottom: 0; border-left: 2px dashed var(--guide); opacity: .85; pointer-events: none; }
.move { border-top: 1px solid var(--line); padding: 14px 0; }
.move-title { font-weight: 700; margin-bottom: 8px; }
.move-sub { margin-top: 10px; }
.move-sub.row .label-sm { margin: 0; }
.savebar {
  position: sticky; bottom: 0; z-index: 5;
  margin: 0 -16px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(246, 245, 241, .95); border-top: 1px solid var(--line);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.savebar .row { max-width: 960px; margin: 0 auto; }

/* 比較 */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: none; font: inherit; font-size: 15px; padding: 8px 14px; min-height: 40px; cursor: pointer; color: var(--ink); }
.seg button.on { background: var(--accent); color: #fff; }
.controls .row + .row { margin-top: 12px; }
.controls label.inline { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
.controls label.inline > span { margin: 0; }
.cmp-block + .cmp-block { margin-top: 18px; }
.cmp-block h3 { margin-top: 0; }
.cmp-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cmp-fig { margin: 0; }
.cmp-fig figcaption { text-align: center; font-weight: 600; margin-top: 6px; }
.cmp-img { position: relative; aspect-ratio: 3 / 4; background: #222; border-radius: 10px; overflow: hidden; max-height: 75vh; }
.cmp-pair .cmp-img { max-height: none; }
.cmp-img.overlay { max-width: 520px; margin: 0 auto; }
.cmp-img img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.cmp-img .noimg-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #ccc; font-size: 14px; text-align: center; padding: 12px; }
table.cmp { width: 100%; border-collapse: collapse; font-size: 15px; }
table.cmp th, table.cmp td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.cmp thead th { color: var(--muted); font-weight: 600; }
table.cmp tbody th { font-weight: 600; width: 34%; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 20px; border-radius: 999px; z-index: 200; font-weight: 600;
}

/* 撮影画面 */
.cam {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column;
  background: #111; color: #fff;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.cam-top { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; }
.cam-title { font-weight: 700; font-size: 18px; }
.cam-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; margin: 0 12px; position: relative; }
.cam-frame { position: relative; background: #000; overflow: hidden; }
.cam-frame video, .cam-frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.cam-ghost { opacity: .35; pointer-events: none; }
.cam-guide { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.g-main { stroke: var(--guide); stroke-width: 2.5; stroke-dasharray: 10 6; vector-effect: non-scaling-stroke; }
.g-sub { stroke: rgba(255, 255, 255, .75); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.g-foot { fill: none; stroke: rgba(255, 255, 255, .75); stroke-width: 1.5; stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; }
.cam-label { position: absolute; left: 8px; font-size: 12px; background: rgba(0, 0, 0, .5); padding: 2px 6px; border-radius: 4px; pointer-events: none; }
.cam-count { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 120px; font-weight: 700; text-shadow: 0 2px 12px rgba(0, 0, 0, .6); }
.cam-hint { margin: 10px 16px 0; font-size: 14px; color: #ddd; text-align: center; }
.cam-ghostctl { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 14px; color: #ddd; margin-top: 6px; }
.cam-ghostctl input { width: 200px; }
.cam-controls { display: flex; align-items: center; justify-content: center; gap: 20px; padding: 12px 16px 16px; flex-wrap: wrap; }
.cam .btn { background: rgba(255, 255, 255, .12); color: #fff; border-color: rgba(255, 255, 255, .25); }
.cam .btn.primary { background: var(--accent); border-color: var(--accent); }
.shutter { width: 76px; height: 76px; border-radius: 50%; border: 5px solid #fff; background: #fff; box-shadow: inset 0 0 0 4px #111; cursor: pointer; }
.shutter:disabled { opacity: .5; }
.cam-fallback { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; text-align: center; padding: 24px; }
.cam-fallback p { max-width: 480px; color: #ddd; }
.cam[data-mode="review"] .cam-ghost,
.cam[data-mode="review"] .cam-label { display: none; }
.cam[data-mode="fallback"] .cam-frame { display: none; }
.cam:not([data-mode="live"]) .live-only,
.cam:not([data-mode="review"]) .review-only,
.cam:not([data-mode="fallback"]) .fallback-only { display: none; }

@media (max-width: 560px) {
  h1 { font-size: 22px; }
  .photos { gap: 8px; }
  .slot { padding: 6px; }
  dl { grid-template-columns: 1fr; gap: 2px; }
  dd { margin-bottom: 8px; }
}

@media print {
  .topbar, .no-print, .savebar { display: none !important; }
  body { background: #fff; font-size: 13px; }
  main { padding: 0; max-width: none; }
  .card { break-inside: avoid; border-color: #ccc; }
  .cmp-img { max-height: 120mm; }
}
