* { box-sizing: border-box; }
:root {
    color-scheme: dark;
    --orange: #ffab52;
    --red: #ff526e;
    --bg: #0d0d0d;
    --panel: #1a1a1a;
    --text: #ece9e4;
    --border: #3b3b39;
    --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}
html { -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
body {
    margin: 0; background: var(--bg); color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    min-height: 100vh; min-height: 100dvh; display: flex; justify-content: center;
    padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.container { width: 100%; max-width: 760px; margin: auto; }
.app-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.eyebrow, .edition, legend, .capture-hint { font-family: "Courier New", monospace; }
.eyebrow { margin: 0 0 8px; color: #aaa59f; font-size: 11px; letter-spacing: 1.5px; }
h1 { margin: 0; font-size: 28px; letter-spacing: 3px; color: var(--orange); }
h1.alternate-mode { color: var(--red); }
.edition { color: #aaa59f; font-size: 10px; letter-spacing: 1px; border: 1px solid var(--border); padding: 8px; border-radius: 4px; }
#webcam, #hiddenCanvas, #warpCanvas { display: none; }
.preview-box {
    position: relative; display: flex; align-items: center; justify-content: center;
    width: min(100%, calc(52dvh * var(--preview-aspect, 1.77778)));
    min-height: 180px; margin-inline: auto; max-width: 100%; border-radius: 12px; background: #000; overflow: hidden;
    box-shadow: 0 0 0 1px rgba(255,255,255,.12), 0 16px 48px rgba(0,0,0,.4);
}
#asciiCanvas, #pixelCanvas { display: none; max-width: 100%; width: 100%; height: auto; max-height: 52dvh; object-fit: contain; background: #000; }
#pixelCanvas { image-rendering: pixelated; }
.timestamp-stamp { position: absolute; bottom: 12px; right: 15px; font: bold 14px "Courier New", monospace; color: var(--orange); text-shadow: 0 0 4px #000; pointer-events: none; }
.timestamp-stamp.glitch { color: var(--red); }
.record-indicator { display: none; position: absolute; top: 12px; left: 12px; color: var(--red); font: bold 13px "Courier New", monospace; background: #000b; border-radius: 4px; padding: 6px 8px; }
.record-indicator.show { display: block; }
.camera-status { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; background: #111; text-align: center; gap: 8px; }
.camera-status[hidden], [hidden] { display: none !important; }
.camera-status p { max-width: 340px; margin: 0; color: #c9c5be; font-size: 14px; line-height: 1.7; }
.controls { display: grid; gap: 16px; margin-top: 24px; }
.effects-menu { position: relative; min-width: 0; z-index: 4; }
.effects-menu summary {
    display: flex; align-items: center; gap: 12px; min-height: 44px;
    padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--panel); cursor: pointer; list-style: none;
    touch-action: manipulation; user-select: none; -webkit-user-select: none;
    font-size: 14px;
}
.effects-menu summary::-webkit-details-marker { display: none; }
.effects-menu summary:focus-visible { outline: 2px solid var(--orange); outline-offset: 4px; }
.effects-menu summary:active { background: #32312f; }
.effects-summary { flex: 1; min-width: 0; text-align: right; color: #b9b4ab; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.effects-chevron { color: var(--orange); }
.effects-menu[open] .effects-chevron { transform: rotate(180deg); }
.effects-panel {
    position: absolute; bottom: calc(100% + 8px); inset-inline: 0;
    display: grid; gap: 16px; padding: 16px; border-radius: 12px;
    background: #171716; border: 1px solid #4b4841;
    box-shadow: 0 12px 40px #0009; max-height: min(360px, 60dvh);
    overflow-y: auto; overscroll-behavior: contain;
}
.effects-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.effects-heading .btn { color: var(--orange); }

.control-group { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 8px; color: #aaa59f; font-size: 11px; letter-spacing: 1px; }
.control-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn, .modal-action, .modal-close {
    min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--border); border-radius: 8px; background: var(--panel); color: #dedbd5;
    padding: 10px 16px; font: inherit; font-size: 14px; text-decoration: none; cursor: pointer;
    touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
    transition: transform 120ms var(--ease-out), background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}
.btn.active { background: #33271a; color: #ffc17a; border-color: #a86e30; }
.btn-accent { background: var(--orange); border-color: var(--orange); color: #17120b; font-weight: 600; flex: 1; }
.btn-record { border-color: #743241; color: #ff9aac; }
.btn-record.recording { background: #94243b; border-color: #ff748d; color: #fff; }
button:disabled, [aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--orange); outline-offset: 4px; transition: none; }
.btn:active:not(:disabled):not(:focus-visible), .modal-action:active:not(:disabled):not(:focus-visible), .modal-close:active:not(:focus-visible) { transform: scale(.97); }
@media (hover: hover) and (pointer: fine) {
    .btn:hover:not(:disabled), .modal-action:hover:not(:disabled), .modal-close:hover { background: #32312f; border-color: #777; }
    .btn-accent:hover:not(:disabled) { background: #ffc17a; color: #17120b; }
}
.capture-hint { margin: 0; color: #aaa59f; font-size: 11px; line-height: 1.7; }
.preview-box::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: #fff; opacity: 0; transition: opacity 160ms ease-out; }
.preview-box.flash::after { opacity: .35; transition-duration: 0ms; }
.modal {
    position: fixed; inset: 0; width: 100%; max-width: none; height: 100dvh; max-height: none; margin: 0; border: 0;
    color: var(--text); background: #0d0d0d; overscroll-behavior: contain; overflow-y: auto;
    padding: max(24px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}
.modal[open] { display: flex; flex-direction: column; align-items: center; justify-content: safe center; gap: 16px; }
.modal::backdrop { background: #000b; }
.modal img, .modal video { max-width: 100%; max-height: 65dvh; min-height: 0; object-fit: contain; border-radius: 8px; background: #000; }
.modal-tip { max-width: 480px; text-align: center; color: #c9c5be; font-size: 14px; line-height: 1.6; }
.modal-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; }
@media (max-width: 600px) and (orientation: portrait) {
    body {
        height: 100dvh;
        padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    }
    .container {
        height: 100%; min-height: 0; margin: 0;
        display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 12px;
    }
    .app-header { margin: 0; }
    .edition { display: none; }
    .eyebrow { margin-bottom: 4px; font-size: 10px; }
    h1 { font-size: 24px; }
    .preview-area { min-height: 0; container-type: size; display: grid; place-items: center; }
    .preview-box {
        width: min(100cqw, calc(100cqh * var(--preview-aspect, 0.5625)));
        aspect-ratio: var(--preview-aspect, 0.5625); min-height: 0;
    }
    #asciiCanvas, #pixelCanvas { width: 100%; max-height: none; }
    .camera-status { padding: 12px; overflow-y: auto; }
    .camera-status p { font-size: 12px; line-height: 1.5; }
    .controls { margin-top: 0; gap: 10px; }
    legend { margin-bottom: 4px; }
    .control-row { gap: 6px; }
    .control-row .btn { padding: 10px 12px; }
    .capture-group .control-row { display: grid; grid-template-columns: 1fr 1.4fr 1fr; }
    .capture-hint { font-size: 10px; line-height: 1.5; }
}
@media (prefers-reduced-motion: reduce) {
    .btn, .modal-action, .modal-close, .preview-box::after { transition: none; }
    .btn:active:not(:disabled), .modal-action:active:not(:disabled), .modal-close:active { transform: none; }
    .preview-box.flash::after { opacity: 0; }
}

/* Keep camera controls familiar and let the image take priority. */
.app-header { justify-content: center; }
h1 { color: #f5f5f7; font-size: 18px; font-weight: 600; letter-spacing: 0.12em; }
.edition { display: none; }
.preview-box { border-radius: 6px; box-shadow: none; }
.controls { gap: 8px; }
.effects-menu summary { width: fit-content; max-width: 100%; margin-inline: auto; border: 0; border-radius: 24px; background: #ffffff12; color: #fff; }
.effects-summary { flex: 0 1 auto; color: #ddd; }
.effects-panel { background: rgba(32,32,34,.94); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); border-color: #ffffff20; border-radius: 20px; }
.capture-modes { display: flex; justify-content: center; gap: 16px; }
.capture-mode {
    min-width: 64px; min-height: 44px; padding: 8px 12px; background: none; border: none;
    color: #c9c9cc; font: 600 14px -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.capture-mode.active { color: #ffd60a; }
.capture-mode:active { opacity: .65; }
.capture-bar { display: grid; grid-template-columns: 1fr 88px 1fr; align-items: center; justify-items: center; min-height: 88px; }
.shutter-slot { display: grid; place-items: center; width: 88px; height: 88px; }
.shutter {
    display: grid; place-items: center; width: 80px; height: 80px; padding: 4px;
    border: 3px solid #f5f5f7; border-radius: 50%; background: transparent;
    touch-action: manipulation; cursor: pointer;
}
.shutter-core { width: 64px; height: 64px; border-radius: 50%; background: #f5f5f7; transition: transform 100ms var(--ease-out); }
.shutter-video .shutter-core { background: #ff453a; }
.shutter-video.recording .shutter-core { width: 28px; height: 28px; border-radius: 6px; }
.shutter:active:not(:disabled):not(:focus-visible) .shutter-core { transform: scale(.92); }
.camera-icon-button, .gallery-button {
    width: 48px; height: 48px; display: grid; place-items: center; padding: 0; border: 0;
    background: #ffffff17; color: #f5f5f7; cursor: pointer; touch-action: manipulation;
    user-select: none; -webkit-user-select: none;
}
.camera-icon-button { border-radius: 50%; }
.gallery-button { border-radius: 8px; overflow: hidden; }
.gallery-button img { width: 100%; height: 100%; object-fit: cover; }
.gallery-button:has(img:not([hidden])) .gallery-placeholder { display: none; }
.camera-icon-button svg, .gallery-placeholder { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.camera-icon-button:active:not(:disabled), .gallery-button:active:not(:disabled) { background: #ffffff30; }
.capture-hint { text-align: center; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #a1a1a6; }
@media (max-width: 600px) and (orientation: portrait) {
    .container { gap: 8px; }
    h1 { font-size: 16px; }
    .controls { gap: 4px; }
}
@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
    .effects-panel { background: #242426; -webkit-backdrop-filter: none; backdrop-filter: none; border-color: #bbb; }
}
@media (prefers-reduced-motion: reduce) {
    .shutter-core { transition: none; }
    .shutter:active:not(:disabled) .shutter-core { transform: none; }
}
