/* Kanji Lens — mobile-first, dark, camera-native UI.
   Sibling of the `kanji` project; shares its dark aesthetic. */

:root {
    --bg: #0d0b12;
    --ink: #f4f1ea;
    --muted: #9891a8;
    --accent: #e8503a;      /* vermilion — torii red */
    --accent-2: #6ee7d0;    /* jade */
    --panel: rgba(20, 17, 28, 0.92);
    --line: rgba(255, 255, 255, 0.10);
    --radius: 20px;
    --safe-b: env(safe-area-inset-bottom, 0px);
}

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

html, body { height: 100%; }

body {
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---------- Viewport / camera ---------- */
#viewport { position: relative; flex: 1; overflow: hidden; background: #000; }

#camera {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    transform: translateZ(0);
}

/* ---------- Reticle ---------- */
#reticle {
    position: absolute; inset: 0;
    display: none;
    place-items: center;
    pointer-events: none;
}
#reticle.on { display: grid; }
#reticle .corner {
    position: absolute;
    width: 46px; height: 46px;
    border: 2px solid var(--accent-2);
    opacity: 0.9;
}
.corner.tl { top: 24%; left: 16%; border-right: 0; border-bottom: 0; }
.corner.tr { top: 24%; right: 16%; border-left: 0; border-bottom: 0; }
.corner.bl { bottom: 24%; left: 16%; border-right: 0; border-top: 0; }
.corner.br { bottom: 24%; right: 16%; border-left: 0; border-top: 0; }
#reticle .hint {
    position: absolute; bottom: 16%;
    font-size: 0.85rem; letter-spacing: 0.04em;
    color: var(--ink);
    background: rgba(0,0,0,0.45);
    padding: 6px 14px; border-radius: 999px;
    backdrop-filter: blur(6px);
}

/* ---------- Gate (permission / intro) ---------- */
.gate {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 14px; padding: 32px;
    text-align: center;
    background: radial-gradient(120% 80% at 50% 20%, #241d33 0%, var(--bg) 70%);
}
.gate.hidden { display: none; }
.brand { font-size: clamp(2.6rem, 12vw, 4rem); font-weight: 800; letter-spacing: 0.02em; }
.brand span { color: var(--accent); }
.tagline { color: var(--muted); text-transform: uppercase; letter-spacing: 0.35em; font-size: 0.7rem; margin-top: -6px; }
#gate-msg { color: var(--muted); max-width: 26ch; line-height: 1.5; margin-top: 8px; }

/* ---------- Buttons ---------- */
button { font: inherit; cursor: pointer; border: 0; }
.primary {
    margin-top: 12px;
    background: var(--accent); color: #fff;
    padding: 14px 30px; border-radius: 999px;
    font-weight: 600; font-size: 1rem;
    box-shadow: 0 8px 30px rgba(232, 80, 58, 0.35);
}
.primary:active { transform: scale(0.97); }
.ghost {
    width: 100%; margin-top: 18px;
    background: transparent; color: var(--muted);
    padding: 12px; border: 1px solid var(--line); border-radius: 12px;
}

/* ---------- Shutter ---------- */
#controls {
    position: absolute; left: 0; right: 0;
    bottom: calc(28px + var(--safe-b));
    display: flex; justify-content: center;
    pointer-events: none;
}
#controls[hidden] { display: none; }
#shutter {
    pointer-events: auto;
    width: 74px; height: 74px; border-radius: 50%;
    background: var(--ink);
    border: 4px solid rgba(255,255,255,0.35);
    box-shadow: 0 0 0 2px rgba(0,0,0,0.4), 0 10px 30px rgba(0,0,0,0.5);
    transition: transform 0.08s ease;
}
#shutter:active { transform: scale(0.9); }
#shutter.busy { background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

/* ---------- Result sheet ---------- */
.sheet {
    position: absolute; left: 0; right: 0; bottom: 0;
    max-height: 82%;
    background: var(--panel);
    backdrop-filter: blur(18px);
    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);
    border-top: 1px solid var(--line);
    padding: 10px 20px calc(20px + var(--safe-b));
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.2, 0.9, 0.2, 1);
}
.sheet.open { transform: translateY(0); }
.sheet[hidden] { display: none; }
.grabber { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 6px auto 16px; }

.headline { display: flex; align-items: baseline; gap: 16px; margin-bottom: 4px; }
.headline .glyph { font-size: 4.2rem; line-height: 1; font-weight: 700; }
.headline .readings { color: var(--muted); }
.headline .readings b { color: var(--accent-2); font-weight: 600; }
.meaning { font-size: 1.3rem; margin: 8px 0 18px; }

.section-title { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.2em; color: var(--muted); margin: 18px 0 10px; }

.components { display: flex; flex-wrap: wrap; gap: 10px; }
.component {
    display: flex; align-items: center; gap: 10px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--line);
    border-radius: 12px; padding: 10px 14px;
}
.component .r-glyph { font-size: 1.8rem; }
.component .r-info small { color: var(--muted); display: block; }

.note { color: var(--muted); line-height: 1.6; font-size: 0.95rem; }
.placeholder { border: 1px dashed var(--line); border-radius: 12px; padding: 16px; color: var(--muted); }
