/*
    Copyright (C) 2025, Paul Hammant

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

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

:root {
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

html {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #000;
    color: #fff;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* iOS Safari viewport fix */
@supports (-webkit-touch-callout: none) {
    html, body {
        height: -webkit-fill-available;
    }
}

.container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 100%;
    overflow: hidden;
}

/* Minimal header - overlays on camera */
header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20;
    padding: calc(var(--safe-area-top) + 10px) 15px 10px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.7) 0%, transparent 100%);
    text-align: center;
}

header h1 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 2px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

header p {
    font-size: 0.75rem;
    opacity: 0.8;
}

#buildTimestamp {
    font-size: 0.65rem !important;
    opacity: 0.6;
}

/* Main camera area */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.camera-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.video-container {
    flex: 1;
    position: relative;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
}

#overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Shutter button - center of viewfinder */
.shutter-btn {
    position: absolute;
    bottom: 25%;
    left: 50%;
    transform: translateX(-50%);
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: #fff;
    border: 4px solid rgba(255,255,255,0.3);
    font-size: 0;
    cursor: pointer;
    box-shadow: 0 2px 20px rgba(0,0,0,0.4);
    z-index: 30;
    transition: all 0.15s ease;
}

.shutter-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #ddd;
}

.shutter-btn:active {
    transform: translateX(-50%) scale(0.92);
}

.shutter-btn:active::before {
    background: #e0e0e0;
}

.shutter-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Controls bar - bottom */
.controls {
    position: absolute;
    bottom: calc(var(--safe-area-bottom) + 20px);
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0 30px;
    z-index: 25;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-primary {
    background: rgba(255,204,0,0.9);
    color: #000;
}

.btn-primary:hover:not(:disabled) {
    background: rgba(255,204,0,1);
}

.btn-secondary {
    background: rgba(255,255,255,0.2);
    color: #fff;
}

.btn-secondary:hover:not(:disabled) {
    background: rgba(255,255,255,0.3);
}

.btn-small {
    padding: 8px 14px;
    font-size: 0.8rem;
}

#debugConsole {
    position: absolute;
    top: 80px;
    left: 10px;
    right: 10px;
    max-height: 120px;
    background: rgba(0, 0, 0, 0.85);
    color: #0f0;
    font-family: monospace;
    font-size: 9px;
    padding: 8px;
    overflow-y: auto;
    z-index: 100;
    border-radius: 8px;
    pointer-events: none;
    line-height: 1.3;
}

/* Verification overlays - camera-native feel */
.verification-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px;
    border-radius: 24px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.overlay-content.success {
    background: rgba(52, 199, 89, 0.85);
}

.overlay-content.failure {
    background: rgba(255, 69, 58, 0.85);
}

.overlay-content.processing {
    background: rgba(0, 0, 0, 0.75);
}

.overlay-icon {
    font-size: 72px;
    font-weight: 300;
    line-height: 1;
    margin-bottom: 15px;
    color: #fff;
    text-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.overlay-content.success .overlay-icon {
    font-weight: 600;
}

.overlay-text {
    font-size: 1.5rem;
    font-weight: 600;
    color: #fff;
    text-align: center;
    text-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.overlay-domain {
    margin-top: 10px;
    font-size: 0.9rem;
    color: rgba(255,255,255,0.9);
    font-weight: 500;
    padding: 6px 14px;
    background: rgba(255,255,255,0.2);
    border-radius: 12px;
}

.overlay-subtext {
    margin-top: 10px;
    font-size: 0.95rem;
    color: rgba(255,255,255,0.9);
    text-align: center;
    max-width: 260px;
}

.overlay-tap-hint {
    position: absolute;
    bottom: calc(var(--safe-area-bottom) + 60px);
    color: rgba(255,255,255,0.7);
    font-size: 0.85rem;
    font-weight: 500;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

.overlay-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Results section - only shown on failure */
.results-section {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 70vh;
    background: rgba(28,28,30,0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px 20px 0 0;
    padding: 20px;
    padding-bottom: calc(var(--safe-area-bottom) + 20px);
    z-index: 40;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    display: none;
}

.results-section.show-failure {
    display: block;
    transform: translateY(0);
}

/* Status indicator - hidden, using overlays instead */
.status-indicator {
    display: none;
}

.status-icon {
    font-size: 2rem;
    margin-bottom: 5px;
}

.status-text {
    font-size: 0.95rem;
    color: rgba(255,255,255,0.9);
    font-weight: 500;
}

#captureInfo {
    padding: 8px;
    margin-bottom: 8px;
}

#captureInfo .status-text {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.6);
    font-weight: 400;
    line-height: 1.4;
}

/* Progress bar - hidden, using processing overlay instead */
.progress-bar {
    display: none;
}

.progress-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: linear-gradient(90deg, #ffcc00 0%, #ff9500 100%);
    animation: progress 2s ease-in-out infinite;
}

.progress-text {
    position: relative;
    z-index: 1;
    line-height: 44px;
    text-align: center;
    font-weight: 600;
    color: #fff;
}

@keyframes progress {
    0% { width: 0%; }
    50% { width: 70%; }
    100% { width: 100%; }
}

.result-card {
    background: rgba(255,255,255,0.08);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 12px;
    border-left: 3px solid #ffcc00;
}

.result-card h3 {
    margin-bottom: 12px;
    color: #fff;
    font-size: 0.95rem;
}

.tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab-btn {
    padding: 8px 14px;
    border: none;
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.7);
    font-weight: 600;
    font-size: 0.8rem;
    cursor: pointer;
    border-radius: 8px;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    background: rgba(255,255,255,0.15);
}

.tab-btn.active {
    background: #ffcc00;
    color: #000;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

.result-card pre {
    background: rgba(0,0,0,0.3);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.8rem;
    line-height: 1.5;
    color: rgba(255,255,255,0.9);
    border: 1px solid rgba(255,255,255,0.1);
}

#normalizedText {
    background: rgba(0,0,0,0.3);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.2);
}

.hash-value {
    background: rgba(0,0,0,0.3);
    padding: 12px;
    border-radius: 8px;
    font-family: 'SF Mono', 'Courier New', monospace;
    word-break: break-all;
    margin-bottom: 10px;
    border: 1px solid rgba(255,255,255,0.1);
    font-size: 0.75rem;
    color: rgba(255,255,255,0.9);
    user-select: text;
    -webkit-user-select: text;
}

.verification-status {
    padding: 12px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 10px;
    text-align: center;
}

.verification-status.verified {
    background: rgba(52,199,89,0.2);
    color: #34c759;
    border: 2px solid #34c759;
}

.verification-status.not-found {
    background: rgba(255,69,58,0.2);
    color: #ff453a;
    border: 2px solid #ff453a;
}

.verification-status.denied {
    background: rgba(255,159,10,0.2);
    color: #ff9f0a;
    border: 2px solid #ff9f0a;
}

.verification-status.revoked {
    background: rgba(191,90,242,0.2);
    color: #bf5af2;
    border: 2px solid #bf5af2;
}

.verification-details {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.6);
    word-break: break-all;
    padding: 10px;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
}

#verificationDisclaimer {
    background-color: rgba(255,159,10,0.15) !important;
    border-left-color: #ff9f0a !important;
    color: rgba(255,255,255,0.9) !important;
    border-radius: 8px;
}

/* Footer - minimal */
footer {
    position: absolute;
    bottom: calc(var(--safe-area-bottom) + 5px);
    left: 0;
    right: 0;
    z-index: 15;
    padding: 0 15px;
}

footer details {
    display: none;
}

footer p {
    text-align: center;
    font-size: 0.65rem;
    color: rgba(255,255,255,0.4);
}

footer a {
    color: rgba(255,255,255,0.6);
    text-decoration: none;
}

/* When results are showing, hide footer */
.results-section.expanded ~ footer,
.results-section:has(.result-card:not([style*="display: none"])) ~ footer {
    display: none;
}

/* Portrait phone - ensure good spacing */
@media (orientation: portrait) and (max-width: 500px) {
    .shutter-btn {
        bottom: 25%;
    }

    .controls {
        bottom: calc(var(--safe-area-bottom) + 15px);
    }

    .results-section {
        max-height: 55vh;
    }

    .status-indicator {
        padding: 12px;
    }

    .status-icon {
        font-size: 1.8rem;
    }

    .status-text {
        font-size: 0.9rem;
    }
}

/* Taller portrait phones (e.g., iPhone Pro Max) */
@media (orientation: portrait) and (min-height: 800px) {
    .shutter-btn {
        bottom: 25%;
    }

    .controls {
        bottom: calc(var(--safe-area-bottom) + 25px);
    }

    .results-section {
        max-height: 50vh;
    }
}

/* Desktop - slightly more padding, max-width */
@media (min-width: 768px) {
    .container {
        max-width: 500px;
        margin: 0 auto;
        height: 100%;
        height: 100dvh;
        border-left: 1px solid #333;
        border-right: 1px solid #333;
    }

    header h1 {
        font-size: 1.3rem;
    }

    .shutter-btn {
        width: 80px;
        height: 80px;
    }

    .shutter-btn::before {
        width: 64px;
        height: 64px;
    }

    .results-section {
        max-height: 50vh;
    }
}

/* Landscape phone */
@media (orientation: landscape) and (max-height: 500px) {
    header {
        padding: 5px 15px;
        background: linear-gradient(to bottom, rgba(0,0,0,0.8) 0%, transparent 100%);
    }

    header h1 {
        font-size: 0.85rem;
    }

    header p {
        display: none;
    }

    #buildTimestamp {
        display: none !important;
    }

    /* Move shutter to right side in landscape */
    .shutter-btn {
        bottom: auto;
        top: 50%;
        left: auto;
        right: calc(var(--safe-area-bottom) + 30px);
        transform: translateY(-50%);
        width: 60px;
        height: 60px;
    }

    .shutter-btn::before {
        width: 48px;
        height: 48px;
    }

    .shutter-btn:active {
        transform: translateY(-50%) scale(0.92);
    }

    /* Move controls to left side in landscape */
    .controls {
        bottom: auto;
        top: 50%;
        left: calc(var(--safe-area-top) + 15px);
        right: auto;
        transform: translateY(-50%);
        flex-direction: column;
        gap: 10px;
        padding: 0;
        width: auto;
    }

    .controls .btn {
        padding: 8px 14px;
        font-size: 0.75rem;
    }

    /* Results as side panel in landscape */
    .results-section {
        top: 0;
        bottom: 0;
        left: auto;
        right: 0;
        width: 50vw;
        max-width: 350px;
        max-height: 100%;
        border-radius: 20px 0 0 20px;
        transform: translateX(100%);
        padding-top: calc(var(--safe-area-top) + 15px);
    }

    .results-section.show-failure {
        transform: translateX(0);
    }

    footer {
        bottom: auto;
        top: calc(var(--safe-area-top) + 45px);
        left: 15px;
        right: auto;
        width: auto;
    }

    footer p {
        font-size: 0.6rem;
    }
}

/* Very short landscape (e.g., iPhone SE landscape) */
@media (orientation: landscape) and (max-height: 380px) {
    .shutter-btn {
        width: 50px;
        height: 50px;
        right: calc(var(--safe-area-bottom) + 20px);
    }

    .shutter-btn::before {
        width: 40px;
        height: 40px;
    }

    .controls .btn {
        padding: 6px 10px;
        font-size: 0.7rem;
    }

    .results-section {
        width: 55vw;
    }
}

/* Tablet landscape */
@media (orientation: landscape) and (min-height: 500px) {
    .container {
        max-width: 100%;
    }

    .shutter-btn {
        bottom: 25%;
        width: 76px;
        height: 76px;
    }

    .shutter-btn::before {
        width: 60px;
        height: 60px;
    }
}
