:root {
    --bg: #0b0f1a;
    --panel: rgba(12, 16, 28, 0.78);
    --line: rgba(255, 255, 255, 0.14);
    --text: #e6edf3;
    --muted: #9aa7b8;
    --accent: #14b8a6;
    --accent-2: #0d9488;
    --warn: #f59e0b;
    --danger: #ef4444;
    --radius: 16px;
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}
[hidden] { display: none !important; }
a { color: var(--accent); }

.screen { position: fixed; inset: 0; }

/* ------------------------------------------------------------ buttons */
.btn {
    appearance: none; border: 1px solid var(--line); border-radius: 999px;
    background: rgba(255, 255, 255, 0.08); color: var(--text);
    padding: 10px 18px; font: inherit; font-weight: 600; cursor: pointer;
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: transparent; color: #04211e; }
.btn.primary:disabled { opacity: .45; cursor: default; }
.btn.ghost { background: rgba(0, 0, 0, 0.35); }
.btn.big { padding: 14px 26px; font-size: 17px; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.danger { background: rgba(239, 68, 68, 0.2); border-color: rgba(239, 68, 68, 0.5); color: #fecaca; }

/* -------------------------------------------------------------- start */
.start {
    display: grid; place-items: center; padding: 24px;
    background: radial-gradient(120% 80% at 50% 0%, #134e4a 0%, var(--bg) 60%);
    overflow-y: auto; touch-action: auto;
}
.start-card { max-width: 420px; width: 100%; text-align: center; }
.logo { width: 96px; height: 96px; border-radius: 24px; box-shadow: 0 12px 40px rgba(20, 184, 166, 0.35); }
h1 { margin: 16px 0 6px; font-size: 34px; letter-spacing: -0.5px; }
.tagline { color: var(--muted); margin: 0 0 18px; }
.how { text-align: left; color: var(--text); padding-left: 22px; margin: 0 0 22px; }
.how li { margin: 6px 0; }
.fineprint { color: var(--muted); font-size: 12.5px; margin-top: 14px; }
.error { color: #fecaca; background: rgba(239, 68, 68, 0.15); border: 1px solid rgba(239, 68, 68, 0.4); padding: 10px 12px; border-radius: 10px; margin-top: 14px; text-align: left; }

/* ----------------------------------------------------------------- AR */
#screen-ar { background: var(--bg); }
#cam, #ar { position: absolute; inset: 0; width: 100%; height: 100%; }
#cam { object-fit: cover; background: #000; }
#ar { touch-action: none; }
.no-cam #cam { display: none; }
.no-cam #screen-ar {
    background:
        radial-gradient(60% 40% at 50% 100%, rgba(20, 184, 166, 0.25), transparent 70%),
        linear-gradient(180deg, #0b1530 0%, #1a3a6b 55%, #3d6a98 100%);
}
.sim #screen-ar::after {
    content: "Simulator — drag or use arrow keys to look around";
    position: absolute; left: 50%; top: calc(var(--sat) + 100px); transform: translateX(-50%);
    color: var(--muted); font-size: 12px; pointer-events: none; white-space: nowrap;
}

.reticle {
    position: absolute; left: 50%; top: 50%; width: 36px; height: 36px; margin: -18px;
    border: 2px solid rgba(255, 255, 255, 0.85); border-radius: 50%; pointer-events: none;
    box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.25);
}
.reticle::before, .reticle::after { content: ""; position: absolute; background: rgba(255, 255, 255, 0.85); }
.reticle::before { left: 50%; top: -10px; width: 2px; height: 56px; margin-left: -1px; }
.reticle::after { top: 50%; left: -10px; height: 2px; width: 56px; margin-top: -1px; }

.hud-top {
    position: absolute; left: 0; right: 0; top: 0; padding: calc(var(--sat) + 8px) 12px 0;
    display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
}
.heading-strip {
    width: min(100%, 420px); height: 44px; border-radius: 12px;
    background: var(--panel); border: 1px solid var(--line);
}
.hud-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.badge {
    background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
    padding: 4px 10px; font-size: 12.5px; color: var(--text);
}
.badge.warn { border-color: rgba(245, 158, 11, 0.6); color: #fde68a; }
.badge.bad { border-color: rgba(239, 68, 68, 0.6); color: #fecaca; }

.hud-bottom {
    position: absolute; left: 0; right: 0; bottom: 0; padding: 0 16px calc(var(--sab) + 18px);
    display: flex; justify-content: center; align-items: center; gap: 12px;
}

/* ----------------------------------------------------- panels / sheets */
.panel, .sheet {
    position: absolute; left: 10px; right: 10px; bottom: calc(var(--sab) + 10px);
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    padding: 14px; max-height: 70vh; overflow-y: auto; touch-action: pan-y;
    animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
.panel-title, .sheet-title { font-weight: 700; margin-bottom: 8px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.panel-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; }

.slider { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; margin: 8px 0; font-size: 13.5px; color: var(--muted); }
.slider output { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.slider input { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); margin: 2px 0 0; touch-action: pan-x; }

textarea {
    width: 100%; resize: none; border-radius: 12px; border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.06); color: var(--text); padding: 10px 12px; font: inherit; font-size: 16px;
}
textarea:focus { outline: 2px solid var(--accent); }
.counter { text-align: right; font-size: 12px; color: var(--muted); margin: 4px 2px 8px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.chip {
    border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 13px;
    background: rgba(255, 255, 255, 0.06); color: var(--text); cursor: pointer; font-weight: 600;
}
.chip.active { background: var(--accent); color: #04211e; border-color: transparent; }

.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.35); cursor: pointer; }
.swatch.active { border-color: #fff; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.35); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 4px; border-top: 1px solid var(--line); display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center; }
.list li:first-child { border-top: 0; }
.list .arrow { font-size: 22px; text-align: center; display: inline-block; }
.list .txt { font-weight: 600; word-break: break-word; }
.list .meta { color: var(--muted); font-size: 12.5px; }
.list .dist { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.list .actions { display: flex; gap: 6px; }
.list .edit-box { grid-column: 1 / -1; display: grid; gap: 8px; }
.list .empty { display: block; color: var(--muted); text-align: center; padding: 18px 0; }

.popover {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
    width: min(88vw, 360px); background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 16px; text-align: center;
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.popover-text { font-size: 20px; font-weight: 700; word-break: break-word; }
.popover-meta { color: var(--muted); font-size: 13px; margin: 8px 0 12px; }

#toast {
    position: fixed; left: 50%; bottom: calc(var(--sab) + 96px); transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.75); color: #fff; padding: 10px 16px; border-radius: 999px;
    font-size: 14px; max-width: 86vw; text-align: center; z-index: 50; pointer-events: none;
}
