:root {
  color-scheme: dark;
  font: 14px/1.45 system-ui, sans-serif;
  background: #101b25;
  color: #f3f0e9;
  --line: #3d4d5d;
  --muted: #bdc8d3;
  --surface: #1b2a38;
  --gold: #f1d19a;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100vh; height: 100dvh; margin: 0; overflow: hidden; }
button, select, summary { min-height: 42px; padding: .5rem .75rem; border: 1px solid var(--line); border-radius: 7px; font: inherit; color: inherit; background: var(--surface); }
button, summary { cursor: pointer; }
button:disabled, select:disabled, fieldset:disabled { opacity: .5; }
button:disabled { cursor: default; }
button:hover:enabled, summary:hover { background: #283b4c; }
button.primary { color: #271e10; background: var(--gold); border-color: var(--gold); font-weight: 650; }
button.primary:hover:enabled { background: #ffe0a9; }
:is(a, button, summary, select, input):focus-visible { outline: 2px solid #ffdfa6; outline-offset: 3px; }
a { color: var(--gold); text-underline-offset: .2em; }

.studio-header { display: flex; align-items: center; gap: .85rem; min-width: 0; padding: .7rem 1.15rem; border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: .5rem; font-weight: 700; text-decoration: none; }
.brand img { display: block; }
h1 { margin: 0; padding-inline-start: .85rem; border-inline-start: 1px solid var(--line); font-size: 1.05rem; font-weight: 600; }
.header-actions { display: flex; gap: .5rem; align-items: center; margin-inline-start: auto; }
.more-tools { position: relative; }
.more-tools summary { display: flex; align-items: center; gap: .65rem; list-style: none; }
.more-tools summary::-webkit-details-marker { display: none; }
.more-tools summary::after { content: "⌄"; }
.more-tools[open] summary { background: #283b4c; }
.more-menu { position: absolute; z-index: 3; inset: calc(100% + .4rem) 0 auto auto; width: 15.5rem; padding: .4rem; display: grid; gap: .25rem; border: 1px solid var(--line); border-radius: 8px; background: #142331; box-shadow: 0 10px 30px #0007; }
.more-menu :is(button, a) { display: flex; align-items: center; width: 100%; text-align: start; min-height: 42px; padding: .55rem .7rem; border: 0; color: inherit; background: transparent; text-decoration: none; border-radius: 5px; }
.more-menu a:hover { background: #283b4c; }

main { min-height: 0; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) 290px; }
.preview { display: flex; justify-content: center; align-items: center; position: relative; min-width: 0; min-height: 0; padding: 1.5rem; background: #080f15; overflow: hidden; }
.preview canvas { max-width: 100%; max-height: 100%; object-fit: contain; }
#empty { text-align: center; color: var(--muted); padding: 1rem; }
#empty h2 { margin: 0 0 .45rem; color: #f3f0e9; font-size: 1.3rem; font-weight: 500; }
#empty p { margin: 0; }
#dimensions { position: absolute; bottom: .6rem; left: 1rem; font-size: .85rem; color: var(--muted); }
.adjustment-panel { min-height: 0; overflow: auto; padding: 1rem; border-inline-start: 1px solid var(--line); scrollbar-width: thin; }
.preset-launch { display: flex; align-items: center; justify-content: space-between; width: 100%; margin-bottom: 1rem; border-color: #a98f62; color: var(--gold); }
.preset-launch small { color: var(--muted); font-size: .85rem; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { width: 100%; margin: 0 0 1.1rem; padding: 0; color: var(--gold); font-weight: 650; }
#adjustments label { display: block; margin: 0 0 1.1rem; }
#adjustments output { float: right; color: var(--muted); font-variant-numeric: tabular-nums; }
input[type=range] { display: block; width: 100%; margin: .65rem 0 0; accent-color: var(--gold); cursor: pointer; }
.crop-control { display: block; padding-block-start: .7rem; border-top: 1px solid var(--line); margin-bottom: .4rem; }
#crop { width: 100%; }
.edit-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; margin-top: .6rem; }
.edit-actions button { padding-inline: .3rem; font-size: .9rem; }
.reset { width: 100%; margin-top: .6rem; background: transparent; color: var(--muted); }
.download-actions { display: grid; grid-template-columns: 74px minmax(0, 1fr); gap: .4rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.download-actions :is(button, select) { min-width: 0; padding-inline: .45rem; }
footer { min-width: 0; min-height: 2.6rem; display: flex; align-items: center; padding: .5rem 1.15rem; border-top: 1px solid var(--line); font-size: .9rem; color: var(--muted); }
#status { overflow-wrap: anywhere; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

dialog { color: inherit; border: 1px solid var(--line); border-radius: 12px; background: #101b25; box-shadow: 0 20px 70px #0009; }
dialog::backdrop { background: #040b12cc; }
#preset-dialog { width: min(1000px, calc(100% - 2rem)); height: min(790px, calc(100dvh - 2rem)); max-height: calc(100dvh - 2rem); padding: 0; }
#preset-dialog[open] { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; }
.preset-heading { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .9rem 1.1rem; }
.preset-heading h2 { margin: 0; font-size: 1.2rem; font-weight: 600; }
.preset-heading button { width: 42px; padding: 0; font-size: 1.4rem; }
.preset-filters { display: grid; grid-template-columns: minmax(0, 1fr) minmax(145px, .4fr); gap: .6rem; padding: 0 1.1rem .85rem; }
.preset-filters input, #preset-name { min-width: 0; width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: inherit; font: inherit; padding: .5rem .75rem; }
.preset-results { min-height: 0; overflow: auto; padding: 0 1.1rem 1.1rem; scrollbar-width: thin; }
#preset-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .65rem; }
.preset-card { padding: 0; min-width: 0; overflow: hidden; text-align: left; }
.preset-card[aria-pressed=true] { outline: 2px solid var(--gold); outline-offset: -2px; }
.preset-card canvas { display: block; width: 100%; height: 112px; object-fit: contain; background: #080f15; }
.preset-card span { display: block; overflow-wrap: anywhere; padding: .5rem .55rem; font-size: .9rem; }
#preset-empty { color: var(--muted); text-align: center; }
.preset-footer { display: grid; grid-template-columns: minmax(130px, 1fr) minmax(0, 1fr) auto; gap: 1rem; align-items: center; border-top: 1px solid var(--line); padding: .9rem 1.1rem; }
.preset-strength label { display: block; font-size: .9rem; }
.preset-strength output { float: right; color: var(--muted); }
.preset-strength input { margin-top: .4rem; }
.preset-selection { display: grid; gap: .2rem; overflow-wrap: anywhere; }
#preset-count { color: var(--muted); }
#preset-save-dialog { width: min(420px, calc(100% - 2rem)); padding: 0 1.1rem 1.1rem; }
#preset-save-dialog .preset-heading { padding-inline: 0; }
#preset-save-dialog label { display: block; margin-bottom: .4rem; }
#preset-save-dialog p { color: var(--muted); font-size: .9rem; }
#preset-save-dialog button[type=submit] { width: 100%; }
#preset-save-error { color: #ffc5b5 !important; }
#preset-save-error:empty { margin: 0; }

@media (max-width: 700px) {
  .studio-header { gap: .55rem; padding: .55rem .75rem; flex-wrap: wrap; }
  .brand span { display: none; }
  h1 { border: 0; padding: 0; }
  button, select, summary { min-height: 44px; }
  main { grid-template-columns: 1fr; grid-template-rows: minmax(130px, 1fr) minmax(0, 310px); }
  .preview { padding: 1.25rem; }
  .adjustment-panel { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; border-inline-start: 0; border-top: 1px solid var(--line); padding: .8rem; }
  #controls { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; min-height: 0; overflow: auto; scrollbar-width: thin; }
  legend, #adjustments { grid-column: 1 / -1; }
  legend { margin-bottom: .5rem; }
  #adjustments { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem 1rem; }
  #adjustments label { margin-bottom: .45rem; }
  .crop-control { display: none; }
  .edit-actions { margin: 0; }
  .reset { grid-column: 1 / -1; margin: 0; }
  .download-actions { margin-top: .65rem; padding-top: .65rem; }
  .preset-launch { margin-bottom: .65rem; }
  footer { padding-inline: .75rem; font-size: .8rem; }
}

@media (max-width: 540px) {
  #preset-dialog { width: calc(100% - 1rem); height: calc(100dvh - 1rem); max-height: calc(100dvh - 1rem); }
  .preset-heading { padding: .65rem .75rem; }
  .preset-filters { grid-template-columns: minmax(0, 1fr); padding: 0 .75rem .65rem; gap: .4rem; }
  .preset-results { padding-inline: .75rem; }
  #preset-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
  .preset-card canvas { height: 102px; }
  .preset-footer { grid-template-columns: minmax(0, 1fr) auto; gap: .6rem; padding: .75rem; }
  .preset-strength { grid-column: 1 / -1; }
}

@media (max-width: 380px) {
  .header-actions { width: 100%; }
  #open { flex: 1; }
  .more-tools { flex: 1; }
  .more-tools summary { justify-content: center; }
  .edit-actions, #crop { grid-column: 1 / -1; }
}
