:root {
  --bg: #0d0d0f;
  --panel: #17171b;
  --panel-2: #1f1f25;
  --line: #2c2c34;
  --text: #f2f2f4;
  --muted: #9a9aa6;
  --accent: #f5c518;
  --accent-ink: #1a1500;
  --danger: #ff6b6b;
  --ok: #4ade80;
  --radius: 16px;
}

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

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: ui-sans-serif, -apple-system, "SF Pro Text", system-ui, sans-serif;
  overscroll-behavior: none;
}
body { overflow: hidden; }

/* 100vh first: browsers that do not understand dvh keep the vh value instead
   of dropping the declaration. Without this the container collapses to zero
   height and every absolutely-positioned screen inside becomes invisible —
   a completely black page. */
#app {
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  width: 100%;
  position: relative;
}

.screen {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  inset: 0;
  display: none; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 16px;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
.screen.active { display: flex; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

/* ── Loader ─────────────────────────────────────────── */
.loader {
  width: 42px; height: 42px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite; margin-bottom: 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Welcome ────────────────────────────────────────── */
.welcome-card {
  width: 100%; max-width: 420px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 22px; padding: 28px 22px;
  text-align: center;
  max-height: 100%; overflow-y: auto;
}
.welcome-card h1 { font-size: 26px; margin: 14px 0 6px; letter-spacing: -0.02em; }

.cam-badge {
  width: 84px; height: 56px; margin: 0 auto;
  background: var(--accent); border-radius: 12px;
  position: relative; box-shadow: 0 6px 20px rgba(245,197,24,.18);
}
.cam-badge-lens {
  position: absolute; left: 50%; top: 52%; transform: translate(-50%,-50%);
  width: 28px; height: 28px; border-radius: 50%;
  background: #0d0d0f; box-shadow: inset 0 0 0 5px #2b6cb0;
}
.cam-badge-flash {
  position: absolute; right: 9px; top: 9px;
  width: 18px; height: 11px; border-radius: 3px; background: #fff; opacity: .92;
}

.roll-intro {
  margin: 18px 0; padding: 14px;
  background: var(--panel-2); border-radius: var(--radius);
  display: flex; flex-direction: column; gap: 2px;
}
.roll-intro strong { font-size: 34px; color: var(--accent); font-variant-numeric: tabular-nums; }
.roll-intro span { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }

.rules { list-style: none; padding: 0; margin: 0 0 18px; text-align: left; }
.rules li {
  font-size: 14px; color: var(--muted); padding: 7px 0 7px 22px; position: relative;
}
.rules li::before {
  content: "●"; position: absolute; left: 4px; top: 7px; color: var(--accent); font-size: 8px;
}

.field { display: block; text-align: left; margin-bottom: 16px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field em { font-style: normal; opacity: .6; }
.field input {
  width: 100%; padding: 13px 14px; font-size: 16px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; color: var(--text); outline: none;
}
.field input:focus { border-color: var(--accent); }

.btn-primary, .btn-secondary {
  width: 100%; padding: 15px; font-size: 16px; font-weight: 650;
  border-radius: 14px; border: none; cursor: pointer;
  font-family: inherit;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:active { transform: scale(.985); }
.btn-primary:disabled { opacity: .5; }
.btn-secondary {
  background: transparent; color: var(--text);
  border: 1px solid var(--line); margin-top: 10px;
}

/* ── Camera ─────────────────────────────────────────── */
#screen-camera { justify-content: flex-start; padding: 0; }

.viewfinder-wrap {
  position: relative; width: 100%; flex: 1 1 auto;
  background: #000; overflow: hidden; min-height: 0;
}
#video { width: 100%; height: 100%; object-fit: cover; display: block; }

.flash {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  inset: 0; background: #fff;
  opacity: 0; pointer-events: none;
}
.flash.fire { animation: flash .34s ease-out; }
@keyframes flash {
  0% { opacity: 0; } 8% { opacity: .95; } 100% { opacity: 0; }
}

.vf-overlay { position: absolute; top: 0; right: 0; bottom: 0; left: 0; inset: 0; pointer-events: none; }
.vf-corner {
  position: absolute; width: 26px; height: 26px;
  border: 2px solid rgba(255,255,255,.55);
}
.vf-corner.tl { top: 18px; left: 18px; border-right: 0; border-bottom: 0; }
.vf-corner.tr { top: 18px; right: 18px; border-left: 0; border-bottom: 0; }
.vf-corner.bl { bottom: 18px; left: 18px; border-right: 0; border-top: 0; }
.vf-corner.br { bottom: 18px; right: 18px; border-left: 0; border-top: 0; }

.camera-error {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  background: rgba(13,13,15,.94); padding: 24px; text-align: center;
}
.file-btn { max-width: 260px; text-align: center; }

.camera-body {
  flex: 0 0 auto; width: 100%;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 14px 18px max(18px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center;
}

.counter-row {
  width: 100%; display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: center; gap: 10px; margin-bottom: 10px;
}
.counter {
  display: flex; align-items: baseline; gap: 6px;
  background: var(--panel-2); border-radius: 10px; padding: 6px 12px;
  justify-self: start;
}
.counter span { font-size: 22px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.counter small { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.counter.low span { color: var(--danger); }

.status-col { display: flex; flex-direction: column; align-items: center; gap: 4px; min-height: 18px; }
.queue-badge { font-size: 11px; color: var(--muted); }
.queue-badge.syncing { color: var(--accent); }
.toast { font-size: 12px; color: var(--ok); }
.toast.warn { color: var(--danger); }

.icon-btn {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  width: 40px; height: 40px; border-radius: 10px; font-size: 17px; cursor: pointer;
  justify-self: end;
}

.shutter {
  width: 86px; height: 86px; border-radius: 50%;
  background: transparent; border: none; padding: 0;
  position: relative; cursor: pointer;
}
.shutter-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 4px solid var(--line);
}
.shutter-core {
  position: absolute; inset: 8px; border-radius: 50%;
  background: var(--accent); transition: transform .08s ease;
}
.shutter:active .shutter-core { transform: scale(.9); }
.shutter:disabled { opacity: .45; cursor: not-allowed; }
.shutter.busy .shutter-core { background: var(--muted); }

.hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; }

/* ── Gallery ────────────────────────────────────────── */
#screen-gallery { justify-content: flex-start; align-items: stretch; }
.gallery-head {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 6px 0 14px; flex: 0 0 auto;
}
.gallery-head h2 { font-size: 18px; margin: 0; }
.gallery-head .icon-btn { justify-self: start; }

.gallery-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px;
  width: 100%; overflow-y: auto; flex: 1 1 auto; align-content: start;
  padding-bottom: 20px;
}
.gallery-grid img {
  width: 100%; aspect-ratio: 1; object-fit: cover;
  border-radius: 8px; background: var(--panel-2); cursor: pointer;
}

.lightbox {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  inset: 0; background: rgba(0,0,0,.95); z-index: 50;
  display: flex; align-items: center; justify-content: center;
}
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox-close { position: absolute; top: max(14px, env(safe-area-inset-top)); right: 14px; }

@media (min-width: 640px) {
  .gallery-grid { grid-template-columns: repeat(5, 1fr); }
}
