:root {
  color-scheme: dark;
  --paper: #F2F0EB;
  --muted: #B8B8B8;
  --accent: #D9B77A;
  --line: #414141;
}
* { box-sizing: border-box; }
body { margin: 0; background: #181818; color: var(--paper); font: 1rem/1.5 system-ui, sans-serif; }
header, main, footer { width: min(1120px, 90%); margin: auto; }
header, .heading, nav { display: flex; align-items: center; }
header, .heading { justify-content: space-between; gap: 1rem; }
header { padding: 1.3rem 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.brand { font: bold 1.65rem Georgia, serif; }
.brand b { font: 650 .7rem system-ui, sans-serif; letter-spacing: .14em; color: var(--accent); }
nav { gap: 1.2rem; font-size: .9rem; }
main { padding: clamp(2rem, 5vw, 4.5rem) 0; }
.label, small, strong { font: 500 .71rem/1.5 ui-monospace, monospace; letter-spacing: .1em; text-transform: uppercase; }
.label, .brand b, h1 span { color: var(--accent); }
h1, h2, h3, figcaption { font-family: Georgia, serif; font-weight: 400; }
h1 { margin: .4rem 0; font-size: clamp(3.2rem, 8vw, 6.6rem); letter-spacing: -.055em; line-height: 1.05; }
.intro, article p, small, footer { color: var(--muted); }
section { margin-top: 2.5rem; }
.heading { margin-bottom: 1rem; }
h2 { margin: 0; font-size: 1.65rem; }
.grid, .shelves { display: grid; gap: 1rem; }
.grid { grid-template-columns: repeat(3, 1fr); }
figure { margin: 0; }
figcaption { padding-top: .65rem; font-size: 1.25rem; }
figcaption small { display: block; }
.shelves { grid-template-columns: repeat(2, 1fr); }
article { padding: 1.4rem; background: #252525; border: 1px solid var(--line); }
h3 { font-size: 1.7rem; margin: .55rem 0 .15rem; }
article p { margin: 0 0 1.2rem; }
strong { color: var(--accent); }
footer { padding: 1rem 0 2rem; border-top: 1px solid var(--line); font-size: .8rem; }
@media (max-width: 650px) {
  nav a { display: inline-flex; align-items: center; min-height: 44px; }
  .grid, .shelves { grid-template-columns: 1fr; }
  .heading { flex-wrap: wrap; }
}
.original-card { padding: 0; }
.original-card a { display: block; height: 100%; padding: 1.4rem; }
.original-card:hover { border-color: var(--accent); }
button { min-height: 44px; padding: .5rem 1rem; border: 1px solid var(--line); border-radius: 4px; background: #303030; color: var(--paper); font: inherit; cursor: pointer; }
button:hover, button:focus-visible { border-color: var(--accent); }
button:disabled { opacity: .6; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(min(100%, 180px),1fr)); gap: 1rem; margin: 1rem 0; }
.photo-grid img { display: block; width: 100%; aspect-ratio: 1.5; object-fit: contain; background: #252525; }
.photo-grid figcaption { overflow-wrap: anywhere; }
#originals { scroll-margin-top: 1rem; }
#album-form, #album-list { display: flex; flex-wrap: wrap; gap: .65rem; align-items: center; }
#album-name { max-width: 100%; padding: .7rem; font: inherit; }
#album-list button, #shoot-title { max-width: 100%; overflow-wrap: anywhere; }
#album-detail { margin-top: 1.5rem; }
#choices label { padding: .5rem; background: #252525; cursor: pointer; }
#choices label:has(:checked) { outline: 2px solid var(--accent); }
#edit-grid a { display: inline-block; padding: .65rem 0; color: var(--accent); overflow-wrap: anywhere; }
#saved figure:target { outline: 2px solid var(--accent); outline-offset: 3px; }
#compare { width: min(64rem, 94vw); max-height: 90vh; overflow: auto; background: #181818; color: var(--paper); border: 1px solid var(--line); padding: 1.25rem; }
#compare::backdrop { background: rgb(0 0 0 / 75%); }
#compare-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
#compare-pair img { display: block; width: 100%; height: min(48vh, 28rem); object-fit: contain; background: #111; }
#compare-pair figcaption { overflow-wrap: anywhere; }
#compare-controls { display: none; }
#compare-controls [aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
@media (max-width: 650px) {
  #compare-controls { display: flex; gap: .5rem; margin-bottom: .75rem; }
  #compare-pair { display: block; }
  #compare-pair[data-side="original"] figure:nth-child(2),
  #compare-pair[data-side="edit"] figure:first-child { display: none; }
  #compare-pair figcaption { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

#gallery [hidden] { display: none; }
#backup { width: min(34rem, 94vw); max-height: 90vh; overflow: auto; background: #181818; color: var(--paper); border: 1px solid var(--line); padding: 1.5rem; }
#studio::backdrop, #backup::backdrop { background: rgb(0 0 0 / 85%); }
.photo-grid button { margin: .2rem .2rem .2rem 0; }
#studio { width: 96vw; max-width: 1600px; height: 94dvh; max-height: 94dvh; padding: 0; overflow: hidden; background: #252525; color: var(--paper); border: 1px solid var(--line); border-radius: 10px; }
#studio[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
#studio h2, #studio h3, #studio figcaption { font-family: system-ui, sans-serif; letter-spacing: normal; }
.editor-topbar { display: flex; align-items: center; gap: 1.5rem; padding: .85rem 1.2rem; border-bottom: 1px solid var(--line); }
.editor-brand { color: var(--accent); font-size: .65rem; letter-spacing: .15em; }
#studio h2 { font-size: 1rem; font-weight: 600; }
#studio-name { flex: 1; color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-workspace { display: grid; grid-template-columns: minmax(0, 1fr) 320px; min-height: 0; }
.editor-canvas { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; padding: 1rem; background: #121212; }
.editor-toolbar { display: flex; justify-content: space-between; gap: .5rem; padding-bottom: .8rem; flex-wrap: wrap; }
.preview-switch { display: flex; gap: .25rem; }
#studio button { font-size: .8rem; }
.preview-switch [aria-pressed="true"] { background: #353027; border-color: var(--accent); color: var(--accent); }
#studio-pair { overflow: auto; min-height: 0; min-width: 0; }
#studio-pair figure { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr); }
#studio-pair[data-view="original"] figure:last-child, #studio-pair[data-view="preview"] figure:first-child { display: none; }
#studio-pair figcaption { font-size: .65rem; color: var(--muted); padding: 0 0 .5rem; }
#studio-pair img { display: block; width: 100%; height: 100%; min-height: 0; object-fit: contain; }
#studio-pair.actual-size figure { width: max-content; height: max-content; display: block; }
#studio-pair.actual-size img { width: auto; height: auto; max-width: none; }
#view-hint { color: var(--muted); font-size: .75rem; margin: .7rem 0 0; }
.editor-sidebar { overflow-y: auto; min-width: 0; border-left: 1px solid var(--line); padding: 0 1.1rem 1rem; }
.sidebar-intro { padding: .8rem 0; }
#studio h3 { font-size: .95rem; font-weight: 600; }
.sidebar-intro p, .detail-help { color: var(--muted); font-size: .75rem; margin: .4rem 0; }
.edit-section { border-top: 1px solid var(--line); padding: .25rem 0; }
.edit-section summary { cursor: pointer; font-size: .85rem; font-weight: 600; padding: .6rem 0; }
.light-control { display: grid; grid-template-columns: 1fr auto; align-items: center; margin: 0 0 .15rem; gap: 0 .5rem; }
.light-control label { font-size: .78rem; }
.light-entry { display: flex; align-items: center; gap: .1rem; }
.light-entry input { width: 3.6rem; padding: .3rem; border: 1px solid #414141; background: #1C1C1C; color: var(--paper); font: .78rem system-ui; border-radius: 4px; }
#studio .light-entry button { min-width: 28px; min-height: 32px; padding: .1rem; background: transparent; border-color: transparent; }
.light-control input[type="range"] { grid-column: 1 / -1; width: 100%; min-height: 26px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.edit-section label { font-size: .8rem; }
#presets, #preset-name, #command { display: block; width: 100%; font: .85rem system-ui; padding: .6rem; margin: .5rem 0; background: #1C1C1C; color: var(--paper); border: 1px solid var(--line); border-radius: 4px; }
#name-recipe { margin-top: 1rem; }
.editor-bottom-bar { display: flex; align-items: center; gap: .6rem; border-top: 1px solid var(--line); padding: .7rem 1rem; }
#studio-status { flex: 1; font-size: .75rem; color: var(--muted); margin: 0; }
#save-enhanced { background: var(--accent); color: #211C14; border-color: var(--accent); font-weight: 600; }
#studio :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 700px) {
  #studio { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .editor-topbar { padding: .5rem .7rem; gap: .5rem; flex-wrap: wrap; }
  .editor-topbar > div { flex: 1; }
  #studio-name { order: 3; flex-basis: 100%; margin: 0; }
  .editor-workspace { grid-template-columns: 1fr; grid-template-rows: minmax(0, 3fr) minmax(0, 1fr); }
  .editor-sidebar { border-left: 0; border-top: 1px solid var(--line); }
  .editor-canvas { padding: .5rem; }
  #view-hint { display: none; }
  .editor-bottom-bar { flex-wrap: wrap; padding: .5rem; }
  #studio-status { flex-basis: 100%; }
  #studio .light-entry button { min-width: 44px; min-height: 44px; }
  .light-control input[type="range"] { min-height: 44px; }
}

#ai-edit-prompt { display: block; width: 100%; resize: vertical; min-height: 8rem; margin: .5rem 0; padding: .65rem; background: #1C1C1C; color: var(--paper); border: 1px solid var(--line); border-radius: 4px; font: .85rem/1.5 system-ui, sans-serif; }
.ai-setup-badge { display: inline-block; margin: .3rem 0; padding: .25rem .5rem; border: 1px solid var(--line); border-radius: 4px; color: var(--accent); font-size: .72rem; }
.ai-setup-status { margin: .8rem 0; font-size: .75rem; }
.ai-setup-status div { display: flex; justify-content: space-between; gap: .5rem; padding: .3rem 0; }
.ai-setup-status dt { color: var(--muted); }
.ai-setup-status dd { margin: 0; }
#ai-generate { width: 100%; background: var(--accent); color: #211C14; }

/* Graphite & Champagne form surfaces and selection accents. */
input, textarea, select { accent-color: var(--accent); }
#album-name { background: #252525; color: var(--paper); border: 1px solid var(--line); border-radius: 4px; }
::selection { background: #D9B77A; color: #181818; }

#delete-photo { width: min(32rem, 94vw); max-height: 90dvh; overflow: auto; background: #252525; color: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 1.5rem; }
#delete-photo::backdrop { background: rgb(0 0 0 / 80%); }
#delete-name { overflow-wrap: anywhere; font-weight: 600; color: var(--accent); }
#delete-confirm { border-color: var(--accent); }

#hf-result-image { width: 100%; display: block; margin: .6rem 0; }
#hf-status, #hf-quote-summary { font-size: .8rem; overflow-wrap: anywhere; }
#hf-approval { padding: .6rem; border: 1px solid var(--accent); border-radius: 4px; }

/* iPhone layout: avoid keyboard zoom, respect the notch and keep controls reachable. */
[hidden] { display: none !important; }
.connection-status { color: var(--accent); font-size: .8rem; }
#app-help { border-top: 1px solid var(--line); padding-top: 1.5rem; }
#app-help p { color: var(--muted); }
#app-help summary { min-height: 44px; cursor: pointer; padding: .5rem 0; }
@media (max-width: 700px) {
  body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
  input, textarea, select, #studio .light-entry input, #presets, #preset-name, #command, #ai-edit-prompt { font-size: 16px; }
  #studio { margin: 0; inset: 0; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
  .editor-workspace { grid-template-rows: minmax(0, 3fr) minmax(0, 1fr); }
  .editor-sidebar, #studio-pair { overscroll-behavior: contain; }
  .editor-sidebar { min-height: 0; }
  .sidebar-intro { display: none; }
  .editor-bottom-bar button { flex: 1; }
  #studio-status { max-height: 3.2em; overflow-y: auto; }
  #studio .edit-section summary { min-height: 44px; }
  .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .photo-grid button { width: 100%; margin: .25rem 0; padding: .5rem; }
  .photo-grid figcaption { font-size: 1rem; }
  #choices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #choices input { width: 24px; height: 24px; }
}
@media (max-height: 500px) and (max-width: 950px) {
  .editor-workspace { grid-template-columns: minmax(0, 1fr) minmax(250px, 42%); grid-template-rows: minmax(0, 1fr); }
  #studio-name, .editor-brand { display: none; }
}

/* Recent imports open the existing editor without creating another library copy. */
.recent-help { color: var(--muted); margin: 0 0 1rem; }
#gallery-photos { grid-template-columns: repeat(3, minmax(0, 1fr)); }
#gallery-photos .recent-photo, #added-grid .recent-photo { display: block; min-width: 0; margin: 0; padding: 0; overflow: hidden; text-align: left; background: #252525; }
.recent-photo:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.recent-name { display: block; padding: .65rem .8rem 0; overflow-wrap: anywhere; font: 1.1rem/1.4 Georgia, serif; }
.recent-action { display: block; padding: .25rem .8rem .75rem; color: var(--accent); font-size: .8rem; }
#gallery-empty { padding: 1.25rem; border: 1px dashed var(--line); border-radius: 6px; }
#gallery-empty p { margin-top: 0; color: var(--muted); }
@media (max-width: 650px) { #gallery-photos { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Keep the photograph prominent; editor naming remains available to assistive tech. */
#studio[open] { grid-template-rows: minmax(0, 1fr) auto; }
.editor-accessible-heading { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.editor-toolbar { flex-wrap: nowrap; gap: .5rem; padding-bottom: .4rem; }
.editor-toolbar .preview-switch { min-width: 0; gap: .25rem; }
#studio .editor-toolbar button { white-space: nowrap; padding: .4rem .65rem; min-width: 44px; }
@media (max-width: 700px) {
  .editor-toolbar { gap: .25rem; }
  #studio .editor-toolbar button { font-size: .75rem; padding: .35rem .4rem; }
  #studio .editor-bottom-bar button { padding: .5rem .35rem; white-space: nowrap; }
}

.import-primary { background: var(--accent); color: #211c14; font-weight: 650; }
#recent-add { margin-top: 1rem; padding: .75rem 1.6rem; }
#review, #just-added { padding: 1rem; border: 1px solid var(--line); border-radius: 6px; }
#added-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 155px), 1fr)); }
#added-grid .recent-photo:only-child { max-width: 20rem; }
