:root {
  --bg: #000;
  --panel: #15171c;
  --line: #2a2f3a;
  --text: #f0f2f6;
  --muted: #8d93a3;
  --accent: #4f8cff;
  --danger: #e5484d;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, sans-serif; overflow: hidden; overscroll-behavior: none; }
h1, h2 { font-size: 16px; margin: 0; }
button { font: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Views */
.view { position: fixed; inset: 0; display: none; flex-direction: column; }
.view.is-active { display: flex; }

/* Tabs */
.tabs { display: flex; border-top: 1px solid var(--line); background: var(--panel); padding-bottom: var(--safe-bottom); }
.tabs button { flex: 1; background: none; border: 0; color: var(--muted); padding: 10px 0 8px; font-size: 12px; }
.tabs button.is-active { color: var(--accent); }
.tabs button span { display: block; font-size: 20px; }

/* Camera */
.camera { flex: 1; position: relative; overflow: hidden; background: #000; touch-action: none; }
.camera video { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera__top { position: absolute; top: 0; left: 0; right: 0; display: flex; gap: 8px; padding: calc(10px + var(--safe-top)) 10px 10px; justify-content: space-between; align-items: center; }
.camera__hint { position: absolute; left: 0; right: 0; top: 50%; margin: 0; text-align: center; color: #fff; text-shadow: 0 1px 4px #000; pointer-events: none; font-size: 15px; }
.camera__error { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 30px; color: var(--muted); background: #000; }
.camera__start { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--accent); color: #fff; border: 0; border-radius: 24px; padding: 14px 22px; font-size: 15px; }
.camera__bar { display: flex; align-items: center; justify-content: space-around; padding: 16px 0; background: var(--panel); }

.chip { background: rgba(0,0,0,.6); color: #fff; border: 1px solid rgba(255,255,255,.25); border-radius: 20px; padding: 6px 12px; font-size: 12px; backdrop-filter: blur(6px); }
.chip.is-active { border-color: var(--accent); color: var(--accent); }

.shutter { width: 72px; height: 72px; border-radius: 50%; background: #fff; border: 5px solid #999; transition: transform .1s; }
.shutter:active { transform: scale(.92); }
.shutter:disabled { opacity: .4; }
.icon-btn { width: 52px; height: 52px; border-radius: 50%; background: #2a2f3a; border: 0; color: #fff; font-size: 22px; overflow: hidden; display: flex; align-items: center; justify-content: center; padding: 0; }
.icon-btn img { width: 100%; height: 100%; object-fit: cover; }

/* Result */
.result { flex: 1; position: relative; background: #000; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.result canvas { max-width: 100%; max-height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
.result__tag { position: absolute; top: calc(10px + var(--safe-top)); left: 10px; }
.bar { display: flex; gap: 8px; padding: 12px; background: var(--panel); padding-bottom: calc(12px + var(--safe-bottom)); }
.bar .btn { flex: 1; }

/* Buttons */
.btn { background: #2a2f3a; color: var(--text); border: 0; border-radius: 8px; padding: 11px 14px; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }

/* Gallery */
.head { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-top)) 14px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.head h1 { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid { flex: 1; overflow: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 3px; padding: 3px; align-content: start; }
.grid button { padding: 0; border: 0; background: #222; aspect-ratio: 1; overflow: hidden; }
.grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.grid .empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 60px 20px; }
.viewer { flex: 1; display: flex; align-items: center; justify-content: center; background: #000; overflow: hidden; }
.viewer img { max-width: 100%; max-height: 100%; }

/* Settings sheet */
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--panel); border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; padding: 14px 16px calc(16px + var(--safe-bottom)); transform: translateY(100%); transition: transform .25s; max-height: 85vh; overflow: auto; }
.sheet.is-open { transform: none; }
.sheet h2 { margin-bottom: 10px; }
.slider { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.slider label { flex: 1; }
.slider input { flex: 2; accent-color: var(--accent); }
.slider output { width: 36px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Feedback */
.busy { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.6); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.spinner { width: 36px; height: 36px; border: 3px solid rgba(255,255,255,.2); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%); z-index: 20; background: #fff; color: #000; padding: 8px 14px; border-radius: 20px; font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; white-space: nowrap; }
.toast.is-visible { opacity: 1; }
