@font-face {
    font-family: "Bricolage Grotesque";
    font-style: normal;
    font-weight: 400 800;
    font-display: swap;
    src: url("./fonts/bricolage-grotesque-latin.woff2") format("woff2");
}
@font-face {
    font-family: "Martian Mono";
    font-style: normal;
    font-weight: 500 700;
    font-display: swap;
    src: url("./fonts/martian-mono-latin.woff2") format("woff2");
}

:root {
    --ink: #121410;
    --ink-soft: #282b24;
    --paper: #e4d9c1;
    --paper-deep: #cdbf9f;
    --lime: #ddff43;
    --lime-hot: #cbf51c;
    --muted: #74776d;
    --line: rgba(18, 20, 16, .16);
    --white-line: rgba(255, 255, 255, .16);
    --display: "Bricolage Grotesque", Arial, sans-serif;
    --mono: "Martian Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html { min-width: 320px; scroll-behavior: smooth; background: var(--paper); color: var(--ink); }
body { min-width: 320px; margin: 0; overflow-x: hidden; background: var(--paper); font-family: var(--display); -webkit-font-smoothing: antialiased; }
body.modal-open { overflow: hidden; }
button, input, select { font: inherit; }
button, select, input[type="range"] { cursor: pointer; }
button { color: inherit; }
button:focus-visible, select:focus-visible, input:focus-visible, canvas:focus-visible { outline: 3px solid #7d43ff; outline-offset: 3px; }

.page-shell { width: min(100%, 1480px); margin: 0 auto; padding: 0 clamp(18px, 4.2vw, 72px); }
.site-header { position: relative; z-index: 20; min-height: 84px; display: flex; align-items: center; justify-content: center; border-bottom: 1px solid var(--line); }
.brand-logo { width: min(62px, 100%); height: auto; display: block; }
.patch-remaining { position: absolute; z-index: 6; top: -28px; left: 50%; display: flex; align-items: center; gap: 7px; margin: 0; color: var(--ink); font-size: 14px; font-weight: 500; line-height: 1.2; text-align: center; white-space: nowrap; transform: translateX(-50%); }
.live-dot { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: #ff6a00; box-shadow: 0 0 0 3px rgba(255,106,0,.14); animation: live-blink 1s ease-in-out infinite; }
@keyframes live-blink { 0%, 45% { opacity: 1; } 55%, 100% { opacity: .18; } }
.studio { min-height: calc(100dvh - 84px); display: grid; align-items: center; margin-top: 0; border: 0; background: transparent; scroll-margin-top: 84px; }
.viewer-column { position: relative; min-width: 0; display: flex; flex-direction: column; transform: translateY(-30px); }
.viewer { position: relative; min-height: min(610px, 100dvh); flex: 1 1 auto; overflow: hidden; background: transparent; touch-action: none; }
.purchase-patch-below { display: flex; justify-content: center; margin-top: 12px; }
.purchase-patch-below[hidden] { display: none; }
.viewer::before { content: none; }
.viewer::after { content: none; }
#ballCanvas { position: absolute; z-index: 1; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
#ballCanvas:active { cursor: grabbing; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }
.on-ball-editor { position: absolute; z-index: 5; inset: 0; pointer-events: none; }
.on-ball-editor[hidden] { display: none; }
.on-ball-surface { position: absolute; min-width: 104px; min-height: 104px; transform: translate(-50%, -50%); pointer-events: none; }
.direct-object { position: absolute; z-index: 1; min-width: 24px; min-height: 18px; border: 1px dashed rgba(221,255,67,.92); border-radius: 2px; background: transparent; transform: translate(-50%, -50%); cursor: move; pointer-events: auto; touch-action: none; }
.direct-object.is-active { z-index: 2; }
.direct-logo-object { display: block; }
.direct-logo-object[hidden] { display: none; }
.direct-text-object { display: block; border-color: rgba(107,64,228,.95); }
.direct-text-object[hidden] { display: none; }
.on-ball-surface[data-panel-type="pentagon"] .direct-text-object { border-color: rgba(221,255,67,.92); }
.direct-object.is-active, .direct-object:focus-within { filter: drop-shadow(0 3px 7px rgba(0,0,0,.28)); }
.direct-object:not(.is-active) .direct-handle { display: none; }
.direct-handle { position: absolute; z-index: 3; width: 22px; height: 22px; display: grid; place-items: center; padding: 0; border: 1px solid var(--ink); border-radius: 50%; background: var(--lime); color: var(--ink); box-shadow: 0 2px 7px rgba(0,0,0,.24); font: 800 12px/1 var(--display); touch-action: none; }
.direct-rotate-handle { top: -7px; left: 50%; cursor: grab; transform: translate(-50%, -50%); }
.direct-resize-handle { right: -7px; bottom: -7px; cursor: nwse-resize; transform: translate(50%, 50%); }
.direct-resize-handle::before { content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; }
.direct-add-logo { position: absolute; z-index: 1; left: 50%; top: 25%; min-height: 25px; padding: 0 7px; border: 1px dashed rgba(221,255,67,.9); border-radius: 3px; background: rgba(10,12,9,.78); color: var(--lime); font: 700 8px var(--mono); transform: translate(-50%, -50%); pointer-events: auto; }
.direct-add-logo[hidden] { display: none; }
.direct-toolbar { position: absolute; left: 50%; top: 50%; width: min(290px, calc(100vw - 28px)); display: grid; gap: 5px; padding: 5px; border: 1px solid rgba(18,20,16,.45); border-radius: 5px; background: rgba(228,217,193,.92); box-shadow: 0 7px 24px rgba(18,20,16,.22); backdrop-filter: blur(8px); transform: translate(-50%, 72px); pointer-events: auto; }
.direct-text-field { min-width: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 7px; padding-left: 5px; color: rgba(18,20,16,.66); font: 700 8px var(--mono); text-transform: uppercase; }
.direct-text-field input { width: 100%; min-width: 0; height: 31px; padding: 0 8px; border: 1px solid rgba(18,20,16,.24); border-radius: 3px; outline: 0; background: rgba(255,255,255,.7); color: var(--ink); font-size: 13px; font-weight: 750; text-transform: none; }
.direct-text-field input:focus { border-color: #6b40e4; box-shadow: 0 0 0 1px #6b40e4; }
.direct-website-field input[aria-invalid="true"] { border-color: #b3261e; box-shadow: 0 0 0 1px #b3261e; }
.purchase-patch-button { min-height: 42px; padding: 0 22px; border: 1px solid var(--ink); border-radius: 4px; background: #ff6a00; color: var(--ink); font-size: 16px; font-weight: 800; line-height: 1.1; }
.purchase-patch-button:hover:not(:disabled) { background: #ed5f00; }
.purchase-patch-button:disabled { cursor: not-allowed; opacity: .45; }
.purchase-patch-button.is-processing { cursor: wait; }
.purchase-notice { position: fixed; z-index: 150; right: 18px; bottom: 18px; width: min(390px, calc(100vw - 36px)); padding: 14px 16px; border: 1px solid var(--ink); border-radius: 5px; background: var(--lime); color: var(--ink); box-shadow: 0 14px 38px rgba(18,20,16,.28); font-size: 14px; font-weight: 750; line-height: 1.35; }
.purchase-notice[hidden] { display: none; }
.purchase-notice.is-error { background: #fff0ea; border-color: #b3261e; color: #7b1c17; }
.purchase-patch-editor { width: 100%; min-height: 35px; margin-top: 2px; padding: 0 10px; font-size: 14px; }
.loading-state { position: absolute; z-index: 6; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: var(--paper); color: var(--ink); transition: opacity .35s ease, visibility .35s ease; }
.loading-state.is-ready { opacity: 0; visibility: hidden; }
.loading-state strong { font-size: 13px; }
.loader-ball { width: 45px; height: 45px; border: 2px solid rgba(18,20,16,.2); border-top-color: #6b40e4; border-radius: 50%; animation: spin .85s linear infinite; }
.viewer-error { position: absolute; z-index: 7; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; padding: 30px; background: var(--paper); color: var(--ink); text-align: center; }
.viewer-error[hidden] { display: none; }
.viewer-error strong { color: #6b40e4; font-size: 18px; }
.viewer-error span { color: var(--muted); }
@keyframes spin { to { transform: rotate(360deg); } }

.brand-modal[hidden] { display: none; }
.brand-modal { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center end; padding: clamp(18px, 4.2vw, 72px); }
.brand-modal-backdrop { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; background: rgba(18, 20, 16, .08); }
.control-panel-shell { position: relative; z-index: 1; width: min(330px, 100%); max-height: calc(100dvh - 36px); }
.control-panel { width: 100%; max-height: inherit; display: flex; flex-direction: column; overflow-y: auto; padding: 10px; border: 1px solid rgba(18,20,16,.52); border-radius: 7px; background: rgba(228,217,193,.68); box-shadow: 0 18px 54px rgba(18,20,16,.16); backdrop-filter: blur(6px) saturate(1.04); -webkit-backdrop-filter: blur(6px) saturate(1.04); }
.modal-close { position: absolute; z-index: 2; top: 0; right: 0; width: 38px; height: 38px; display: grid; place-items: center; padding: 0 0 3px; border: 1px solid rgba(18,20,16,.5); border-radius: 50%; background: rgba(228,217,193,.94); box-shadow: 0 4px 16px rgba(18,20,16,.18); font-size: 24px; line-height: 1; transform: translate(50%, -50%); }
.modal-close:hover { border-color: var(--ink); background: var(--paper); }
.patch-status[hidden] { display: none; }
.modal-section { padding: 0px 0; border-bottom: 1px solid var(--line); }
.upload-step { border-bottom: 0; }
.brand-primary-row { display: grid; grid-template-columns: 72px minmax(0, 1fr); grid-template-areas: "favicon link" "favicon description"; align-items: stretch; gap: 9px 8px; }
.favicon-field, .brand-link-field, .brand-description-field { min-width: 0; display: grid; gap: 5px; }
.favicon-field { grid-area: favicon; align-self: center; justify-items: center; }
.brand-link-field { grid-area: link; }
.brand-description-field { grid-area: description; }
.brand-link-field label, .brand-description-field label { color: rgba(18,20,16,.66); font: 700 7px var(--mono); letter-spacing: .02em; text-transform: uppercase; }
.brand-description-field label span { font-weight: 500; text-transform: none; }
.field-label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.visit-site-link { color: #6b40e4; font: 700 7px var(--mono); text-decoration: none; text-transform: uppercase; }
.visit-site-link:hover { text-decoration: underline; }
.visit-site-link[hidden] { display: none; }
.favicon-preview { width: 64px; height: 64px; display: grid; place-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 7px; background: #f8f5ed; color: #6b40e4; }
.favicon-preview.is-loading { opacity: .58; }
.favicon-preview svg { width: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.favicon-preview img { width: 100%; height: 100%; object-fit: contain; padding: 7px; background: #f8f5ed; }
.favicon-field small { max-width: 72px; color: var(--muted); font: 500 6px/1.3 var(--mono); text-align: center; }
.field-error { margin: 8px 0 0; color: #b3261e; font: 600 8px var(--mono); }
.brand-link-field input, .brand-description-field input { width: 100%; min-height: 30px; padding: 0 3px; border: 1px solid var(--line); border-radius: 3px; outline: 0; background: rgba(255,255,255,.78); color: var(--ink); font-size: 14px; font-weight: 650; text-transform: none; }
.brand-link-field input:focus, .brand-description-field input:focus { border-color: #6b40e4; box-shadow: 0 0 0 1px #6b40e4; }
.brand-link-field input::placeholder, .brand-description-field input::placeholder { color: #8c8e85; font-weight: 500; }
.size-step { padding: 9px 0; }
.adjustment-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stepper-control { min-width: 0; display: grid; grid-template-columns: auto 27px minmax(38px, 1fr) 27px; align-items: center; gap: 4px; }
.stepper-label { font-size: 9px; font-weight: 700; }
.stepper-button { width: 27px; height: 28px; display: grid; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 3px; background: rgba(255,255,255,.5); font-size: 16px; line-height: 1; }
.stepper-button:hover:not(:disabled) { border-color: #6b40e4; background: #fff; }
.stepper-button:disabled { cursor: not-allowed; opacity: .35; }
.stepper-value { min-width: 0; height: 28px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 3px; background: rgba(255,255,255,.72); color: #6b40e4; font: 700 14px var(--mono); }
.modal-action-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding-top: 8px; }
.purchase-patch-modal { width: 100%; min-height: 38px; margin-top: 8px; font-size: 15px; }
.apply-button { height: 35px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--ink); border-radius: 3px; background: var(--lime); color: var(--ink); font-size: 18px; font-weight: 800; }
.apply-button:hover:not(:disabled) { background: var(--lime-hot); }
.apply-button:disabled { cursor: not-allowed; opacity: .45; }
.secondary-button { height: 35px; border: 1px solid var(--line); border-radius: 3px; background: transparent; font-size: 18px; font-weight: 700; }
.secondary-button:hover:not(:disabled) { border-color: var(--ink); background: #fff; }
.secondary-button:disabled { cursor: not-allowed; opacity: .4; }
.download-button { min-width: 0; height: 35px; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 0 8px; border: 1px solid var(--ink); border-radius: 3px; background: transparent; color: var(--ink); font-size: 18px; font-weight: 800; transition: background .12s ease; }
.download-button:hover { background: rgba(255,255,255,.55); }
.download-button svg { width: 15px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 920px) {
    .viewer { min-height: 600px; }
}

@media (max-width: 620px) {
    .page-shell { padding: 0 14px; }
    .site-header { min-height: 68px; }
    .brand-logo { width: min(50px, 100%); }
    .patch-remaining { top: -24px; font-size: 13px; }
    .studio { min-height: calc(100dvh - 68px); margin-top: 0; scroll-margin-top: 68px; }
    .viewer-column { transform: translateY(-50px); }
    .viewer { min-height: min(108vw, 430px, 100dvh); }
    .purchase-patch-below { margin-top: 8px; }
    .direct-toolbar { transform: translate(-50%, 68px); }
    .direct-handle { width: 24px; height: 24px; }
    .brand-modal { place-items: start center; padding: max(20px, env(safe-area-inset-top)) 20px 20px; }
    .control-panel-shell { width: 100%; max-height: min(78dvh, 660px); }
    .control-panel { width: 100%; max-height: inherit; padding: 18px; border-radius: 9px 9px 3px 3px; }
}

@media (max-width: 350px) {
    .control-panel { padding: 14px; }
    .brand-primary-row { gap: 6px; }
    .upload-copy small { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
    .live-dot { animation: none !important; }
}
