:root {
  --bg: #0e0c0a;
  --panel: #1a1613;
  --panel-2: #241e19;
  --line: #3a312a;
  --ink: #f3e9dc;
  --ink-dim: #a89a8a;
  --amber: #f5a623;
  --amber-ink: #1a1206;
  --red: #e5484d;
  --stamp: #ff8a1f;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#app { position: fixed; inset: 0; overflow: hidden; }

[hidden] { display: none !important; }

button, a { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; }
p, h1 { margin: 0; }

svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}

.wordmark {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.32em;
  color: var(--amber);
}
.wordmark.small { font-size: 11px; color: var(--ink-dim); }

/* ボタン */
.btn-primary, .btn-secondary {
  display: block;
  width: 100%;
  min-height: 52px;
  padding: 14px 20px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
}
.btn-primary { background: var(--amber); color: var(--amber-ink); }
.btn-primary:active { filter: brightness(0.9); }
.btn-secondary { border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); }
.btn-text { min-height: 44px; padding: 10px 14px; font-size: 14px; color: var(--ink-dim); }
.btn-text.accent { color: var(--amber); font-weight: 600; }
.btn-text.danger { color: var(--red); }

.icon-btn {
  position: relative;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--ink);
}
.icon-btn.ghost { visibility: hidden; }
.badge {
  position: absolute;
  top: 4px;
  right: 2px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--amber);
  color: var(--amber-ink);
  font: 600 11px/17px var(--mono);
  text-align: center;
}

/* はじめの画面 */
#gate {
  justify-content: center;
  background:
    radial-gradient(120% 70% at 50% 0%, rgba(245, 166, 35, 0.16), transparent 60%),
    var(--bg);
}
.gate-inner {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.gate-title { font-size: 26px; line-height: 1.5; font-weight: 600; }
.gate-title span { display: inline-block; }
.gate-title span:first-child { display: block; }
.gate-lead { color: var(--ink-dim); font-size: 15px; line-height: 1.7; }
.gate-note { color: var(--ink-dim); font-size: 12px; line-height: 1.7; }
.gate-error {
  padding: 12px 14px;
  border: 1px solid var(--red);
  border-radius: 12px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.7;
  -webkit-user-select: text;
  user-select: text;
}

/* 撮る画面 */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
}

.finder {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 0 10px;
  border-radius: 18px;
  overflow: hidden;
  background: #000;
}
.finder video { width: 100%; height: 100%; object-fit: cover; display: block; }

.grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.16;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='160' height='160' filter='url(%23n)'/></svg>");
}

.corners i {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 2px solid rgba(243, 233, 220, 0.75);
}
.corners i:nth-child(1) { top: 14px; left: 14px; border-right: 0; border-bottom: 0; }
.corners i:nth-child(2) { top: 14px; right: 14px; border-left: 0; border-bottom: 0; }
.corners i:nth-child(3) { bottom: 14px; left: 14px; border-right: 0; border-top: 0; }
.corners i:nth-child(4) { bottom: 14px; right: 14px; border-left: 0; border-top: 0; }

.rec {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  font: 600 15px var(--mono);
}
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); animation: blink 0.8s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.2; } }

.finder.is-rec { box-shadow: inset 0 0 0 3px var(--red); }

.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: flash 0.45s ease-out; }
@keyframes flash { 0% { opacity: 0.75; } 100% { opacity: 0; } }

.finder-msg {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(14, 12, 10, 0.82);
  text-align: center;
  font-size: 15px;
  line-height: 1.8;
  white-space: pre-line;
}

.nudge {
  flex: none;
  margin: 10px 10px 0;
  padding: 12px 14px 4px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  font-size: 14px;
}
.nudge-actions { display: flex; justify-content: flex-end; gap: 4px; }

.deck {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 16px;
}

.counter { display: flex; align-items: baseline; gap: 10px; }
.counter-label { font-size: 12px; color: var(--ink-dim); letter-spacing: 0.08em; }
.counter-num {
  min-width: 2.4ch;
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #050403;
  color: var(--amber);
  font: 600 30px/1.2 var(--mono);
  font-variant-numeric: tabular-nums;
  text-align: center;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.8);
}
.counter-num.tick { animation: tick 0.35s ease-out; }
@keyframes tick { 0% { transform: translateY(-6px); opacity: 0.3; } 100% { transform: none; opacity: 1; } }

.shutter-row {
  width: 100%;
  max-width: 380px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}
.side-btn {
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 11px;
  color: var(--ink-dim);
}
.side-btn .ico-mute { display: none; }
.side-btn[aria-pressed="true"] { color: var(--amber); }
.side-btn[aria-pressed="true"] .ico-mute { display: block; }
.side-btn[aria-pressed="true"] .ico-sound { display: none; }

.shutter { position: relative; width: 84px; height: 84px; display: grid; place-items: center; }
.shutter svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { stroke: var(--ink); stroke-width: 4; }
.ring { stroke: var(--red); stroke-width: 5; stroke-dasharray: 289.03; stroke-dashoffset: 289.03; }
.shutter-core { width: 64px; height: 64px; border-radius: 50%; background: var(--ink); transition: transform 0.15s, border-radius 0.15s, background 0.15s; }
.shutter:active .shutter-core { transform: scale(0.92); }
.shutter.is-rec .shutter-core { transform: scale(0.5); border-radius: 10px; background: var(--red); }
.shutter.is-rec .ring { animation: ring linear forwards; animation-duration: var(--clip-ms, 3000ms); }
@keyframes ring { to { stroke-dashoffset: 0; } }
.shutter:disabled { opacity: 0.35; }

.hint { font-size: 12px; color: var(--ink-dim); min-height: 18px; }

/* 現像中 */
#developing {
  align-items: center;
  justify-content: center;
  background: radial-gradient(90% 60% at 50% 45%, rgba(229, 72, 77, 0.3), transparent 70%), #0a0303;
}
.dev-inner { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 24px; }
.dev-strip { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; max-width: 280px; }
.dev-strip i {
  width: 18px;
  height: 26px;
  border-radius: 3px;
  background: #2a0b0c;
  transition: background 0.5s, box-shadow 0.5s;
}
.dev-strip i.on { background: #ff6b6f; box-shadow: 0 0 12px rgba(255, 107, 111, 0.7); }
.dev-title { font-size: 22px; letter-spacing: 0.3em; text-indent: 0.3em; color: #ffb3b5; }
.dev-sub { font-size: 13px; color: #c98a8c; }

/* フィルム棚 */
.shelf-body { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 16px 24px; -webkit-overflow-scrolling: touch; }
.shelf-empty { margin-top: 28vh; text-align: center; color: var(--ink-dim); font-size: 14px; line-height: 1.9; }
.rolls { list-style: none; margin: 0 auto; padding: 0; max-width: 480px; display: flex; flex-direction: column; gap: 12px; }
.roll {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(135deg, var(--panel-2), var(--panel));
  text-align: left;
}
.roll-can {
  width: 44px;
  height: 56px;
  border-radius: 8px;
  background: linear-gradient(90deg, #7a4a08, var(--amber) 45%, #7a4a08);
  display: grid;
  place-items: center;
  color: var(--amber-ink);
  font: 700 14px var(--mono);
}
.roll-date { font: 600 15px var(--mono); letter-spacing: 0.04em; }
.roll-meta { margin-top: 4px; font-size: 12px; color: var(--ink-dim); }
.roll-new { font-size: 11px; color: var(--amber); font-weight: 600; }

/* 上映 */
#player { background: #000; padding: 0; }
.segments {
  position: absolute;
  z-index: 3;
  top: calc(var(--safe-t) + 10px);
  left: calc(var(--safe-l) + 12px);
  right: calc(var(--safe-r) + 64px);
  display: flex;
  gap: 3px;
}
.segments i { flex: 1; height: 3px; border-radius: 2px; background: rgba(255, 255, 255, 0.28); overflow: hidden; }
.segments i b { display: block; height: 100%; width: 0; background: var(--ink); }
.segments i.done b { width: 100%; }
.stage { position: absolute; inset: 0; }
.stage video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.stamp {
  position: absolute;
  right: calc(var(--safe-r) + 18px);
  bottom: calc(var(--safe-b) + 22px);
  font: 600 17px var(--mono);
  letter-spacing: 0.12em;
  color: var(--stamp);
  text-shadow: 0 0 8px rgba(255, 138, 31, 0.75);
}
.paused {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  font-size: 13px;
}
.player-x { position: absolute; z-index: 4; top: calc(var(--safe-t) + 2px); right: calc(var(--safe-r) + 8px); }
.endcard {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px max(24px, calc((100% - 380px) / 2));
  background: rgba(14, 12, 10, 0.9);
}
.endcard-title { font-size: 24px; letter-spacing: 0.3em; text-indent: 0.3em; }
.endcard-sub { margin-bottom: 14px; font: 13px var(--mono); color: var(--ink-dim); }

/* 重ねて出す画面 */
.overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.72);
}
.overlay-card {
  width: 100%;
  max-width: 380px;
  max-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
}
.overlay-title { font-size: 18px; font-weight: 600; }
.overlay-sub { font-size: 14px; line-height: 1.8; color: var(--ink-dim); white-space: pre-line; }
.bar { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--amber); transition: width 0.3s linear; }

.field { padding: 6px 0; }
.field.row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.field-label { font-size: 14px; font-weight: 600; }
.field-note { margin-top: 4px; font-size: 12px; line-height: 1.6; color: var(--ink-dim); }
.seg { margin-top: 8px; display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { min-height: 44px; font: 600 15px var(--mono); color: var(--ink-dim); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-checked="true"] { background: var(--amber); color: var(--amber-ink); }
.toggle { flex: none; width: 52px; height: 32px; padding: 3px; border-radius: 16px; background: var(--line); transition: background 0.15s; }
.toggle i { display: block; width: 26px; height: 26px; border-radius: 50%; background: var(--ink); transition: transform 0.15s; }
.toggle[aria-checked="true"] { background: var(--amber); }
.toggle[aria-checked="true"] i { transform: translateX(20px); }
.diag summary { font-size: 12px; color: var(--ink-dim); min-height: 32px; }
.diag pre {
  margin: 6px 0 0;
  padding: 10px;
  border-radius: 10px;
  background: #050403;
  color: var(--ink-dim);
  font: 11px/1.6 var(--mono);
  white-space: pre-wrap;
  word-break: break-all;
  -webkit-user-select: text;
  user-select: text;
}

/* 横向き */
@media (orientation: landscape) {
  #camera { flex-direction: row; flex-wrap: nowrap; }
  #camera .topbar { flex-direction: column; padding: 10px 6px; }
  #camera .topbar .wordmark { display: none; }
  #camera .finder { margin: 10px 0; }
  #camera .nudge { position: absolute; z-index: 5; left: calc(var(--safe-l) + 70px); top: calc(var(--safe-t) + 16px); margin: 0; }
  #camera .deck { justify-content: center; padding: 10px 16px; width: 170px; }
  #camera .shutter-row { grid-template-columns: 1fr; grid-template-rows: auto auto auto; justify-items: center; gap: 4px; }
  #camera .hint { display: none; }
  .counter { flex-direction: column; align-items: center; gap: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .rec-dot, .flash.go, .counter-num.tick { animation: none; }
  .dev-strip i { transition: none; }
}
