:root {
    color-scheme: dark;
    --navy: #100b1d;
    --navy-soft: #191126;
    --card: #21162f;
    --card-hover: #2a1c3b;
    --line: #3d2b4d;
    --text: #fff9f7;
    --muted: #b9acbf;
    --pink: #ff5c8c;
    --pink-soft: #ffd4e1;
    --cream: #fff9ef;
    --green: #54d7a1;
    --danger: #ff9aaa;
    font-family: "Avenir Next", Avenir, Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-width: 320px;
    min-height: 100vh;
    background:
        radial-gradient(circle at 82% 4%, rgba(255, 70, 133, .15), transparent 30rem),
        radial-gradient(circle at 10% 30%, rgba(114, 54, 160, .14), transparent 34rem),
        var(--navy);
    color: var(--text);
}

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

.site-header {
    width: min(1440px, calc(100% - 48px));
    min-height: 104px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    border-bottom: 1px solid rgba(255, 255, 255, .09);
}

.brand-link { display: inline-flex; }
.brand { display: block; width: 178px; height: auto; }

.app-nav { display: inline-flex; align-items: center; gap: 5px; padding: 5px; border: 1px solid var(--line); border-radius: 999px; background: rgba(22, 15, 33, .72); }
.app-nav a { padding: 8px 14px; border-radius: 999px; color: var(--muted); font-size: 13px; font-weight: 800; text-decoration: none; }
.app-nav a:hover, .app-nav a.is-active { background: rgba(255, 92, 140, .17); color: white; }

.meta-status {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 9px 13px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    font-size: 13px;
}

.meta-status.is-connected { color: #b8f6dd; border-color: rgba(84, 215, 161, .35); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.page-shell { width: min(1440px, calc(100% - 48px)); margin: 0 auto; padding: 54px 0 72px; }
.intro { max-width: 780px; margin-bottom: 34px; }
.eyebrow { margin: 0 0 9px; color: var(--pink); font-weight: 800; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; }
.intro h1 { margin: 0; font-size: clamp(38px, 6vw, 72px); line-height: .98; letter-spacing: -.045em; }
.intro > p:last-child { margin: 20px 0 0; max-width: 650px; color: var(--muted); font-size: 18px; line-height: 1.6; }
.flash { margin: 0 0 28px; padding: 14px 18px; border: 1px solid #5f4576; border-radius: 14px; background: #2a1c3b; color: var(--pink-soft); }

.generator-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(360px, .72fr); gap: 30px; align-items: start; }
.controls { display: grid; gap: 18px; min-width: 0; }
.control-card, .preview-panel { border: 1px solid var(--line); border-radius: 24px; background: rgba(33, 22, 47, .88); box-shadow: 0 25px 70px rgba(0, 0, 0, .2); }
.control-card { min-width: 0; padding: 25px; }
.compact-card { padding-bottom: 22px; }
.step-heading { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 22px; }
.step-number { flex: 0 0 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: var(--pink); color: #250819; font-weight: 900; }
.step-heading h2, .preview-heading h2 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.step-heading p { margin: 5px 0 0; color: var(--muted); line-height: 1.45; }

.field-grid { display: grid; gap: 13px; }
.three-columns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 700; }
.field input, .field select {
    width: 100%;
    min-height: 50px;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: #160f21;
    color: var(--text);
    padding: 0 13px;
    outline: none;
}
.field input:focus, .field select:focus { border-color: var(--pink); box-shadow: 0 0 0 3px rgba(255, 92, 140, .13); }

.availability-toolbar, .template-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-top: 18px; }
.inline-status { min-height: 22px; color: var(--muted); font-size: 14px; }
.inline-status.is-error { color: var(--danger); }
.text-button { border: 0; background: transparent; color: var(--pink-soft); font-weight: 800; padding: 6px 0; }
.text-button:hover { color: white; }
.slider-actions { display: flex; align-items: center; gap: 7px; flex: 0 0 auto; }
.slider-button { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 10px; background: #160f21; color: var(--pink-soft); font-size: 18px; line-height: 1; }
.slider-button:hover { border-color: var(--pink); color: white; }

.asset-section h3 { margin: 0 0 5px; font-size: 15px; color: var(--text); }
.asset-heading-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; }
.asset-section-separated { margin-top: 23px; padding-top: 22px; border-top: 1px solid rgba(255, 255, 255, .09); }

.slots-list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; margin-top: 13px; }
.slot-option { position: relative; }
.slot-option input { position: absolute; opacity: 0; pointer-events: none; }
.slot-option span {
    display: grid;
    width: 100%;
    min-width: 0;
    padding: 10px 13px 9px;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: #160f21;
    color: var(--muted);
    text-align: center;
    transition: background .16s ease, border-color .16s ease, transform .16s ease;
}
.slot-option strong { color: var(--text); font-size: 18px; line-height: 1.1; }
.slot-option small { margin-top: 3px; font-size: 10px; }
.slot-option input:checked + span { background: rgba(255, 92, 140, .17); border-color: var(--pink); color: var(--pink-soft); }
.slot-option input:focus-visible + span { outline: 3px solid rgba(255, 92, 140, .3); outline-offset: 2px; }
.slot-option:hover span { transform: translateY(-1px); }

.templates-list, .backgrounds-list {
    display: grid;
    grid-auto-flow: column;
    width: 100%;
    max-width: 100%;
    gap: 12px;
    margin-top: 13px;
    padding: 2px 2px 12px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    scrollbar-color: #634776 transparent;
}
.templates-list { grid-auto-columns: 142px; }
.backgrounds-list { grid-auto-columns: 108px; }
.template-option {
    padding: 0;
    overflow: hidden;
    border: 2px solid transparent;
    border-radius: 15px;
    background: #160f21;
    color: var(--text);
    text-align: left;
    scroll-snap-align: start;
}
.template-option img { display: block; width: 100%; aspect-ratio: 9 / 16; object-fit: cover; background: #120b19; }
.template-option span { display: block; padding: 9px 10px 10px; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.template-option.is-selected { border-color: var(--pink); box-shadow: 0 0 0 3px rgba(255, 92, 140, .12); }
.template-option.is-selected span { color: white; }

.background-option {
    padding: 0;
    overflow: hidden;
    border: 2px solid transparent;
    border-radius: 15px;
    background: #160f21;
    color: var(--text);
    text-align: left;
    scroll-snap-align: start;
}
.background-option img { display: block; width: 100%; aspect-ratio: 9 / 16; object-fit: cover; background: #120b19; }
.background-option span { display: block; padding: 8px 8px 9px; color: var(--muted); font-size: 10px; line-height: 1.25; }
.background-option.is-selected { border-color: var(--pink); box-shadow: 0 0 0 3px rgba(255, 92, 140, .12); }
.background-option.is-selected span { color: white; }

.copy-row { display: flex; align-items: end; gap: 10px; }
.grow-field { flex: 1; }
.secondary-button, .primary-button {
    min-height: 50px;
    border: 0;
    border-radius: 13px;
    font-weight: 900;
}
.secondary-button { padding: 0 18px; background: #3a294a; color: white; }
.secondary-button:hover { background: #49345d; }
.copy-status { min-height: 18px; margin-top: 8px; color: var(--green); font-size: 12px; }

.preview-panel { position: static; min-width: 0; padding: 22px; }
.preview-heading { display: flex; justify-content: space-between; align-items: end; gap: 18px; margin-bottom: 16px; }
.preview-heading .eyebrow { margin-bottom: 5px; }
.template-id { padding: 6px 9px; border-radius: 8px; background: #160f21; color: var(--pink-soft); font-size: 11px; font-weight: 900; }
.canvas-frame { position: relative; width: min(100%, 390px); margin: 0 auto; overflow: hidden; aspect-ratio: 9 / 16; border-radius: 18px; background: #0d0813; box-shadow: 0 24px 60px rgba(0, 0, 0, .35); }
#story-canvas { display: block; width: 100%; height: 100%; }
.canvas-placeholder { position: absolute; inset: 0; display: grid; place-items: center; padding: 28px; background: linear-gradient(145deg, #21162f, #130b1d); color: var(--muted); text-align: center; }
.canvas-frame.is-ready .canvas-placeholder { display: none; }
.primary-button { width: 100%; margin-top: 18px; padding: 0 22px; background: linear-gradient(110deg, #ff715f, #ff4b8d 52%, #bf45dd); color: #220816; box-shadow: 0 14px 36px rgba(255, 75, 141, .2); }
.primary-button:not(:disabled):hover { filter: brightness(1.08); }
.publish-note { margin: 13px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; text-align: center; }
.publish-note span { color: #ffbf64; }

.archive-section { margin-top: 30px; }
.archive-panel { overflow: hidden; border: 1px solid var(--line); border-radius: 24px; background: rgba(33, 22, 47, .88); box-shadow: 0 25px 70px rgba(0, 0, 0, .2); }
.archive-panel > summary { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 24px 26px; cursor: pointer; list-style: none; }
.archive-panel > summary::-webkit-details-marker { display: none; }
.archive-panel > summary strong { display: block; font-size: 24px; letter-spacing: .04em; }
.archive-panel > summary .eyebrow { margin-bottom: 5px; }
.archive-count { flex: 0 0 auto; padding: 7px 11px; border-radius: 999px; background: #160f21; color: var(--pink-soft); font-size: 12px; font-weight: 900; }
.archive-panel[open] .archive-count { background: rgba(255, 92, 140, .17); color: white; }
.archive-content { padding: 0 26px 28px; border-top: 1px solid rgba(255, 255, 255, .09); }
.archive-content > .inline-status { margin: 22px 0 0; }
.archive-list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-top: 20px; }
.archive-item { overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: #160f21; }
.archive-image-link { display: block; overflow: hidden; background: #0d0813; }
.archive-image-link img { display: block; width: 100%; aspect-ratio: 9 / 16; object-fit: cover; transition: transform .2s ease; }
.archive-image-link:hover img { transform: scale(1.015); }
.archive-meta { padding: 14px; }
.archive-date { margin: 0; color: white; font-size: 17px; font-weight: 900; }
.archive-time { margin: 4px 0 0; color: var(--pink-soft); font-size: 13px; font-weight: 800; }
.archive-slots { margin: 9px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.archive-empty { grid-column: 1 / -1; margin: 0; padding: 24px; border: 1px dashed var(--line); border-radius: 16px; color: var(--muted); text-align: center; }

.site-footer { width: min(1440px, calc(100% - 48px)); margin: 0 auto; padding: 24px 0 36px; border-top: 1px solid rgba(255, 255, 255, .09); display: flex; justify-content: space-between; gap: 20px; color: #897b91; font-size: 12px; }
.site-footer p { margin: 0; }
.site-footer a { color: var(--pink-soft); }

@media (max-width: 980px) {
    .generator-layout { grid-template-columns: 1fr; }
    .canvas-frame { width: min(100%, 430px); }
    .archive-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
    .site-header, .page-shell, .site-footer { width: min(100% - 28px, 1440px); }
    .site-header { min-height: 84px; }
    .brand { width: 142px; }
    .app-nav { order: 3; width: 100%; justify-content: center; margin-bottom: 12px; }
    .site-header { flex-wrap: wrap; padding-top: 14px; }
    .meta-status { max-width: 48%; padding: 7px 9px; font-size: 10px; }
    .page-shell { padding: 36px 0 48px; }
    .intro { margin-bottom: 24px; }
    .intro h1 { font-size: clamp(36px, 12vw, 54px); }
    .intro > p:last-child { font-size: 16px; }
    .control-card, .preview-panel { border-radius: 19px; padding: 18px; }
    .three-columns { grid-template-columns: 1fr; }
    .template-toolbar, .asset-heading-row { align-items: flex-start; flex-direction: column; }
    .slots-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .templates-list { grid-auto-columns: 126px; }
    .backgrounds-list { grid-auto-columns: 96px; }
    .copy-row { align-items: stretch; flex-direction: column; }
    .copy-row .secondary-button { width: 100%; }
    .archive-panel { border-radius: 19px; }
    .archive-panel > summary { padding: 20px 18px; }
    .archive-content { padding: 0 18px 20px; }
    .archive-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
    .site-footer { flex-direction: column; }
}

@media (max-width: 420px) {
    .slots-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .archive-list { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
