.photo-page {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    background: #f5f5f5;
    font-weight: 800;
}

.photo-page [hidden] { display: none !important; }
.photo-page button, .photo-page a { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.photo-page :focus-visible { outline: 3px solid #9a5700; outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.photo-header {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: min(100%, 480px);
    min-height: 62px;
    margin: 0 auto;
    padding: 6px 16px;
}

.help-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    color: #111;
    background: transparent;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
}

.help-button { min-width: 78px; padding: 0 12px; border: 3px solid #111; border-radius: 14px; background: #fff; }

.photo-main {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: 0 12px 14px;
}

.photo-preview {
    position: relative;
    flex: none;
    min-height: 0;
    min-width: 0;
    box-sizing: content-box;
    width: calc(100% - 8px);
    aspect-ratio: 3 / 4;
    border: 4px solid #111;
    border-radius: 22px;
    background: #e6e6e6;
    overflow: hidden;
}

/* The preview is sized to the photograph, so no letterbox sits inside the border. */
.photo-preview canvas, .photo-preview > img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.preview-cover {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px;
    background: #e6e6e6;
    border-radius: 18px;
}

#previewMessage { font-size: 0.95rem; }
#photoStatus { max-width: 26em; color: #666; font-size: 0.8rem; line-height: 1.7; font-weight: 500; }
.result-notice { position: absolute; bottom: 12px; left: 5%; width: 90%; padding: 12px; border-radius: 8px; background: #fff; color: #9a2921; font-size: 0.8rem; font-weight: 500; }

.photo-controls { flex: none; width: 100%; min-height: 76px; margin: 0 auto; }
.live-controls { display: grid; grid-template-columns: minmax(0, 2.15fr) minmax(0, 0.9fr) minmax(0, 1fr); gap: 8px; }
.photo-options { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); border: 4px solid #111; border-radius: 24px; background: #fff; }
.camera-actions { display: grid; min-width: 0; }
.result-actions { display: flex; border: 4px solid #111; border-radius: 24px; background: #fff; }
.photo-button {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-width: 0;
    min-height: 76px;
    padding: 6px 2px;
    border: 4px solid #111;
    border-radius: 22px;
    font: inherit;
    font-size: 0.875rem;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    color: #ff9800;
    background: #fff;
}

.photo-button.primary { background: #ff9800; color: #111; }
.photo-options .photo-button, .result-actions .photo-button { min-height: 68px; border: 0; border-radius: 0; }
.photo-options .photo-button:first-child, .result-actions .photo-button:first-child { border-radius: 19px 0 0 19px; }
.photo-options .photo-button:last-child, .result-actions .photo-button:last-child { border-radius: 0 19px 19px 0; }
.photo-options .photo-button + .photo-button, .result-actions .photo-button + .photo-button { border-left: 2px solid #111; }
.option-button { flex-direction: column; gap: 2px; }
.option-button small { font-size: 0.6875rem; color: #686868; font-weight: 500; }
.switch-camera span { line-height: 1.25; }
.photo-button:disabled { opacity: 0.45; cursor: default; }
@media (hover: hover) {
    .photo-button:hover:not(:disabled), .help-button:hover { background: #ffebcc; }
    .photo-button.primary:hover:not(:disabled) { background: #ffb84d; }
}

.help-dialog { width: min(440px, calc(100% - 32px)); max-height: calc(100dvh - 32px); margin: auto; padding: 22px; border: 4px solid #111; border-radius: 24px; background: #fff; color: #222; text-align: left; overflow: auto; }
.help-dialog::backdrop { background: #0008; }
.help-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.help-heading h2 { font-size: 1.15rem; color: #ff9800; }
.help-dialog ol { padding-left: 1.4em; font-size: 0.9rem; line-height: 1.8; font-weight: 500; }
.help-dialog li + li { margin-top: 12px; }
.help-dialog p { margin-top: 18px; color: #666; font-size: 0.75rem; line-height: 1.8; font-weight: 500; }
.help-dialog .help-credit { font-size: 0.65rem; }
.camera-source { position: fixed; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.noscript-message { position: fixed; inset: 20% 10% auto; background: #fff; padding: 20px; }

@media (orientation: landscape) and (max-height: 560px) {
    .photo-header { width: min(100%, 760px); min-height: 54px; padding-top: 4px; padding-bottom: 4px; }
    .photo-main { max-width: 760px; flex-direction: row; }
    .photo-controls { width: min(55%, 360px); margin: auto 0; }
    .photo-button { font-size: 0.75rem; }
    .preview-cover { gap: 8px; padding: 12px; }
    #previewMessage { font-size: 0.85rem; }
    #photoStatus { font-size: 0.75rem; }
}

@media (max-width: 380px) {
    .photo-button { font-size: 0.75rem; }
}
