/* === Global Settings & Variables === */
:root {
    /* Color Palette */
    --primary-color: #0056b3;       /* Primary action blue */
    --primary-hover-color: #004494;  /* Darker blue for hover */
    --secondary-color: #6c757d;     /* Grey for secondary actions */
    --secondary-hover-color: #5a6268;/* Darker grey for hover */
    --success-color: #28a745;       /* Green for success/download */
    --success-hover-color: #218838; /* Darker green for hover */
    --danger-color: #dc3545;        /* Red for clear/errors (optional) */
    --danger-hover-color: #c82333;   /* Darker red */

    /* Backgrounds */
    --body-bg: #f4f7f9;             /* Lighter, softer body background */
    --container-bg: #ffffff;       /* White container background */
    --input-bg: #ffffff;
    --input-disabled-bg: #e9ecef;
    --readonly-bg: #f8f9fa;
    --disabled-bg: #adb5bd;

    /* Text Colors */
    --text-dark: #212529;          /* Main text */
    --text-medium: #495057;        /* Secondary text */
    --text-light: #6c757d;         /* Subtle text, status */
    --text-on-primary: #ffffff;    /* Text on primary color */
    --text-on-secondary: #ffffff;   /* Text on secondary color */
    --text-on-success: #ffffff;    /* Text on success color */
    --text-disabled: #6c757d;       /* Disabled button text */
    --link-color: var(--primary-color);

    /* Borders */
    --border-color: #ced4da;        /* Standard border */
    --border-light: #dee2e6;       /* Lighter border for dividers */
    --border-focus: #80bdff;        /* Focus ring color (matches Bootstrap) */

    /* Fonts */
    --font-primary: 'Roboto', -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    --font-monospace: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;

    /* Shadows & Radii */
    --box-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --box-shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --box-shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    --border-radius: 0.375rem; /* ~6px */
    --border-radius-lg: 0.5rem;  /* ~8px */
}

/* === Basic Reset & Global Styles === */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
    scroll-behavior: smooth;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    font-family: var(--font-primary);
    font-size: 16px; /* Base font size */
    line-height: 1.6;
    color: var(--text-dark);
    background-color: var(--body-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* === Layout Structure === */
header {
    padding: 1.5rem 1rem; /* Use rem for scalable padding */
    background-color: var(--primary-color);
    color: var(--text-on-primary);
    text-align: center;
    box-shadow: var(--box-shadow-md);
    flex-shrink: 0;
}

main.container {
    max-width: 800px; /* Slightly narrower */
    width: calc(100% - 2rem); /* Responsive width with padding */
    margin: 2rem auto; /* Use rem for consistent spacing */
    padding: 2rem;
    background: var(--container-bg);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--box-shadow-lg);
    flex-grow: 1;
}

footer {
    padding: 1.5rem 1rem;
    margin-top: auto;
    background-color: var(--medium-bg);
    color: var(--text-light);
    text-align: center;
    font-size: 0.875em; /* Slightly smaller footer text */
    flex-shrink: 0;
    width: 100%;
    border-top: 1px solid var(--border-light);
}

/* === Typography === */
header h1 {
    margin-bottom: 0.25em;
    font-weight: 700;
    font-size: 1.75em; /* Adjusted size */
}

.subtitle {
    font-weight: 300;
    opacity: 0.9;
    font-size: 1em;
}

.step-section h2 {
    display: flex;
    align-items: center;
    gap: 0.8em; /* Space between number and text */
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-light);
    color: var(--primary-color);
    font-weight: 700;
    font-size: 1.5em; /* Adjusted size */
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600; /* Semi-bold labels */
    color: var(--text-medium);
}

/* === Step Sections === */
.step-section {
    margin-bottom: 2.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-light);
}

.step-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.step-number {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 36px;
    height: 36px;
    background-color: var(--primary-color);
    color: var(--text-on-primary);
    border-radius: 50%;
    font-size: 1em;
    font-weight: bold;
    flex-shrink: 0;
}

/* === Buttons === */
.button-group {
    display: flex; /* Use flexbox for better alignment */
    flex-wrap: wrap; /* Allow wrapping on small screens */
    justify-content: center; /* Center buttons */
    gap: 0.75rem; /* Space between buttons */
    margin: 1.25rem 0 0.75rem 0;
}

button,
.button-download {
    display: inline-block;
    padding: 0.75rem 1.75rem; /* Adjusted padding */
    border: 1px solid transparent; /* Add border for consistency */
    border-radius: var(--border-radius);
    background-color: var(--secondary-color);
    color: var(--text-on-secondary);
    font-size: 1rem;
    font-weight: 500; /* Medium weight */
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    box-shadow: var(--box-shadow-sm);
}

button:hover:not(:disabled),
.button-download:hover {
    transform: translateY(-2px);
    box-shadow: var(--box-shadow-md);
}

button:focus-visible,
.button-download:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

button:active:not(:disabled),
.button-download:active {
    transform: translateY(0px);
    box-shadow: var(--box-shadow-sm);
}

button:disabled {
    background-color: var(--disabled-bg);
    color: var(--text-disabled);
    border-color: var(--disabled-bg);
    cursor: not-allowed;
    box-shadow: none;
}

.button-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: var(--text-on-primary);
}
.button-primary:hover:not(:disabled) {
    background-color: var(--primary-hover-color);
    border-color: var(--primary-hover-color);
}

.button-secondary {
    background-color: var(--secondary-color);
    border-color: var(--secondary-color);
    color: var(--text-on-secondary);
}
.button-secondary:hover:not(:disabled) {
    background-color: var(--secondary-hover-color);
    border-color: var(--secondary-hover-color);
}

/* Specific button styling if needed (e.g., clear button) */
#clearRedactBtn {
    background-color: var(--white-color);
    color: var(--danger-color);
    border-color: var(--danger-color);
}
#clearRedactBtn:hover:not(:disabled) {
    background-color: var(--danger-color);
    color: var(--white-color);
}

.button-download {
    background-color: var(--success-color);
    border-color: var(--success-color);
    color: var(--text-on-success);
}
.button-download:hover {
    background-color: var(--success-hover-color);
    border-color: var(--success-hover-color);
}

/* === Forms (Textarea) === */
textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-family: var(--font-monospace);
    font-size: 0.9em;
    line-height: 1.5;
    min-height: 140px; /* Slightly taller */
    resize: vertical;
    background-color: var(--input-bg);
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

textarea:focus {
    border-color: var(--primary-color);
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(0, 86, 179, 0.25);
}

textarea:disabled {
    background-color: var(--input-disabled-bg);
    cursor: not-allowed;
}

textarea#encryptedOutput {
    background-color: var(--readonly-bg);
    cursor: default;
}

/* === Camera and Canvas === */
.camera-area,
.canvas-container {
    display: flex; /* Center content */
    justify-content: center;
    align-items: center;
    flex-direction: column;
    margin-bottom: 1.25rem;
}

video,
canvas {
    display: block;
    border: 1px solid var(--border-light); /* Lighter border */
    background-color: #000; /* Black background often looks better for cameras */
    max-width: 100%;
    height: auto;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow-sm);
}

#redactionCanvas {
    cursor: crosshair;
    touch-action: none;
    background-color: var(--medium-bg); /* Background when empty */
}

/* === Status & Instructions Text === */
.status,
.instructions {
    margin-top: 0.75rem;
    color: var(--text-light);
    font-size: 0.95em;
    line-height: 1.5;
}

.status {
    text-align: center;
    font-style: italic;
    min-height: 1.5em; /* Prevent layout shifts */
}

.instructions {
    text-align: center; /* Center instructions */
    margin-bottom: 1rem;
}

#processStatus {
    font-weight: 500; /* Medium weight status */
    color: var(--text-medium);
}

/* === Responsive Adjustments === */
@media (max-width: 768px) {
    body { font-size: 15px; } /* Slightly smaller base font */

    main.container {
        margin: 1.5rem auto;
        padding: 1.5rem;
    }

    header h1 { font-size: 1.6em; }
    .step-section h2 { font-size: 1.3em; }

    .button-group { justify-content: center; } /* Ensure centered on wrap */
}

@media (max-width: 480px) {
    body { font-size: 14px; }

    main.container {
        margin: 1rem auto;
        padding: 1rem;
        width: calc(100% - 1.5rem);
    }

    header { padding: 1rem; }
    header h1 { font-size: 1.4em; }
    .subtitle { font-size: 0.9em; }

    .step-section h2 { font-size: 1.2em; margin-bottom: 1rem;}
    .step-number { width: 30px; height: 30px; font-size: 0.9em; }

    /* Ensure buttons stack nicely */
    .button-group {
         flex-direction: column;
         align-items: center;
    }
    .button-group button,
    .button-group .button-download {
        width: 90%; /* Consistent width for stacked buttons */
        padding: 0.8rem 1rem;
    }

    textarea { min-height: 100px; }
}