.studio-page {
  min-height: 100dvh;
  overflow: hidden;
  background: #f4f5f6;
}

.studio-shell {
  display: grid;
  width: min(100%, 1540px);
  height: 100dvh;
  min-height: 680px;
  margin: 0 auto;
  padding: 16px 24px 18px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 48px minmax(0, 1fr) 70px;
  gap: 12px;
  overflow: visible;
}

.studio-brand {
  z-index: 2;
  display: flex;
  grid-row: 1;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.studio-brand img {
  display: block;
  width: min(240px, 44vw);
  height: auto;
  max-width: min(44vw, 280px);
  object-fit: contain;
}

.studio-shell > .poster-shape {
  display: none;
}

.studio-preview {
  grid-row: 2;
  display: flex;
  min-height: 0;
  height: 100%;
  max-height: none !important;
  gap: 12px;
  padding: 16px;
  overflow: hidden;
  border-radius: 22px;
  background: rgba(255, 254, 250, 0.96);
  backdrop-filter: none;
}

.studio-preview .preview-toolbar {
  flex: 0 0 auto;
}

.preview-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.preview-detail-trigger {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border: 1px solid rgba(205, 199, 189, 0.72);
  border-radius: 999px;
  background: #fffefa;
  color: #111;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 5px 14px rgba(35, 31, 27, 0.08);
}

.preview-detail-trigger:hover {
  border-color: #111;
  background: #fff;
}

.preview-detail-trigger:active {
  transform: scale(0.97);
}

.preview-detail-trigger .ui-icon {
  width: 18px;
  height: 18px;
}

.studio-preview .preview-toolbar h2 {
  gap: 8px;
  font-size: 22px;
}

.studio-preview .preview-toolbar h2 small {
  font-size: 13px;
}

.studio-preview #downloadBtn {
  min-height: 42px;
  padding-inline: 18px;
  box-shadow: 0 8px 20px rgba(5, 5, 5, 0.14);
}

.studio-preview .preview-home-host {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
}

.studio-preview .preview-home-host .paper-preview-shell {
  height: 100%;
  aspect-ratio: auto;
  border-radius: 16px;
  background: #f3f2ed;
}

.studio-preview .paper-frame {
  border-radius: inherit;
}

.preview-detail-open {
  overflow: hidden;
}

.preview-detail-modal {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: #e8e9eb;
}

.preview-detail-modal::backdrop {
  background: rgba(12, 13, 14, 0.38);
  backdrop-filter: blur(10px);
}

.preview-detail-surface {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  padding: max(76px, env(safe-area-inset-top)) 28px max(94px, calc(env(safe-area-inset-bottom) + 78px));
  place-items: center;
  overflow: hidden;
  background: #e8e9eb;
}

.preview-detail-close {
  position: fixed;
  top: max(22px, env(safe-area-inset-top));
  left: max(22px, env(safe-area-inset-left));
  z-index: 3;
  display: inline-grid;
  width: 46px;
  height: 46px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(17, 17, 17, 0.7);
  color: #fff;
  box-shadow: 0 10px 28px rgba(5, 5, 5, 0.18);
  backdrop-filter: blur(14px);
}

.preview-detail-close:hover {
  background: #111;
}

.preview-detail-close:active {
  transform: scale(0.94);
}

.preview-detail-close .ui-icon {
  width: 20px;
  height: 20px;
}

.preview-detail-canvas-host {
  display: grid;
  width: 100%;
  height: 100%;
  min-height: 0;
  place-items: center;
  overflow: hidden;
}

.preview-detail-canvas-host .paper-preview-shell {
  width: min(100%, calc((100dvh - 170px) * var(--paper-aspect, 1.4)));
  height: auto;
  aspect-ratio: var(--paper-aspect, 1.4);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(20, 22, 24, 0.16);
}

.preview-detail-canvas-host .paper-frame {
  border-radius: inherit;
}

.preview-detail-controls {
  position: fixed;
  bottom: max(22px, env(safe-area-inset-bottom));
  left: 50%;
  z-index: 3;
  transform: translateX(-50%);
}

.preview-detail-modal .preview-zoom-controls {
  position: static;
  width: max-content;
  border-color: rgba(255, 255, 255, 0.78);
  background: rgba(31, 32, 34, 0.72);
  color: #fff;
  box-shadow: 0 12px 36px rgba(5, 5, 5, 0.22);
  backdrop-filter: blur(18px);
}

.preview-detail-modal .preview-zoom-controls button {
  color: #fff;
}

.preview-detail-modal .preview-zoom-controls button:hover {
  background: rgba(255, 255, 255, 0.14);
  box-shadow: none;
}

.preview-detail-modal #zoomValue {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.studio-editor {
  z-index: 50;
  display: block;
  grid-row: 3;
  justify-self: center;
  width: min(900px, calc(100vw - 32px));
  min-height: 70px;
  height: 70px;
  padding: 6px;
  overflow: visible;
  border-radius: 999px;
  background: #fff;
  box-shadow:
    0 16px 42px rgba(0, 0, 0, 0.1),
    0 0 0 1px rgba(0, 0, 0, 0.14);
  backdrop-filter: none;
}

.studio-editor .editor-title {
  display: none;
}

.studio-editor .editor-section {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  left: 0;
  z-index: 80;
  display: none;
  max-height: min(350px, calc(100dvh - 190px));
  gap: 14px;
  margin: 0;
  padding: 18px;
  overflow: auto;
  scrollbar-width: none;
  overscroll-behavior: contain;
  border: 1px solid rgba(205, 199, 189, 0.66);
  border-radius: 20px;
  background: #fffefa;
  box-shadow: 0 20px 54px rgba(35, 31, 27, 0.17);
  animation: studio-panel-in 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.studio-editor .editor-section::-webkit-scrollbar {
  display: none;
}

.studio-editor .editor-section.is-open {
  display: grid;
}

.studio-panel-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  display: inline-grid;
  width: 34px;
  height: 34px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(5, 5, 5, 0.16);
  border-radius: 50%;
  background: #fffefa;
  color: #111;
  box-shadow: 0 5px 14px rgba(35, 31, 27, 0.09);
}

.studio-panel-close:hover {
  border-color: #111;
  background: #fff;
}

.studio-panel-close:active {
  transform: scale(0.94);
}

.studio-panel-close .ui-icon {
  width: 16px;
  height: 16px;
}

.studio-editor .editor-section > .section-title {
  padding-right: 46px;
}

.studio-editor [data-studio-panel="color"] {
  overflow: visible;
}

.studio-editor .section-title {
  gap: 8px;
}

.studio-editor .section-title strong {
  font-size: 17px;
}

.studio-editor .section-title small {
  font-size: 13px;
}

.studio-editor .avatar-workbench {
  grid-template-columns: minmax(220px, 280px) minmax(180px, 240px);
  justify-content: center;
  gap: 22px;
}

.studio-editor .portrait-stage {
  max-width: 280px;
}

.studio-editor .avatar-actions {
  align-content: center;
}

.studio-editor .color-row {
  justify-content: center;
  padding: 10px 0 4px;
}

.studio-editor .custom-color-menu {
  top: auto;
  right: 0;
  bottom: calc(100% + 10px);
  background: #fffefa;
  backdrop-filter: none;
}

.studio-editor .pattern-options {
  justify-content: center;
  padding: 8px 0 2px;
}

.studio-editor .text-controls {
  grid-template-columns: minmax(240px, 0.95fr) minmax(560px, 2.05fr);
  gap: 12px;
}

.studio-editor .text-controls textarea {
  min-height: 104px;
  border-color: rgba(205, 199, 189, 0.56);
  border-radius: 14px;
  background: transparent;
  box-shadow: none;
}

.studio-editor .copy-style-controls {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: minmax(72px, 1fr);
  gap: 10px;
}

.studio-editor .copy-option,
.studio-editor .copy-size-control {
  min-height: 72px;
  padding: 10px 12px;
  border-color: rgba(205, 199, 189, 0.56);
  border-radius: 14px;
}

.studio-font-options {
  width: 100%;
  margin: 6px auto 2px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.studio-font-options .font-option {
  min-height: 122px;
  padding: 16px;
  background: transparent;
}

.studio-font-options .font-option-preview {
  overflow: visible;
  font-size: 20px;
  line-height: 1.08;
  text-overflow: clip;
  white-space: normal;
}

.studio-font-options .font-option.active {
  background: #fff;
}

.studio-editor .paper-settings {
  grid-template-columns: minmax(270px, 1.2fr) minmax(210px, 1fr) minmax(210px, 1fr);
  gap: 20px;
  padding: 14px 0 8px;
}

.studio-editor .paper-settings .field-inline {
  min-height: 68px;
  border: 1px solid rgba(205, 199, 189, 0.66);
  border-radius: 16px;
  padding-inline: 16px;
}

.studio-editor .paper-settings #paperSizeSelect {
  width: 100%;
  font-size: 15px;
}

.studio-editor .slider-row {
  min-height: 68px;
}

.studio-tool-nav {
  display: grid;
  height: 58px;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 2px;
  align-items: stretch;
}

.studio-tool-nav button {
  position: relative;
  display: inline-flex;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #333;
  padding: 0 12px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: none;
}

.studio-tool-nav button:hover {
  background: rgba(5, 5, 5, 0.045);
  color: #1f1f1f;
}

.studio-tool-nav button.is-active {
  background: #111;
  color: #fff;
}

.studio-tool-icon,
.studio-tool-color,
.studio-tool-glyph {
  display: inline-grid;
  width: 20px;
  height: 20px;
  place-items: center;
  flex: 0 0 auto;
}

.studio-tool-color {
  border: 1.5px solid currentColor;
  border-radius: 50%;
  background: linear-gradient(135deg, #fae3e4 0 50%, #ebf1f7 50% 100%);
}

.studio-tool-glyph {
  font-family: Georgia, serif;
  font-size: 17px;
  font-weight: 700;
  line-height: 1;
}

.studio-tool-glyph-wide {
  font-size: 14px;
}

@keyframes studio-panel-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .studio-editor .editor-section {
    animation: none;
  }
}

@media (max-width: 900px) {
  .studio-page {
    overflow: auto;
  }

  .studio-shell {
    width: 100%;
    height: auto;
    min-height: 100dvh;
    padding: 12px;
    grid-template-rows: 42px minmax(520px, 68dvh) 66px;
    gap: 10px;
  }

  .studio-brand img {
    width: min(210px, 58vw);
    height: auto;
    max-width: 58vw;
  }

  .studio-preview {
    min-height: 520px;
    padding: 14px;
    border-radius: 20px;
  }

  .studio-preview .preview-toolbar {
    align-items: center;
    flex-direction: row;
  }

  .studio-preview .preview-toolbar h2 {
    font-size: 20px;
  }

  .studio-preview #downloadBtn {
    width: auto;
    min-height: 38px;
    padding-inline: 14px;
  }

  .preview-detail-trigger {
    min-height: 38px;
    padding-inline: 13px;
  }

  .preview-detail-surface {
    padding-inline: 18px;
  }

  .studio-editor {
    position: sticky;
    bottom: 10px;
    min-height: 66px;
    height: 66px;
    border-radius: 999px;
  }

  .studio-editor .editor-section {
    position: absolute;
    max-height: min(52dvh, 470px);
    padding: 16px;
    border-radius: 18px;
  }

  .studio-editor .avatar-workbench {
    grid-template-columns: minmax(180px, 250px) minmax(150px, 210px);
  }

  .studio-editor .text-controls {
    grid-template-columns: minmax(190px, 0.8fr) minmax(420px, 1.8fr);
  }

  .studio-editor .paper-settings {
    grid-template-columns: minmax(240px, 1.15fr) minmax(190px, 1fr) minmax(190px, 1fr);
  }

  .studio-tool-nav {
    height: 54px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .studio-tool-nav::-webkit-scrollbar {
    display: none;
  }

  .studio-tool-nav button {
    min-width: 88px;
    padding: 0 10px;
  }
}

@media (max-width: 620px) {
  .studio-shell {
    padding: 8px;
    grid-template-rows: 38px auto 62px;
    gap: 8px;
  }

  .studio-brand img {
    width: min(185px, 62vw);
    height: auto;
  }

  .studio-preview {
    min-height: 0;
    height: auto;
    gap: 9px;
    padding: 12px;
    border-radius: 18px;
  }

  .studio-preview .preview-toolbar h2 {
    font-size: 18px;
  }

  .studio-preview .preview-toolbar h2 small {
    display: none;
  }

  .studio-preview #downloadBtn {
    min-height: 36px;
    gap: 6px;
    padding-inline: 12px;
  }

  .studio-preview .preview-home-host {
    flex: 0 0 auto;
  }

  .studio-preview .preview-home-host .paper-preview-shell {
    height: auto;
    aspect-ratio: var(--paper-aspect, 1.4);
    border-radius: 13px;
  }

  .preview-toolbar-actions {
    gap: 6px;
  }

  .preview-detail-trigger {
    width: 36px;
    min-height: 36px;
    padding: 0;
  }

  .preview-detail-trigger > span:last-child {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .preview-detail-surface {
    padding: max(66px, env(safe-area-inset-top)) 10px max(82px, calc(env(safe-area-inset-bottom) + 70px));
  }

  .preview-detail-close {
    top: max(14px, env(safe-area-inset-top));
    left: max(14px, env(safe-area-inset-left));
    width: 42px;
    height: 42px;
  }

  .preview-detail-canvas-host .paper-preview-shell {
    width: min(100%, calc((100dvh - 148px) * var(--paper-aspect, 1.4)));
    border-radius: 8px;
  }

  .preview-detail-controls {
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 12px;
    transform: none;
  }

  .preview-detail-modal .preview-zoom-controls {
    width: 100%;
    justify-content: stretch;
  }

  .preview-detail-modal .preview-zoom-controls button {
    flex: 1 1 0;
  }

  .preview-detail-modal #zoomValue {
    flex: 0 0 72px;
  }

  .studio-editor {
    bottom: 8px;
    min-height: 62px;
    height: 62px;
    padding: 5px;
  }

  .studio-editor .editor-section {
    bottom: calc(100% + 8px);
    max-height: min(58dvh, 520px);
    gap: 12px;
    padding: 14px;
  }

  .studio-editor .section-title strong {
    font-size: 16px;
  }

  .studio-editor .avatar-workbench,
  .studio-editor .text-controls,
  .studio-editor .paper-settings {
    grid-template-columns: 1fr;
  }

  .studio-editor .portrait-stage {
    width: min(100%, 280px);
    justify-self: center;
  }

  .studio-editor .avatar-actions {
    width: min(100%, 280px);
    justify-self: center;
  }

  .studio-editor .color-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
    justify-content: flex-start;
    flex-wrap: nowrap;
    align-items: center;
    overflow: visible;
    padding: 6px 2px 12px;
  }

  .studio-editor .color-row .swatches::-webkit-scrollbar {
    display: none;
  }

  .studio-editor .color-row .swatches {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }

  .studio-editor .color-row .swatch {
    width: 44px;
    flex: 0 0 44px;
  }

  .studio-editor .color-row .custom-color-picker {
    flex: 0 0 44px;
    z-index: 300;
  }

  .studio-editor .color-row .custom-color-trigger {
    width: 44px;
    height: 44px;
  }

  .studio-editor .pattern-options {
    justify-content: flex-start;
  }

  .studio-editor .copy-style-controls {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(3, minmax(64px, auto));
  }

  .studio-font-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .studio-font-options .font-option {
    min-height: 98px;
    gap: 12px;
    padding: 13px;
  }

  .studio-font-options .font-option-preview {
    font-size: 18px;
  }

  .studio-editor .paper-settings {
    gap: 14px;
  }

  .studio-tool-nav {
    height: 52px;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    overflow: hidden;
  }

  .studio-tool-nav button {
    min-width: 0;
    flex-direction: column;
    gap: 2px;
    padding: 4px 2px;
    font-size: 11px;
  }

  .studio-tool-icon,
  .studio-tool-color,
  .studio-tool-glyph {
    width: 18px;
    height: 18px;
  }
}
