:root {
    --bg: #0b0f16;
    --panel: #f8fafc;
    --panel-strong: #ffffff;
    --ink: #111827;
    --muted: #6b7280;
    --line: #d7dde8;
    --blue: #2563eb;
    --cyan: #06b6d4;
    --green: #15a34a;
    --danger: #dc2626;
    --shadow: 0 24px 70px rgba(7, 12, 20, 0.28);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, Lato, Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: 72px 1fr;
    background:
        radial-gradient(circle at 18% 12%, rgba(37, 99, 235, .20), transparent 28%),
        linear-gradient(135deg, #111827 0%, #0b0f16 45%, #121826 100%);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 12px 22px;
    border-bottom: 1px solid rgba(255,255,255,.10);
    background: rgba(9, 13, 22, .88);
    backdrop-filter: blur(18px);
    color: #fff;
    z-index: 20;
}

.brand, .topbar-center, .topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: linear-gradient(145deg, #f8fafc, #b8c7df);
    color: #0f172a;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.9), 0 10px 28px rgba(0,0,0,.35);
}

.brand h1 {
    margin: 0;
    font-size: 16px;
    line-height: 1.1;
    font-weight: 800;
    letter-spacing: 0;
}

.brand p {
    margin: 4px 0 0;
    font-size: 10px;
    text-transform: uppercase;
    color: #9ca3af;
    letter-spacing: .12em;
}

.segmented {
    display: flex;
    gap: 4px;
    padding: 4px;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 12px;
    background: rgba(255,255,255,.06);
}

.segmented button, .icon-action, .ghost-danger, .cart-button {
    border: 0;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform .16s ease, background .16s ease, color .16s ease, border .16s ease;
}

.segmented button {
    padding: 10px 14px;
    background: transparent;
    color: #cbd5e1;
    font-weight: 700;
    font-size: 13px;
}

.segmented button.active {
    color: #07111f;
    background: #fff;
    box-shadow: 0 10px 26px rgba(0,0,0,.22);
}

.icon-action {
    width: 40px;
    height: 40px;
    color: #cbd5e1;
    background: rgba(255,255,255,.07);
    border: 1px solid rgba(255,255,255,.10);
}

.ghost-danger {
    padding: 10px 12px;
    color: #fecaca;
    background: rgba(220,38,38,.08);
    border: 1px solid rgba(248,113,113,.18);
}

.cart-button {
    padding: 12px 18px;
    color: #fff;
    background: linear-gradient(135deg, #16a34a, #22c55e);
    font-weight: 800;
    box-shadow: 0 14px 32px rgba(22, 163, 74, .32);
}

.designer-grid {
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(310px, 360px) 1fr minmax(300px, 340px);
}

.panel {
    overflow: auto;
    background: linear-gradient(180deg, #ffffff 0%, #f4f7fb 100%);
    border-right: 1px solid var(--line);
}

.right-panel {
    border-right: 0;
    border-left: 1px solid var(--line);
}

.tool-section {
    padding: 18px;
    border-bottom: 1px solid #e5eaf2;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    color: #111827;
    font-weight: 800;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: .08em;
}

.section-heading i { color: var(--blue); }

.add-row {
    display: grid;
    grid-template-columns: 1fr 48px;
    gap: 10px;
}

input[type="text"], select, textarea {
    width: 100%;
    border: 1px solid #cfd8e6;
    border-radius: 10px;
    background: #fff;
    color: #111827;
    outline: 0;
    padding: 12px 13px;
    box-shadow: inset 0 1px 2px rgba(15,23,42,.04);
}

textarea { resize: vertical; min-height: 82px; }

input:focus, select:focus, textarea:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 4px rgba(37,99,235,.12);
}

.primary-square {
    border: 0;
    border-radius: 12px;
    color: #fff;
    background: #111827;
    box-shadow: 0 12px 26px rgba(17,24,39,.24);
}

.quick-fonts {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 10px;
}

.quick-fonts button, .motif-tabs button, .button-grid button {
    border: 1px solid #d8e0ec;
    border-radius: 9px;
    background: #fff;
    color: #334155;
    padding: 9px 8px;
    font-size: 12px;
    font-weight: 700;
}

.upload-drop {
    display: grid;
    place-items: center;
    min-height: 132px;
    padding: 18px;
    border: 1px dashed #aebbd0;
    border-radius: 14px;
    background: linear-gradient(180deg, #f8fafc, #eef4fb);
    color: #475569;
    text-align: center;
}

.upload-drop input { display: none; }
.upload-drop i { margin-bottom: 8px; color: #64748b; font-size: 28px; }
.upload-drop span { margin-top: 4px; color: #7b8798; font-size: 12px; }

#upload-status {
    margin-top: 10px;
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 800;
    text-align: center;
}

#upload-status.ok { background: #dcfce7; color: #15803d; }
#upload-status.error { background: #fee2e2; color: #b91c1c; }
#upload-status.load { background: #dbeafe; color: #1d4ed8; }
.hidden { display: none !important; }

.motif-tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 12px;
}

.motif-tabs button.active {
    border-color: #93c5fd;
    background: #eff6ff;
    color: #1d4ed8;
}

.icon-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 9px;
    max-height: calc(100vh - 445px);
    min-height: 230px;
    overflow: auto;
    padding-right: 4px;
}

.icon-btn {
    min-height: 48px;
    border: 1px solid #dbe3ef;
    border-radius: 12px;
    background: #fff;
    color: #334155;
    display: grid;
    place-items: center;
    font-size: 18px;
    transition: transform .14s ease, border .14s ease, background .14s ease, color .14s ease;
}

.icon-btn:hover {
    transform: translateY(-1px);
    border-color: #7dd3fc;
    color: #0369a1;
    background: #f0f9ff;
}

.stage {
    min-width: 0;
    display: grid;
    grid-template-rows: auto 1fr;
    position: relative;
    overflow: hidden;
    background-color: #10151f;
    background-image:
        linear-gradient(rgba(255,255,255,.045) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,.045) 1px, transparent 1px);
    background-size: 24px 24px;
}

.stage::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 50% 12%, rgba(14,165,233,.18), transparent 34%),
        linear-gradient(180deg, rgba(255,255,255,.04), transparent 42%);
    pointer-events: none;
}

.stage-toolbar {
    position: relative;
    z-index: 2;
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: center;
    padding: 18px 22px;
    color: #e5e7eb;
    border-bottom: 1px solid rgba(255,255,255,.08);
    background: rgba(5,9,16,.46);
    backdrop-filter: blur(14px);
}

.stage-toolbar strong { display: block; font-size: 14px; }
.stage-toolbar span { color: #94a3b8; font-size: 12px; }

.stage-pills { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.stage-pills span {
    padding: 7px 10px;
    border-radius: 999px;
    background: rgba(255,255,255,.07);
    border: 1px solid rgba(255,255,255,.10);
    color: #cbd5e1;
}

.stage-center {
    position: relative;
    z-index: 1;
    min-height: 0;
    display: grid;
    place-items: center;
    padding: 34px 22px 44px;
}

.export-overlay {
    position: absolute;
    inset: 0;
    z-index: 40;
    display: grid;
    place-items: center;
    background: rgba(5, 9, 16, .58);
    backdrop-filter: blur(5px);
}

.export-box {
    width: min(420px, calc(100% - 36px));
    padding: 26px;
    border-radius: 18px;
    border: 1px solid rgba(255,255,255,.16);
    background: rgba(15, 23, 42, .94);
    color: #fff;
    box-shadow: 0 28px 80px rgba(0,0,0,.46);
    text-align: center;
}

.export-spinner {
    width: 58px;
    height: 58px;
    margin: 0 auto 14px;
    display: grid;
    place-items: center;
    border-radius: 16px;
    background: linear-gradient(135deg, #e0f2fe, #bfdbfe);
    color: #0f172a;
    font-size: 24px;
    animation: exportPulse 1.2s ease-in-out infinite;
}

.export-box strong {
    display: block;
    font-size: 18px;
    margin-bottom: 8px;
}

.export-box span {
    display: block;
    min-height: 20px;
    color: #cbd5e1;
    font-size: 13px;
}

.export-progress {
    height: 10px;
    margin-top: 18px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(255,255,255,.12);
}

#export-progress-bar {
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #38bdf8, #22c55e);
    transition: width .35s ease;
}

@keyframes exportPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

#trophy-wrapper {
    position: relative;
    width: min(45vw, 430px);
    min-width: 330px;
    aspect-ratio: 360 / 520;
    background: linear-gradient(135deg, rgba(255,255,255,.10) 0%, rgba(160,210,230,.16) 45%, rgba(255,255,255,.06) 100%);
    border: 1px solid rgba(255,255,255,.28);
    box-shadow: var(--shadow), inset 0 0 38px rgba(255,255,255,.06);
    backdrop-filter: blur(3px);
    clip-path: polygon(0 0, 100% 0, 92% 85%, 8% 85%);
}

.glass-shine {
    position: absolute;
    inset: 0;
    background:
        linear-gradient(115deg, transparent 29%, rgba(255,255,255,.18) 42%, transparent 56%),
        linear-gradient(90deg, rgba(255,255,255,.10), transparent 14%, transparent 82%, rgba(255,255,255,.08));
    z-index: 20;
    pointer-events: none;
}

.canvas-container-wrapper {
    position: absolute;
    top: 8%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    border: 1px solid rgba(255,255,255,.16);
    box-shadow: 0 0 0 1px rgba(0,0,0,.24);
}

.inspector-empty {
    min-height: 190px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 8px;
    text-align: center;
    color: #64748b;
}

.inspector-empty i { color: #2563eb; font-size: 28px; }
.inspector-empty strong { color: #111827; }
.inspector-empty span { max-width: 250px; font-size: 13px; line-height: 1.45; }

.inspector { display: none; }
.inspector.active { display: block; }

.control-label {
    display: block;
    margin: 12px 0 7px;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: .08em;
    font-size: 11px;
    font-weight: 800;
}

.control-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.slider-control { margin-top: 14px; }
.slider-control label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #475569;
    font-size: 12px;
    font-weight: 800;
}

input[type="range"] { width: 100%; accent-color: var(--blue); }
input[type="color"] {
    width: 100%;
    min-height: 43px;
    border: 1px solid #cfd8e6;
    border-radius: 10px;
    background: #fff;
    padding: 4px;
}

.button-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 16px;
}

.button-grid button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
}

.small-danger {
    border: 0;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    color: #b91c1c;
    background: #fee2e2;
}

.done-button {
    width: 100%;
    margin-top: 14px;
    border: 0;
    border-radius: 11px;
    padding: 12px 14px;
    background: #111827;
    color: #fff;
    font-weight: 800;
}

@media (max-width: 1120px) {
    .designer-grid { grid-template-columns: 320px 1fr; }
    .right-panel { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); max-height: 42vh; }
}

@media (max-width: 780px) {
    .app-shell { grid-template-rows: auto 1fr; }
    .topbar { flex-wrap: wrap; }
    .topbar-center { order: 3; width: 100%; justify-content: space-between; }
    .designer-grid { grid-template-columns: 1fr; }
    .panel { max-height: none; }
    .stage { min-height: 640px; }
    #trophy-wrapper { width: min(86vw, 380px); min-width: 280px; }
    .icon-grid { max-height: 260px; }
}
