/* CSS Variables */
:root {
    --bg-dark: #1a1a2e;
    --bg-card: #16213e;
    --accent: #e94560;
    --accent-light: #ff6b6b;
    --text-primary: #eee;
    --text-secondary: #aaa;
    --success: #4ade80;
    --warning: #fbbf24;
    --error: #ef4444;
    --sun-color: #ffd700;
    --sun-glow: rgba(255, 215, 0, 0.3);
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
    height: -webkit-fill-available;
    overflow: hidden;
}

body {
    height: 100%;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.5;
    /* Prevent text size adjustment */
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Screen Management */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
}

.screen.active {
    display: flex;
}

.screen-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    text-align: center;
}

/* Typography */
h1 {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--sun-color), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

h2 {
    font-size: 1.75rem;
    margin-bottom: 1rem;
}

.tagline {
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.description {
    max-width: 320px;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

/* Buttons */
.btn-primary, .btn-secondary {
    padding: 1rem 2rem;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
    min-width: 200px;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--text-secondary);
    margin-top: 1rem;
}

.btn-icon {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Permission List */
.permission-list {
    width: 100%;
    max-width: 320px;
    margin: 2rem 0;
}

.permission-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-card);
    border-radius: 12px;
    margin-bottom: 0.75rem;
}

.permission-icon {
    font-size: 1.5rem;
}

.permission-info {
    flex: 1;
    text-align: left;
    display: flex;
    flex-direction: column;
}

.permission-status {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.permission-item.granted .permission-status {
    color: var(--success);
}

.permission-item.denied .permission-status {
    color: var(--error);
}

.permission-note {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 1rem;
}

/* Calibration */
.calibration-step {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    text-align: left;
    margin-bottom: 1rem;
    max-width: 320px;
}

.step-number {
    background: var(--accent);
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    flex-shrink: 0;
}

#calibration-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: black;
    z-index: 50;
}

#calibration-overlay.hidden {
    display: none;
}

#calibration-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;  /* Video behind everything else */
}

.calibration-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem;
    padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0));
    background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
    z-index: 100;  /* Above video and crosshair */
}

#calibration-status {
    background: rgba(0, 0, 0, 0.7);
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    text-align: center;
}

#btn-calibration-action {
    margin-bottom: 0.5rem;
}

.crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    pointer-events: none;
    z-index: 50;  /* Above video, below controls */
}

.crosshair::before,
.crosshair::after {
    content: '';
    position: absolute;
    background: var(--accent);
}

.crosshair::before {
    top: 50%;
    left: 0;
    right: 0;
    height: 2px;
    transform: translateY(-50%);
}

.crosshair::after {
    left: 50%;
    top: 0;
    bottom: 0;
    width: 2px;
    transform: translateX(-50%);
}

.edge-indicator {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--warning);
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 50;  /* Above video, below controls */
}

.edge-indicator.left {
    left: 20px;
}

.edge-indicator.right {
    right: 20px;
}

.edge-indicator.active {
    opacity: 1;
}

#calibration-status {
    position: relative;
    z-index: 10;
    background: rgba(0, 0, 0, 0.85);
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    text-align: center;
    max-width: 90%;
}

/* Camera Screen */
#camera-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

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

.camera-ui {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    pointer-events: none;
}

.camera-top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: linear-gradient(to bottom, rgba(0,0,0,0.5), transparent);
    pointer-events: auto;
}

#orientation-display {
    display: flex;
    gap: 1rem;
    font-family: monospace;
    font-size: 0.875rem;
    background: rgba(0, 0, 0, 0.5);
    padding: 0.5rem 1rem;
    border-radius: 8px;
}

.camera-bottom-bar {
    display: flex;
    justify-content: center;
    padding: 2rem;
    background: linear-gradient(to top, rgba(0,0,0,0.5), transparent);
    pointer-events: auto;
}

.btn-capture {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: 4px solid white;
    background: transparent;
    cursor: pointer;
    position: relative;
    transition: transform 0.1s;
}

.btn-capture:active {
    transform: scale(0.95);
}

.capture-ring {
    position: absolute;
    top: 4px;
    left: 4px;
    right: 4px;
    bottom: 4px;
    border-radius: 50%;
    background: white;
    transition: transform 0.1s;
}

.btn-capture:active .capture-ring {
    transform: scale(0.9);
}

/* Result Screen */
.result-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: black;
    overflow: hidden;
    position: relative;
    /* Disable browser touch handling so we can do custom zoom */
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.zoom-wrapper {
    transform-origin: center center;
    transition: transform 0.1s ease-out;
    cursor: grab;
}

.zoom-wrapper.grabbing {
    cursor: grabbing;
}

#result-canvas {
    max-width: 100vw;
    max-height: 100%;
    display: block;
}

.zoom-hint {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.875rem;
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.3s;
}

.zoom-hint.hidden {
    opacity: 0;
}

.result-ui {
    background: var(--bg-dark);
    padding: 1rem;
}

.result-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.result-actions {
    display: flex;
    gap: 1rem;
}

.result-actions .btn-primary,
.result-actions .btn-secondary {
    flex: 1;
    min-width: auto;
    margin: 0;
}

/* Modal */
.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: 16px;
    max-width: 360px;
    text-align: center;
}

.modal-content h3 {
    margin-bottom: 1rem;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

#error-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

#error-actions .btn-primary,
#error-actions .btn-secondary {
    min-width: auto;
    margin: 0;
}

/* Debug Console */
.debug-console {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 40vh;
    background: rgba(0, 0, 0, 0.95);
    border-top: 2px solid #444;
    z-index: 9999;
    font-family: monospace;
    font-size: 11px;
    display: flex;
    flex-direction: column;
}

.debug-console.minimized {
    max-height: 30px;
}

.debug-console.minimized .debug-log {
    display: none;
}

.debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 8px;
    background: #333;
    border-bottom: 1px solid #555;
    flex-shrink: 0;
}

.debug-header span {
    color: #0f0;
    font-weight: bold;
}

.debug-header button {
    background: #555;
    border: none;
    color: #fff;
    padding: 2px 8px;
    margin-left: 8px;
    cursor: pointer;
    border-radius: 3px;
}

.debug-log {
    flex: 1;
    overflow-y: auto;
    padding: 4px;
    -webkit-overflow-scrolling: touch;
}

.debug-entry {
    padding: 2px 4px;
    border-bottom: 1px solid #333;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.debug-entry.log { color: #fff; }
.debug-entry.info { color: #0af; }
.debug-entry.warn { color: #fa0; }
.debug-entry.error { color: #f55; }
.debug-entry.debug { color: #a0f; }

.debug-time {
    color: #888;
    margin-right: 8px;
}

/* Utilities */
.hidden {
    display: none !important;
}

/* Safe area insets for notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
    .camera-top-bar {
        padding-top: calc(1rem + env(safe-area-inset-top));
    }

    .camera-bottom-bar {
        padding-bottom: calc(2rem + env(safe-area-inset-bottom));
    }
}
