:root {
    --studio-ink: #2f2440;
    --studio-purple: #b99de3;
    --studio-green: #a7d98b;
    --studio-pink: #f4c6d7;
    --studio-cream: #fff4d6;
    --studio-paper: #fffaf0;
    --studio-line: rgba(47, 36, 64, 0.16);
    --studio-muted: #756c7e;
    --studio-shadow: 0 24px 70px rgba(47, 36, 64, 0.12);
}

.type-studio {
    min-height: 100vh;
    color: var(--studio-ink);
    background: #f1eee8;
    font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
}

.type-studio header {
    position: relative;
    z-index: 20;
    height: 72px;
    border-bottom: 1px solid var(--studio-line);
    background: rgba(255, 250, 240, 0.94);
    backdrop-filter: blur(16px);
}

.type-studio header .overlay {
    width: min(1480px, calc(100% - 40px));
    max-width: none;
}

.type-studio header a {
    color: var(--studio-ink);
}

.type-studio header nav a.active {
    text-decoration: underline;
    text-decoration-color: var(--studio-green);
    text-decoration-thickness: 3px;
    text-underline-offset: 8px;
}

.type-studio main {
    min-width: 0;
    background: transparent;
}

.studio-shell,
.studio-shell *,
.studio-shell *::before,
.studio-shell *::after {
    box-sizing: border-box;
}

.studio-shell button,
.studio-shell input {
    font: inherit;
}

.studio-shell button {
    color: inherit;
}

.studio-shell {
    display: grid;
    grid-template-columns: 304px minmax(0, 1fr);
    min-height: calc(100vh - 72px);
    border-top: 1px solid rgba(255, 255, 255, 0.75);
}

.studio-panel {
    position: relative;
    z-index: 2;
    overflow-y: auto;
    max-height: calc(100vh - 72px);
    padding: 24px 18px 32px;
    border-right: 1px solid var(--studio-line);
    background: rgba(255, 250, 240, 0.93);
}

.studio-brand {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 0 4px 22px;
}

.studio-brand h1,
.studio-workspace h2,
.control-section h2 {
    margin: 0;
    color: var(--studio-ink);
    font-weight: 700;
    line-height: 1.1;
}

.studio-brand h1 {
    font-size: 1.14rem;
    letter-spacing: -0.025em;
}

.studio-kicker {
    margin: 0 0 4px;
    color: var(--studio-muted);
    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    line-height: 1;
    text-transform: uppercase;
}

.studio-mark {
    position: relative;
    display: block;
    width: 34px;
    height: 34px;
    border: 1px solid var(--studio-line);
    border-radius: 11px;
    background: var(--studio-ink);
    box-shadow: 3px 3px 0 var(--studio-green);
}

.studio-mark i {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.studio-mark i:nth-child(1) {
    top: 7px;
    left: 7px;
    background: var(--studio-purple);
}

.studio-mark i:nth-child(2) {
    right: 7px;
    bottom: 7px;
    background: var(--studio-green);
}

.studio-mark i:nth-child(3) {
    top: 8px;
    right: 8px;
    width: 5px;
    height: 5px;
    background: var(--studio-pink);
}

.control-section {
    padding: 20px 4px;
    border-top: 1px solid var(--studio-line);
}

.control-section h2,
.settings-section summary {
    font-size: 0.73rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.section-heading-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.upload-label {
    cursor: pointer;
    color: var(--studio-muted);
    font-size: 0.72rem;
    font-weight: 700;
}

.upload-label:hover {
    color: var(--studio-ink);
}

.asset-grid,
.preset-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.asset-button,
.preset-button {
    min-width: 0;
    cursor: pointer;
    border: 1px solid var(--studio-line);
    border-radius: 11px;
    background: rgba(255, 255, 255, 0.56);
    transition: 150ms ease;
}

.asset-button:hover,
.preset-button:hover,
.asset-button.is-active,
.preset-button.is-active {
    border-color: var(--studio-ink);
    box-shadow: 0 4px 12px rgba(47, 36, 64, 0.08);
    transform: translateY(-1px);
}

.asset-button:focus-visible,
.preset-button:focus-visible,
.segmented-control button:focus-visible,
.palette-button:focus-visible,
.button-quiet:focus-visible,
.button-export:focus-visible,
.upload-label:focus-visible {
    outline: 3px solid var(--studio-green);
    outline-offset: 2px;
}

.asset-button {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr);
    gap: 8px;
    align-items: center;
    padding: 7px;
    text-align: left;
}

.asset-button img {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 7px;
    background: var(--studio-cream);
}

.asset-button span {
    overflow: hidden;
    font-size: 0.71rem;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preset-button {
    display: flex;
    gap: 7px;
    align-items: center;
    justify-content: flex-start;
    min-height: 38px;
    padding: 8px;
    font-size: 0.72rem;
    font-weight: 700;
}

.preset-icon {
    position: relative;
    display: block;
    flex: 0 0 24px;
    width: 24px;
    height: 20px;
    overflow: hidden;
    border-radius: 5px;
    background: var(--studio-cream);
}

.preset-icon::before,
.preset-icon::after {
    position: absolute;
    content: "";
}

.preset-signal::before {
    top: 4px;
    bottom: 4px;
    left: 8px;
    width: 7px;
    background: var(--studio-purple);
    box-shadow: 5px 0 0 rgba(167, 217, 139, 0.8);
}

.preset-orbit::before {
    inset: 4px 6px;
    border: 2px solid var(--studio-purple);
    border-radius: 50%;
}

.preset-orbit::after {
    top: 4px;
    right: 5px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--studio-green);
}

.preset-window::before {
    inset: 4px 5px;
    border: 2px solid var(--studio-ink);
    border-radius: 1px 8px 1px 1px;
}

.preset-echo::before {
    top: 5px;
    left: 5px;
    width: 9px;
    height: 9px;
    border: 1px solid var(--studio-ink);
    box-shadow: 3px 2px 0 var(--studio-purple), 6px 4px 0 var(--studio-green);
}

.settings-section summary {
    display: flex;
    cursor: pointer;
    list-style: none;
    align-items: center;
    justify-content: space-between;
}

.settings-section summary::-webkit-details-marker {
    display: none;
}

.settings-section[open] summary {
    margin-bottom: 20px;
}

.settings-section summary span {
    font-size: 1rem;
    transition: transform 160ms ease;
}

.settings-section:not([open]) summary span {
    transform: rotate(-90deg);
}

.setting-group,
.range-setting,
.switch-row {
    margin-top: 16px;
}

.setting-label,
.range-setting > span,
.switch-row > span {
    display: block;
    color: var(--studio-muted);
    font-size: 0.72rem;
    font-weight: 700;
}

.segmented-control {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 3px;
    margin-top: 7px;
    padding: 3px;
    border: 1px solid var(--studio-line);
    border-radius: 9px;
    background: rgba(47, 36, 64, 0.035);
}

.segmented-control button {
    cursor: pointer;
    padding: 6px 4px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    font-size: 0.69rem;
    font-weight: 750;
}

.segmented-control button.is-active {
    background: var(--studio-ink);
    color: var(--studio-cream);
}

.palette-options {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.palette-button {
    cursor: pointer;
    padding: 3px;
    border: 1px solid transparent;
    border-radius: 999px;
    background: transparent;
}

.palette-button.is-active {
    border-color: var(--studio-ink);
}

.palette-button i {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: 42px;
    height: 18px;
    overflow: hidden;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--a) 0 33%, var(--b) 33% 66%, var(--c) 66%);
}

.range-setting > span {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.range-setting output {
    min-width: 34px;
    color: var(--studio-ink);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.range-setting input[type="range"] {
    width: 100%;
    height: 3px;
    margin: 11px 0 3px;
    cursor: pointer;
    appearance: none;
    border-radius: 999px;
    background: rgba(47, 36, 64, 0.18);
}

.range-setting input[type="range"]::-webkit-slider-thumb {
    width: 13px;
    height: 13px;
    appearance: none;
    border: 2px solid var(--studio-paper);
    border-radius: 50%;
    background: var(--studio-ink);
    box-shadow: 0 0 0 1px var(--studio-ink);
}

.range-setting input[type="range"]::-moz-range-thumb {
    width: 10px;
    height: 10px;
    border: 2px solid var(--studio-paper);
    border-radius: 50%;
    background: var(--studio-ink);
    box-shadow: 0 0 0 1px var(--studio-ink);
}

.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.switch {
    position: relative;
    display: block;
    width: 32px;
    height: 18px;
}

.switch input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.switch > span {
    position: absolute;
    inset: 0;
    cursor: pointer;
    border-radius: 999px;
    background: rgba(47, 36, 64, 0.2);
    transition: 160ms ease;
}

.switch > span::after {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 1px 4px rgba(47, 36, 64, 0.26);
    content: "";
    transition: 160ms ease;
}

.switch input:checked + span {
    background: var(--studio-ink);
}

.switch input:checked + span::after {
    transform: translateX(14px);
}

.switch input:focus-visible + span {
    outline: 3px solid var(--studio-green);
    outline-offset: 2px;
}

.studio-workspace {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-width: 0;
    min-height: calc(100vh - 72px);
    padding: 26px clamp(22px, 3vw, 46px) 20px;
    background-color: #f1eee8;
    background-image: radial-gradient(rgba(47, 36, 64, 0.13) 0.7px, transparent 0.7px);
    background-size: 9px 9px;
}

.workspace-toolbar,
.workspace-footer {
    display: flex;
    gap: 24px;
    align-items: center;
    justify-content: space-between;
}

.studio-workspace h2 {
    font-family: "Iowan Old Style", Georgia, serif;
    font-size: clamp(1.55rem, 2.3vw, 2.35rem);
    letter-spacing: -0.035em;
}

.toolbar-actions {
    display: flex;
    gap: 9px;
}

.button-quiet,
.button-export {
    display: inline-flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    cursor: pointer;
    border: 1px solid var(--studio-ink);
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 800;
    transition: transform 160ms ease, box-shadow 160ms ease;
}

.button-quiet:hover,
.button-export:hover {
    transform: translateY(-2px);
}

.button-quiet {
    padding: 10px 15px;
    background: rgba(255, 250, 240, 0.76);
}

.button-export {
    padding: 10px 18px;
    color: var(--studio-cream) !important;
    background: var(--studio-ink);
    box-shadow: 4px 4px 0 var(--studio-purple);
}

.canvas-field {
    display: grid;
    min-height: 0;
    padding: clamp(24px, 3.3vw, 48px) 0;
    place-items: center;
}

.canvas-wrap {
    position: relative;
    display: grid;
    width: min(68vh, 760px, 76vw);
    overflow: hidden;
    border: 1px solid rgba(47, 36, 64, 0.18);
    border-radius: 4px;
    background: var(--studio-cream);
    box-shadow: var(--studio-shadow), 10px 10px 0 rgba(185, 157, 227, 0.38);
    aspect-ratio: var(--studio-aspect, 1 / 1);
    place-items: center;
    transition: width 200ms ease, aspect-ratio 200ms ease;
}

.canvas-wrap[data-ratio="portrait"] {
    width: min(52vh, 640px, 70vw);
}

.canvas-wrap[data-ratio="landscape"] {
    width: min(92vh, 960px, 76vw);
}

.canvas-wrap::before,
.canvas-wrap::after {
    position: absolute;
    z-index: 3;
    width: 8px;
    height: 8px;
    border: 1px solid var(--studio-ink);
    background: var(--studio-paper);
    content: "";
    pointer-events: none;
}

.canvas-wrap::before {
    top: -4px;
    left: -4px;
}

.canvas-wrap::after {
    right: -4px;
    bottom: -4px;
}

.canvas-wrap canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
    object-fit: contain;
    touch-action: none;
}

.canvas-wrap canvas:active {
    cursor: grabbing;
}

.drag-hint {
    position: absolute;
    z-index: 4;
    bottom: 14px;
    left: 50%;
    padding: 7px 11px;
    border: 1px solid rgba(47, 36, 64, 0.12);
    border-radius: 999px;
    color: var(--studio-muted);
    background: rgba(255, 250, 240, 0.82);
    box-shadow: 0 4px 14px rgba(47, 36, 64, 0.08);
    font-size: 0.66rem;
    font-weight: 700;
    pointer-events: none;
    transform: translateX(-50%);
    transition: opacity 200ms ease;
}

.drag-hint.is-hidden {
    opacity: 0;
}

.workspace-footer {
    color: var(--studio-muted);
    font-size: 0.72rem;
}

.workspace-footer p {
    margin: 0;
    font-size: inherit;
}

.workspace-footer strong {
    color: var(--studio-ink);
}

.live-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 7px;
    border-radius: 50%;
    background: #6eae5c;
    box-shadow: 0 0 0 4px rgba(167, 217, 139, 0.3);
}

.visually-hidden {
    position: absolute !important;
    overflow: hidden !important;
    width: 1px !important;
    height: 1px !important;
    clip: rect(0 0 0 0) !important;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
}

.studio-noscript {
    padding: 24px;
    text-align: center;
}

@media (max-width: 980px) {
    .studio-shell {
        grid-template-columns: 256px minmax(0, 1fr);
    }

    .studio-panel {
        padding-inline: 12px;
    }

    .asset-grid {
        grid-template-columns: 1fr;
    }

    .canvas-wrap {
        width: min(62vh, 68vw);
    }
}

@media (max-width: 760px) {
    .type-studio header {
        height: 84px;
    }

    .type-studio header .overlay,
    .type-studio header nav {
        flex-wrap: wrap;
    }

    .studio-shell {
        display: flex;
        min-height: calc(100vh - 84px);
        flex-direction: column-reverse;
    }

    .studio-panel {
        overflow: visible;
        max-height: none;
        border-top: 1px solid var(--studio-line);
        border-right: 0;
    }

    .studio-workspace {
        min-height: auto;
        padding: 22px 16px 18px;
    }

    .workspace-toolbar {
        align-items: flex-start;
    }

    .toolbar-actions {
        flex-direction: column-reverse;
    }

    .button-quiet,
    .button-export {
        min-height: 38px;
        padding: 8px 12px;
    }

    .canvas-field {
        padding: 30px 0;
    }

    .canvas-wrap {
        width: min(82vw, 560px);
        max-height: 62vh;
    }

    .workspace-tip {
        display: none;
    }

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

@media (max-width: 460px) {
    .type-studio header .overlay {
        width: calc(100% - 24px);
    }

    .type-studio header .home {
        margin-right: 10px;
    }

    .type-studio header nav a {
        margin-right: 8px;
        font-size: 0.86rem;
    }

    .workspace-toolbar {
        gap: 12px;
    }

    .studio-workspace h2 {
        font-size: 1.35rem;
    }

    .button-quiet {
        display: none;
    }

    .button-export {
        white-space: nowrap;
    }

    .canvas-wrap {
        width: calc(100vw - 42px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .canvas-wrap,
    .asset-button,
    .preset-button,
    .button-quiet,
    .button-export,
    .settings-section summary span,
    .switch > span,
    .switch > span::after {
        transition: none;
    }
}
