html:has(#photo-studio[open]) { overflow: hidden; }
#studio-launch {
  display: none;
  position: fixed;
  z-index: 5;
  bottom: max(12px, env(safe-area-inset-bottom));
  min-height: 44px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: 2px;
  font-size: 13px;
  line-height: 1.3;
}
body[data-letter-state="sealed"] #studio-launch {
  display: block;
  left: 50%;
  transform: translateX(-50%);
  background: #333827e8;
  border-color: #e7e7ce50;
  color: #faf9ed;
}
body[data-photo-preview="true"][data-letter-state="open"] #studio-launch {
  display: block;
  right: max(12px, env(safe-area-inset-right));
  color: var(--olive);
  background: var(--paper);
  border-color: var(--rule);
  box-shadow: 0 1px 5px #3636261c;
}
body[data-letter-state="sealed"] #studio-launch:focus-visible { outline-color: #fff9e8; }

#photo-studio {
  --studio-ground: #f1f0e9;
  --studio-gutter: clamp(18px, 3.5vw, 32px);
  width: min(950px, calc(100% - 40px));
  max-width: none;
  max-height: min(92dvh, 820px);
  padding: 0;
  color: var(--ink);
  background: #faf9f5;
  line-height: 1.5;
  overflow: hidden;
}
#photo-studio[open] { display: flex; flex-direction: column; }
.studio-symbols { position: absolute; overflow: hidden; }
.studio-header, .studio-footer, .studio-setting, .studio-picker-heading,
.studio-slot-heading, .studio-formats { display: flex; align-items: center; }
.studio-header, .studio-footer { flex: none; padding-inline: var(--studio-gutter); }
.studio-header { justify-content: space-between; min-height: 68px; border-bottom: 1px solid var(--rule); }
#studio-title { margin: 0; font-size: clamp(19px, 3vw, 24px); font-weight: 600; letter-spacing: -.035em; }
[data-studio-close], .studio-file { min-height: 44px; color: var(--muted); font-size: 14px; }
[data-studio-close] { min-width: 44px; }
.studio-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(246px, 1fr);
  overflow: auto;
  overscroll-behavior: contain;
}
.studio-previews {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  align-items: start;
  gap: clamp(10px, 1.6vw, 18px);
  padding: 20px var(--studio-gutter) 28px;
  background: var(--studio-ground);
}
.studio-slot { min-width: 0; text-align: left; }
.studio-slot-heading {
  min-height: 44px;
  gap: 5px;
  color: var(--muted);
  font-size: 14px;
}
.studio-slot-heading::before {
  content: "";
  display: block;
  width: 13px;
  height: 13px;
  box-sizing: border-box;
  border: 1px solid #97988a;
  border-radius: 50%;
}
.studio-slot[aria-pressed="true"] .studio-slot-heading { color: var(--olive); }
.studio-slot[aria-pressed="true"] .studio-slot-heading::before {
  background: var(--olive);
  border-color: var(--olive);
  box-shadow: inset 0 0 0 2px var(--studio-ground);
}
.studio-slot-format { margin-left: auto; font-size: 11px; color: var(--muted); }
.studio-slot[data-format="landscape"] .studio-slot-format::after { content: "가로형"; }
.studio-slot[data-format="portrait"] .studio-slot-format::after { content: "세로형"; }
.studio-slot[data-format="full"] .studio-slot-format::after { content: "화면 가득"; }
.studio-paper {
  display: block;
  position: relative;
  width: 100%;
  aspect-ratio: var(--studio-screen-ratio, 393 / 852);
  container-type: size;
  background: var(--paper) var(--grain) repeat;
  box-shadow: 0 0 0 1px #c9c7bb, 0 2px 4px #38392a12;
}
.studio-slot[aria-pressed="true"] .studio-paper { outline: 2px solid var(--olive); outline-offset: 2px; }
.studio-print {
  display: block;
  position: absolute;
  inset: 0;
}
.studio-print [data-preview-photo] { display: block; width: 100%; height: 100%; object-fit: cover; }

.studio-slot[data-format="landscape"],
body[data-photo-preview][data-print-format="landscape"] { --studio-print-ratio: 1.739130435; }
.studio-slot[data-format="portrait"],
body[data-photo-preview][data-print-format="portrait"] { --studio-print-ratio: .8; }
body[data-photo-preview]:is([data-print-format="landscape"],[data-print-format="portrait"]) .opening-print {
  background: var(--paper) var(--grain) repeat;
  container-type: size;
}
.studio-slot:is([data-format="landscape"],[data-format="portrait"]) .studio-print,
body[data-photo-preview]:is([data-print-format="landscape"],[data-print-format="portrait"]) .opening-photo-link {
  position: absolute;
  inset: 50% auto auto 50%;
  translate: -50% -50%;
  width: min(100cqw, calc(100cqh * var(--studio-print-ratio)));
  height: auto;
  aspect-ratio: var(--studio-print-ratio);
  overflow: hidden;
}
.studio-signature {
  display: block;
  position: absolute;
  top: var(--studio-signature-top, 7%);
  left: var(--studio-signature-center, 50%);
  width: var(--studio-signature-width, 63%);
  translate: -50% 0;
}
.studio-signature img { display: block; width: 100%; }
.studio-editor { min-width: 0; padding: 22px var(--studio-gutter) 20px; border-left: 1px solid var(--rule); }
.studio-editor h3 { margin-bottom: 6px; font-size: 18px; font-weight: 600; }
.studio-setting, .studio-picker-heading { justify-content: space-between; gap: 12px; }
.studio-setting { min-height: 46px; font-size: 14px; }
.studio-formats { gap: 2px; }
.studio-formats button {
  min-width: 49px;
  min-height: 44px;
  padding-inline: 5px;
  color: var(--muted);
}
.studio-formats button[aria-pressed="true"] {
  color: var(--olive);
  font-weight: 650;
  text-decoration: underline;
  text-underline-offset: 5px;
  text-decoration-thickness: 2px;
}
#studio-position { width: 52%; height: 34px; margin: 0; accent-color: var(--olive); }
.studio-picker-heading { margin-top: 9px; border-top: 1px solid var(--rule); }
.studio-picker-heading h4 { font-size: 14px; font-weight: 600; }
.studio-file {
  position: relative;
  display: inline-flex;
  align-items: center;
  color: var(--olive);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.studio-file input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.studio-file:focus-within { outline: 2px solid var(--olive); outline-offset: 2px; }
#studio-gallery {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  max-height: 232px;
  padding: 3px;
  margin: -3px;
  overflow: auto;
  scrollbar-color: #aaa898 transparent;
  scrollbar-width: thin;
}
#studio-gallery button {
  display: block;
  position: relative;
  min-width: 0;
  aspect-ratio: 1;
  background: var(--studio-ground);
}
#studio-gallery img { display: block; width: 100%; height: 100%; object-fit: cover; }
#studio-gallery button[aria-pressed="true"] { outline: 2px solid var(--olive); outline-offset: 1px; }
#studio-gallery button[aria-pressed="true"]::after {
  content: "✓";
  position: absolute;
  bottom: 3px;
  right: 3px;
  width: 16px;
  line-height: 16px;
  color: #fff;
  background: var(--olive);
  border-radius: 50%;
  font-size: 12px;
}
.studio-device-note { margin-top: 9px; font-size: 12px; color: var(--muted); }
.studio-footer {
  justify-content: flex-end;
  gap: 12px;
  padding-block: 12px;
  border-top: 1px solid var(--rule);
}
#studio-status { flex: 1; margin: 0; font-size: 13px; }
#studio-status:empty { display: none; }
.studio-apply { padding: 0 24px; min-height: 44px; background: var(--olive); color: white; font-weight: 550; font-size: 15px; }
.studio-apply:disabled { opacity: .55; cursor: wait; }

@media (max-width: 670px) {
  #photo-studio {
    --studio-gutter: clamp(14px, 4.5vw, 24px);
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border: 0;
  }
  .studio-header { min-height: 53px; padding-top: env(safe-area-inset-top); }
  .studio-workspace { display: block; flex: 1; min-height: 0; }
  .studio-previews { padding-block: 4px 16px; border-bottom: 1px solid var(--rule); gap: 12px; }
  .studio-editor { border: 0; padding-block: 14px; }
  .studio-editor h3 { margin-bottom: 2px; font-size: 16px; }
  .studio-setting { min-height: 40px; }
  #studio-position { max-width: 180px; }
  .studio-picker-heading { margin-top: 4px; }
  #studio-gallery {
    grid-template-columns: none;
    grid-template-rows: repeat(2, auto);
    grid-auto-flow: column;
    grid-auto-columns: clamp(51px, 15.8vw, 74px);
    max-height: none;
    overflow-y: hidden;
    padding-bottom: 5px;
  }
  .studio-footer { flex-direction: column; align-items: stretch; gap: 6px; padding-block: 8px max(8px, env(safe-area-inset-bottom)); }
  .studio-apply { width: 100%; }
}
