/* ═══════════════════════════════════════════════
   Zigillo PWA — Style
   ═══════════════════════════════════════════════ */

:root {
    --bg: #0f0f1a;
    --surface: #1a1a2e;
    --surface2: #222244;
    --primary: #6c63ff;
    --primary-glow: rgba(108, 99, 255, 0.3);
    --secondary: #e94560;
    --success: #00c897;
    --warning: #ffc107;
    --text: #e0e0f0;
    --text-muted: #8888aa;
    --border: #2a2a4a;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
}

#app {
    min-height: 100vh;
    max-width: 480px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    padding: 16px;
}

/* ── HEADER ── */
header {
    text-align: center;
    padding: 20px 0 12px;
}
header h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.version {
    font-size: 0.6rem;
    font-weight: 500;
    vertical-align: super;
    background: var(--surface2);
    padding: 2px 6px;
    border-radius: 6px;
    -webkit-text-fill-color: var(--text-muted);
    letter-spacing: 0;
}
.subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 2px;
}

/* ── SCREENS ── */
.screen {
    display: none;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}
.screen.active {
    display: flex;
}

/* ── CARDS ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    box-shadow: var(--shadow);
}
.card-hint {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 16px;
    font-size: 0.9rem;
}
.result-card {
    text-align: center;
}
.result-card.success {
    border-color: var(--success);
}
.result-icon {
    font-size: 3rem;
    margin-bottom: 8px;
}
.result-label {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 12px 0 6px;
}
.result-hint {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin: 12px 0;
}

/* ── BUTTONS ── */
.btn-row {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 8px;
}
.btn {
    border: none;
    border-radius: var(--radius-sm);
    padding: 14px 20px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    transition: transform 0.15s, box-shadow 0.15s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 0 20px var(--primary-glow);
}
.btn-secondary {
    background: var(--secondary);
    color: #fff;
    box-shadow: 0 0 20px rgba(233, 69, 96, 0.3);
}
.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.btn-small {
    padding: 8px 14px;
    font-size: 0.85rem;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    flex-shrink: 0;
}
.btn-action {
    background: var(--primary);
    color: #fff;
    border-radius: 50px;
    padding: 16px 40px;
    font-size: 1.1rem;
    box-shadow: 0 0 30px var(--primary-glow);
}
.btn-icon { font-size: 2rem; }
.btn-label { font-size: 1.1rem; }
.btn-desc { font-size: 0.75rem; opacity: 0.7; }

/* ── INPUT ── */
.input-group {
    display: flex;
    gap: 8px;
    margin: 12px 0;
}
.input-group input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 12px 16px;
    font-size: 1.1rem;
    font-family: monospace;
    letter-spacing: 2px;
    text-align: center;
    outline: none;
}
.input-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

/* ── SEAL CODE DISPLAY ── */
.seal-code-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    background: var(--bg);
    border: 1px dashed var(--primary);
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    margin: 8px 0;
}
.seal-code-wrap code {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 3px;
    color: var(--primary);
}

/* ── CAMERA ── */
.camera-container {
    position: relative;
    width: 100%;
    max-width: 360px;
    aspect-ratio: 1;
    border-radius: var(--radius);
    overflow: hidden;
    background: #000;
    box-shadow: var(--shadow);
}
.camera-container video,
.camera-container canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    object-fit: cover;
}
.viewfinder-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.viewfinder-frame {
    width: 60%;
    height: 60%;
    border: 3px solid rgba(108, 99, 255, 0.7);
    border-radius: 12px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
}
.camera-status {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.6);
    color: #fff;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
}
.camera-controls {
    display: flex;
    gap: 12px;
    margin-top: 12px;
}

/* ── LIVE VERIFY OVERLAY ── */
.live-verify-overlay {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    pointer-events: none;
}
.live-verify-overlay.active {
    display: flex;
}
.live-score {
    background: rgba(0,0,0,0.75);
    color: #fff;
    padding: 3px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 700;
    font-family: monospace;
    letter-spacing: 1px;
}
.live-score.match { color: var(--success); }
.live-score.nomatch { color: var(--secondary); }
.live-orb-info {
    font-size: 0.6rem;
    font-family: monospace;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}
.live-orb-info.ok { color: var(--success); }
.live-orb-info.fail { color: var(--secondary); }
.live-orb-info.dim { color: var(--text-muted); opacity: 0.6; }
.live-patch-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 2px;
    background: rgba(0,0,0,0.55);
    padding: 3px;
    border-radius: 8px;
    max-width: 132px;
}
.live-patch-cell {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    transition: background 0.2s;
}
.live-patch-match { background: rgba(0, 200, 151, 0.7); }
.live-patch-fail  { background: rgba(233, 69, 96, 0.7); }
.live-patch-skip  { background: rgba(255, 193, 7, 0.3); }
.live-patch-idle  { background: rgba(255, 255, 255, 0.1); }
/* Center = mark/writing patch — gold border to distinguish */
.live-patch-mark-match { background: rgba(0, 200, 151, 0.85); box-shadow: 0 0 4px rgba(255, 193, 7, 0.7); }
.live-patch-mark-fail  { background: rgba(233, 69, 96, 0.85); box-shadow: 0 0 4px rgba(255, 193, 7, 0.7); }

/* ── PROGRESS ── */
.progress-wrap {
    width: 100%;
    max-width: 360px;
    margin-top: 8px;
    text-align: center;
}
.progress-bar {
    height: 6px;
    background: var(--surface2);
    border-radius: 3px;
    overflow: hidden;
    width: 0%;
    transition: width 0.3s;
}
.progress-bar.active {
    background: linear-gradient(90deg, var(--primary), var(--secondary));
}
.progress-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
    display: block;
}

/* ── PATCH GRID (verify result) ── */
.patch-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    max-width: 240px;
    margin: 16px auto;
}
.patch-cell {
    aspect-ratio: 1;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
}
.patch-match { background: rgba(0, 200, 151, 0.25); }
.patch-fail  { background: rgba(233, 69, 96, 0.25); }
.patch-skip  { background: rgba(255, 193, 7, 0.2); }
/* Center = mark/writing patch — gold border */
.patch-mark-match { background: rgba(0, 200, 151, 0.3); box-shadow: inset 0 0 0 2px rgba(255, 193, 7, 0.6); }
.patch-mark-fail  { background: rgba(233, 69, 96, 0.3); box-shadow: inset 0 0 0 2px rgba(255, 193, 7, 0.6); }

/* ── VERIFY BREAKDOWN ── */
.breakdown {
    text-align: left;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin: 8px 0;
    padding: 8px 12px;
    background: var(--bg);
    border-radius: 8px;
    line-height: 1.6;
}
.breakdown .ok { color: var(--success); font-weight: 600; }
.breakdown .fail { color: var(--secondary); font-weight: 600; }
.breakdown .dim { opacity: 0.6; }

/* ── TOAST ── */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--surface2);
    color: var(--text);
    padding: 12px 24px;
    border-radius: 50px;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    transition: transform 0.3s ease;
    z-index: 100;
    pointer-events: none;
}
.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* ── RESPONSIVE ── */
@media (max-width: 380px) {
    #app { padding: 10px; }
    .card { padding: 18px; }
    .btn { padding: 12px 16px; font-size: 0.9rem; }
    header h1 { font-size: 1.6rem; }
}
