:root { color-scheme: dark; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; color: #f7f3ea; background: #061525; --gold: #f5c542; --muted: #a9becb; }
* { box-sizing: border-box; }
body { margin: 0; min-width: 300px; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr); }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; border: 1px solid #426078; border-radius: 10px; color: inherit; background: #102d45; padding: 9px 12px; }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, .photo-layer:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.primary-button { background: var(--gold); border-color: var(--gold); color: #061525; font-weight: 800; }
.secondary-button { font-size: 12px; }
.camera-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: max(10px, env(safe-area-inset-top)) 18px 10px; border-bottom: 1px solid #284055; }
.camera-header h1 { font-size: 16px; margin: 0; }
.back-link { color: var(--muted); text-decoration: none; font-size: 13px; }
.header-tag { font-size: 12px; color: var(--gold); }
.camera-layout { width: 100%; max-width: 1400px; min-height: 0; margin: 0 auto; padding: 12px max(12px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); display: grid; grid-template-columns: minmax(0, 1fr) 350px; gap: 16px; }
.viewfinder { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; gap: 6px; }
.source-bar { display: flex; justify-content: center; gap: 8px; }
.source-bar button { padding: 7px 16px; font-size: 12px; }
#add-overlay-image, #add-shape, #add-text { flex-shrink: 0; padding: 8px 12px; font-size: 12px; }
#background-image { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; user-select: none; pointer-events: none; }
#background-image[hidden] { display: none; }
body[data-mode="image"] .camera-stage { background: #ddd; }
.stage-shell { min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center; background: #020b12; border-radius: 16px; overflow: hidden; border: 1px solid #284055; }
/* Fit the stage into the space remaining after the visible controls. */
.camera-stage { position: relative; flex: none; overflow: hidden; background: radial-gradient(ellipse at center, #234861, #0a1d2d); touch-action: none; }
#camera-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#camera-video.mirrored { transform: scaleX(-1); }
.camera-placeholder { position: absolute; z-index: 4; inset: 0; display: flex; align-items: center; justify-content: flex-start; flex-direction: column; padding: 12px 8px; background: linear-gradient(#061525ed, #06152540); text-align: center; pointer-events: none; }
.camera-placeholder[hidden] { display: none; }
.camera-placeholder button { pointer-events: auto; }
.camera-mark { font-size: 26px; color: var(--gold); }
.camera-placeholder h2 { font-size: 15px; margin: 4px 0; }
.camera-placeholder p { font-size: 11px; color: var(--muted); margin: 0 0 10px; }
.photo-layer { position: absolute; z-index: 2; height: auto; user-select: none; -webkit-user-select: none; touch-action: none; cursor: grab; transform-origin: center; }
.photo-layer.selected { outline: 2px dashed var(--gold); outline-offset: 4px; }
.photo-layer.dragging { cursor: grabbing; }
.photo-layer[hidden] { display: none; }
.credit-layer { position: absolute; z-index: 3; height: auto; pointer-events: none; user-select: none; transform: translate(-50%, -50%); }
.preview-badge { position: absolute; top: 7px; left: 50%; transform: translateX(-50%); white-space: nowrap; font-size: 10px; border-radius: 20px; background: #061525b3; padding: 4px 8px; color: #d9e6ec; pointer-events: none; z-index: 3; }
.camera-placeholder:not([hidden]) ~ .preview-badge { display: none; }
.shutter-bar { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 20px; }
.shutter-bar > .secondary-button { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.shutter-bar > .secondary-button:first-child { justify-self: end; }
.shutter-bar > .secondary-button:last-child { justify-self: start; }
.shutter-button { width: 58px; height: 58px; border-radius: 50%; background: transparent; padding: 4px; border: 2px solid var(--gold); flex: 0 0 58px; }
.shutter-button span { display: block; width: 100%; height: 100%; background: var(--gold); border-radius: 50%; }
.shutter-button span { display: grid; place-items: center; color: #061525; font-size: 12px; font-weight: 800; }
.shutter-button:active span { transform: scale(.84); }
.status { min-height: 1.5em; font-size: 11px; color: var(--muted); text-align: center; line-height: 1.5; margin: 0; overflow-wrap: anywhere; }
.status.error { color: #ffb0a7; }
.control-panel { overflow-y: auto; min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.control-section { padding: 12px; background: #0c2336; border: 1px solid #284055; border-radius: 14px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 4px; margin-bottom: 8px; }
.section-heading h2 { font-size: 13px; margin: 0; }
.section-heading span { font-size: 10px; color: var(--muted); }
.character-list { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
.character-choice { padding: 6px 2px; font-size: 9px; line-height: 1.3; background: #061525; border-color: #284055; }
.character-choice img { display: block; height: 45px; width: 100%; object-fit: contain; margin-bottom: 5px; }
.character-choice span { display: block; min-height: 2.6em; }
.placed-characters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.placed-choice { display: flex; align-items: center; gap: 5px; min-width: 0; height: 42px; padding: 4px; font-size: 10px; text-align: left; }
.placed-choice img { width: 28px; height: 30px; object-fit: contain; flex-shrink: 0; }
.placed-choice span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-slot { display: flex; align-items: center; justify-content: center; height: 42px; border: 1px dashed #426078; border-radius: 10px; color: var(--muted); font-size: 10px; }
button[aria-pressed="true"] { border-color: var(--gold); background: #f5c54215; color: var(--gold); }
.edit-actions { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.selected-name { flex: 1; min-width: 0; font-size: 11px; color: var(--gold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo-controls { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.logo-controls button { font-size: 11px; padding: 8px; }
.check-row { display: flex; align-items: center; gap: 4px; font-size: 10px; line-height: 1.3; }
.check-row input { accent-color: var(--gold); width: 18px; height: 18px; margin: 0; flex-shrink: 0; }
.photo-dialog { width: min(94vw, 680px); max-height: 94dvh; overflow: auto; border: 1px solid #426078; border-radius: 20px; padding: 20px; background: #0c2336; color: inherit; }
.photo-dialog::backdrop { background: #020b12db; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.dialog-heading h2 { font-size: 19px; margin: 0; color: var(--gold); }
#captured-photo { display: block; max-width: 100%; max-height: 62dvh; margin: 0 auto; border-radius: 12px; }
.photo-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 16px 0 10px; }
.credit-layer[hidden] { display: none; }
.shape-dialog { width: min(94vw, 620px); max-height: 92dvh; box-sizing: border-box; overflow: hidden; border: 1px solid #426078; border-radius: 18px; padding: 16px; background: #0c2336; color: inherit; }
.shape-dialog[open] { display: flex; flex-direction: column; gap: 10px; }
.shape-dialog::backdrop { background: #020b12db; }
.shape-dialog .dialog-heading { margin-bottom: 0; flex-shrink: 0; }
.shape-dialog .dialog-heading h2 { font-size: 17px; }
.nauru-shape-choice { border-color: var(--gold); color: var(--gold); font-size: 13px; flex-shrink: 0; }
.shape-filters { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); gap: 8px; flex-shrink: 0; }
.shape-filters label { min-width: 0; font-size: 11px; color: var(--muted); }
.shape-filters select, .shape-filters input { box-sizing: border-box; display: block; width: 100%; min-width: 0; margin-top: 4px; font: inherit; font-size: 16px; padding: 8px; border: 1px solid #426078; border-radius: 8px; background: #061525; color: #f7f3ea; }
.shape-message, .shape-note { margin: 0; font-size: 11px; color: var(--muted); flex-shrink: 0; }
.shape-results { min-height: 0; overflow: auto; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.shape-results button { font-size: 12px; padding: 10px 6px; overflow-wrap: anywhere; }
.shape-note { font-size: 9px; line-height: 1.5; }
@media (orientation: landscape) and (max-height: 450px) {
  .shape-dialog { padding: 10px; gap: 6px; }
  .shape-filters select, .shape-filters input { padding: 4px; }
  .shape-results button { padding: 7px 6px; }
  .nauru-shape-choice { padding: 6px; }
}

.placed-texts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-top: 6px; }
.placed-texts[hidden], #edit-text[hidden] { display: none; }
.placed-text-choice { min-width: 0; height: 28px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 4px 6px; font-size: 10px; text-align: left; }
.text-dialog { width: min(94vw, 650px); max-height: 92dvh; overflow: auto; box-sizing: border-box; border: 1px solid #426078; border-radius: 18px; padding: 16px; background: #0c2336; color: inherit; }
.text-dialog::backdrop { background: #020b12db; }
.text-dialog .dialog-heading { margin-bottom: 10px; }
.text-dialog .dialog-heading h2 { font-size: 17px; }
.text-preview-box { height: clamp(70px, 17dvh, 145px); display: flex; align-items: center; justify-content: center; padding: 10px; background: #061525; border: 1px solid #284055; border-radius: 12px; margin-bottom: 10px; }
#text-preview { display: block; max-width: 100%; max-height: 100%; object-fit: contain; }
.text-content-label, .text-options label { display: block; font-size: 12px; color: var(--muted); }
.text-dialog textarea, .text-dialog select { box-sizing: border-box; width: 100%; min-width: 0; display: block; margin-top: 4px; font: inherit; font-size: 16px; padding: 8px; border: 1px solid #426078; border-radius: 8px; background: #061525; color: #f7f3ea; }
.text-dialog textarea { resize: vertical; min-height: 60px; max-height: 180px; }
.text-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 10px 0; }
.text-color-option { display: flex !important; align-items: center; justify-content: space-between; gap: 6px; }
.text-color-option input { width: 52px; height: 34px; cursor: pointer; border: 1px solid #426078; border-radius: 6px; background: #061525; padding: 3px; }
.text-color-option input:disabled { opacity: .35; }
.text-outline-option { margin: 6px 0 10px; font-size: 12px; }
.text-editor-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; }
.text-editor-actions span { font-size: 10px; color: var(--muted); }
@media (orientation: landscape) and (max-height: 600px) {
  .placed-texts { margin-top: 4px; gap: 4px; }
  .placed-text-choice { height: 24px; padding: 3px 5px; font-size: 9px; }
}

.text-options .text-outline-option { display: flex; align-items: center; margin: 0; }
.text-preview-box[data-direction="vertical"] { height: clamp(100px, 25dvh, 210px); }

.control-section[hidden] { display: none; }
.tool-launcher, .tool-sheet-head { display: none; }
.material-actions { display: flex; gap: 8px; margin-top: 10px; }
.material-actions button { flex: 1; }
.tool-help { color: var(--muted); font-size: 11px; line-height: 1.5; margin: 10px 0 0; }
@media (max-width: 1100px), (pointer: coarse) {
  body { grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; --tool-dock-height: 64px; }
  .camera-header { padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left)); }
  .header-tag { display: none; }
  .camera-layout { display: block; padding: 6px max(8px, env(safe-area-inset-right)) 4px max(8px, env(safe-area-inset-left)); }
  .viewfinder { height: 100%; display: block; position: relative; }
  .stage-shell { height: 100%; width: 100%; }
  .source-bar { position: absolute; top: 10px; left: 0; right: 0; z-index: 5; }
  .source-bar button { padding: 8px 16px; background: #061525df; box-shadow: 0 2px 8px #0004; }
  .shutter-bar { position: absolute; bottom: 24px; left: 0; right: 0; gap: 16px; z-index: 5; }
  .shutter-bar .secondary-button { background: #061525df; box-shadow: 0 2px 8px #0004; }
  .shutter-button { background: #061525b3; }
  #camera-status { position: absolute; bottom: 2px; left: 4px; right: 4px; border-radius: 8px; background: #061525b3; padding: 2px 4px; font-size: 10px; z-index: 5; }
  .preview-badge { display: none; }
  .camera-placeholder { justify-content: center; padding: 54px 12px 100px; }
  .tool-launcher { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 8px max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); background: #061525; border-top: 1px solid #284055; z-index: 7; }
  .tool-launcher button { min-height: 44px; padding: 8px 6px; font-size: 13px; font-weight: 700; }
  .tool-launcher button[aria-expanded="true"] { background: #f5c54220; border-color: var(--gold); color: var(--gold); }
  .control-panel { display: block; position: fixed; left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); bottom: calc(var(--tool-dock-height) + 8px); max-height: calc(100dvh - var(--tool-dock-height) - 72px); max-width: 620px; margin: 0 auto; padding: 8px 12px 12px; background: linear-gradient(155deg, #0a2744fa, #061525fa); border: 1px solid #f5c54260; border-radius: 18px; box-shadow: 0 12px 36px #0007; z-index: 6; opacity: 0; visibility: hidden; transform: translateY(calc(100% + var(--tool-dock-height) + 16px)); pointer-events: none; transition: transform .24s ease, opacity .18s ease, visibility .24s; overscroll-behavior: contain; }
  body[data-tool-open] .control-panel { transform: translateY(0); opacity: 1; visibility: visible; pointer-events: auto; }
  .tool-sheet-head { display: block; touch-action: none; }
  .sheet-grip { height: 4px; width: 34px; border-radius: 4px; background: #6d8799; margin: 0 auto 5px; }
  .sheet-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
  .sheet-heading h2 { margin: 0; font-size: 15px; color: var(--gold); }
  .sheet-heading button { min-height: 36px; padding: 6px 12px; }
  .control-section { padding: 0; border: 0; background: transparent; border-radius: 0; }
  .section-heading { margin-bottom: 8px; }
  .section-heading h2 { font-size: 12px; }
  .section-heading span { font-size: 11px; }
  .character-list { gap: 6px; }
  .character-choice { padding: 8px 2px; font-size: 10px; }
  .character-choice img { height: 48px; }
  .character-choice span { min-height: 2.6em; }
  .placed-texts { margin-top: 8px; }
  .placed-text-choice { height: 40px; font-size: 12px; }
  .edit-actions { flex-wrap: wrap; }
  .selected-name { flex-basis: 100%; }
  .edit-actions button, .logo-controls button { min-height: 36px; padding: 7px 10px; }
  .logo-controls { gap: 8px; }
  .check-row { font-size: 11px; }
  .tool-help { margin-top: 8px; }
}
@media (max-height: 450px) and (max-width: 1100px), (max-height: 450px) and (pointer: coarse) {
  .camera-header { padding-top: max(5px, env(safe-area-inset-top)); padding-bottom: 5px; }
  .camera-placeholder { padding: 38px 8px 82px; }
  .camera-placeholder p, .camera-mark { display: none; }
  .camera-placeholder h2 { font-size: 12px; margin-bottom: 8px; }
  .camera-placeholder button { padding: 6px 10px; }
  .source-bar { top: 6px; }
  .source-bar button { padding: 6px 12px; font-size: 11px; }
  .shutter-bar { bottom: 22px; gap: 12px; }
  .shutter-button { width: 48px; height: 48px; flex-basis: 48px; }
  .shutter-bar .secondary-button { font-size: 11px; padding: 7px 10px; }
  .tool-launcher { padding-top: 5px; padding-bottom: max(5px, env(safe-area-inset-bottom)); }
  .tool-launcher button { min-height: 36px; padding: 6px; font-size: 12px; }
  .control-panel { padding: 5px 10px 10px; }
  .sheet-heading { margin-bottom: 6px; }
  .sheet-heading button { min-height: 30px; padding: 4px 10px; font-size: 11px; }
  .character-choice { padding: 4px 2px; font-size: 9px; }
  .character-choice img { height: 30px; margin-bottom: 3px; }
  .character-choice span { min-height: 1.3em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .section-heading { margin-bottom: 6px; }
  .material-actions { margin-top: 6px; }
  .material-actions button, #add-text { padding: 6px 10px; }
  .placed-choice, .empty-slot { height: 32px; }
  .placed-text-choice { height: 32px; }
  .placed-choice img { width: 22px; height: 24px; }
  .edit-actions { margin-top: 5px; gap: 5px; }
  .selected-name { flex-basis: auto; }
  .edit-actions button, .logo-controls button { min-height: 30px; font-size: 10px; padding: 5px 8px; }
  .logo-controls { margin-top: 6px; }
  .tool-help { font-size: 10px; margin-top: 6px; }
}
@media (prefers-reduced-motion: reduce) { .control-panel { transition: none; } }

/* Keep photo editing surfaces in SDR; source HDR gain maps stay out of the DOM. */
#background-image, .photo-layer, .credit-layer, #captured-photo, #text-preview { dynamic-range-limit: standard; }
