:root {
    --bg: #ffffff;
    --soft-bg: #f8fafc;
    --panel: #ffffff;
    --line: #dbe3ef;
    --line-soft: #edf1f6;
    --text: #121826;
    --muted: #8a96a8;
    --deep: #0f172a;
    --brand: #ae513f;
    --blue: #3b82f6;
    --purple: #8b5cf6;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

button,
input,
textarea {
    font: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 42px;
    padding: 0 9px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
}

.brand-pill {
    display: inline-flex;
    align-items: center;
    height: 31px;
    padding: 0 13px;
    border-radius: 5px;
    color: #fff;
    background: var(--brand);
    font-size: 17px;
    font-weight: 800;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 7px;
}

.header-nav a {
    height: 28px;
    padding: 0 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: #fff;
    color: #111827;
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
}

.header-nav a.active {
    color: #fff;
    background: #060b19;
    border-color: #060b19;
}

.generator-layout {
    display: grid;
    grid-template-columns: 318px minmax(0, 1fr);
    gap: 10px;
    min-height: calc(100vh - 42px);
    border-bottom: 1px solid var(--line-soft);
}

.tool-sidebar {
    margin: 12px 0 10px 8px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
}

.toggle-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
}

.toggle-card {
    display: grid;
    place-items: center;
    gap: 7px;
    height: 59px;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: #64748b;
    background: #fff;
    cursor: pointer;
}

.toggle-card input {
    display: none;
}

.toggle-card.checked {
    color: var(--blue);
    border-color: #91b7ff;
    background: #eff6ff;
}

.toggle-card.checked.purple {
    color: var(--purple);
    border-color: #c4a6ff;
    background: #f5f0ff;
}

.toggle-icon {
    font-size: 16px;
    line-height: 1;
}

.toggle-card strong {
    font-size: 13px;
}

.side-divider {
    height: 1px;
    margin: 17px 0;
    background: var(--line);
}

.range-field {
    position: relative;
    display: grid;
    gap: 6px;
    margin-bottom: 12px;
    font-size: 13px;
    font-weight: 700;
}

.mini-number {
    position: absolute;
    right: 0;
    top: -5px;
    width: 56px;
    height: 22px;
    padding: 0 8px;
    border: 1px solid var(--line);
    border-radius: 4px;
    color: #64748b;
    text-align: center;
    font-size: 12px;
}

input[type="range"] {
    width: 100%;
    accent-color: #111827;
}

.choice-block {
    display: grid;
    gap: 8px;
    margin-bottom: 13px;
}

.choice-title {
    color: #111827;
    font-size: 13px;
    font-weight: 700;
}

.segmented {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.segmented.four {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
}

.segmented button,
.toolbar button,
.wide-soft,
.wide-download {
    min-height: 30px;
    border: 1px solid var(--line);
    border-radius: 5px;
    color: #53637a;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
}

.segmented button {
    padding: 0 10px;
}

.segmented button.active,
.tool.active {
    color: #fff;
    border-color: var(--deep);
    background: var(--deep);
}

.brand button {
    min-width: 44px;
}

.preset button {
    min-width: 51px;
}

.wide-soft,
.wide-download {
    width: 100%;
    margin-top: 3px;
}

.wide-soft {
    background: #fff;
}

.wide-soft.muted {
    color: #a0a8b4;
    background: #f5f6f8;
}

.wide-download {
    margin-top: 8px;
    color: #fff;
    border-color: #8f939d;
    background: #8f939d;
    font-weight: 700;
}

.toolbar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
    margin-bottom: 12px;
}

#editColor {
    width: 100%;
    min-height: 30px;
    padding: 2px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: #fff;
}

.canvas-workbench {
    margin: 12px 0 10px;
    padding-right: 0;
}

.canvas-shell {
    position: relative;
    display: grid;
    place-items: center;
    height: calc(100vh - 64px);
    min-height: 620px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 14px 0 0 14px;
    background: #fff;
}

.canvas-shell.dragging {
    background: #f8fbff;
}

#patternCanvas {
    display: block;
    max-width: none;
    background: #fff;
    cursor: crosshair;
}

.upload-prompt {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 12px;
    cursor: pointer;
}

.upload-prompt input {
    display: none;
}

.upload-square {
    display: grid;
    place-items: center;
    width: 176px;
    height: 176px;
    border-radius: 15px;
    color: #fff;
    background:
        radial-gradient(circle, rgba(255,255,255,0.32) 1px, transparent 1px) 0 0 / 11px 11px,
        #0f172a;
    font-size: 74px;
    font-weight: 200;
}

.upload-prompt strong {
    font-size: 22px;
}

.upload-prompt em {
    color: var(--muted);
    font-style: normal;
    font-size: 15px;
}

.loading {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: #111827;
    background: rgba(255, 255, 255, 0.75);
    font-weight: 800;
}

.effect-section,
.features {
    padding: 34px 28px;
    border-bottom: 1px solid var(--line-soft);
}

.effect-section h2,
.features h2 {
    margin: 0 0 28px;
    color: #a23f2d;
    text-align: center;
    font-size: 25px;
    font-weight: 900;
}

.effect-pair {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 70px minmax(0, 1fr);
    align-items: center;
    gap: 24px;
}

.effect-card {
    min-width: 0;
}

.sample-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 16px 7px;
    color: #9aa5b5;
    font-size: 14px;
}

.sample-label span {
    display: inline-grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 5px;
    color: #334155;
    background: #f1f5f9;
    font-weight: 800;
}

.sample-frame {
    display: grid;
    place-items: center;
    height: 306px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fbfdff;
}

.effect-arrow {
    color: #b8c1ce;
    text-align: center;
    font-size: 28px;
}

.demo-face {
    position: relative;
    width: 256px;
    height: 256px;
    border-radius: 8px;
    background:
        radial-gradient(circle at 39% 46%, #050505 0 8px, transparent 9px),
        radial-gradient(circle at 67% 46%, #050505 0 8px, transparent 9px),
        radial-gradient(circle at 52% 55%, #f8cd27 0 7px, #050505 8px 10px, transparent 11px),
        radial-gradient(circle at 58% 70%, #f42f45 0 31px, #050505 32px 37px, transparent 38px),
        radial-gradient(circle at 50% 52%, #fff 0 82px, #050505 84px 90px, transparent 91px),
        #f7f7f7;
}

.demo-face::before {
    content: "";
    position: absolute;
    left: 92px;
    bottom: 12px;
    width: 76px;
    height: 76px;
    border: 7px solid #050505;
    border-radius: 24px 24px 18px 18px;
    background: #238ed8;
}

.demo-face::after {
    content: "";
    position: absolute;
    right: 39px;
    top: 18px;
    width: 94px;
    height: 54px;
    border-radius: 32px;
    background:
        radial-gradient(circle at 23% 48%, #f22e45 0 26px, #050505 27px 32px, transparent 33px),
        radial-gradient(circle at 55% 54%, #f22e45 0 17px, #050505 18px 23px, transparent 24px),
        radial-gradient(circle at 79% 61%, #f22e45 0 21px, #050505 22px 27px, transparent 28px);
}

.demo-pattern {
    width: 256px;
    height: 256px;
    background:
        linear-gradient(rgba(0,0,0,0.08) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0,0,0,0.08) 1px, transparent 1px),
        radial-gradient(circle at 42% 46%, #111827 0 9px, transparent 10px),
        radial-gradient(circle at 66% 46%, #111827 0 9px, transparent 10px),
        radial-gradient(circle at 52% 55%, #f6cf28 0 8px, transparent 9px),
        radial-gradient(circle at 58% 70%, #f23d4f 0 34px, #111827 35px 39px, transparent 40px),
        radial-gradient(circle at 50% 52%, #f8fafc 0 82px, #111827 83px 91px, transparent 92px),
        radial-gradient(circle at 76% 28%, #f23d4f 0 42px, #111827 43px 50px, transparent 51px);
    background-size:
        8px 8px,
        8px 8px,
        auto,
        auto,
        auto,
        auto,
        auto,
        auto;
    image-rendering: pixelated;
}

.feature-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.feature-grid article {
    min-height: 120px;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
}

.feature-icon {
    display: inline-grid;
    place-items: center;
    width: 28px;
    height: 28px;
    margin-right: 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 800;
}

.feature-icon.dark { background: #e5e7eb; color: #111827; }
.feature-icon.gray { background: #e5e7eb; color: #334155; }
.feature-icon.green { background: #d7faee; color: #10b981; }
.feature-icon.orange { background: #ffedd5; color: #fb923c; }
.feature-icon.pink { background: #fce7f3; color: #ec4899; }
.feature-icon.yellow { background: #fef3c7; color: #111827; }

.feature-grid h3 {
    display: inline;
    margin: 0;
    font-size: 16px;
}

.feature-grid p {
    margin: 16px 0 0;
    color: #64748b;
    line-height: 1.7;
    font-size: 14px;
}

.stats-drawer {
    width: min(980px, calc(100% - 32px));
    margin: 24px auto 40px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
}

.panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.panel-title h2 {
    margin: 0;
    font-size: 18px;
}

.panel-title span {
    color: var(--muted);
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    min-width: 520px;
    border-collapse: collapse;
}

th,
td {
    padding: 10px 12px;
    border: 1px solid var(--line);
    text-align: center;
    font-size: 14px;
}

th {
    background: #f8fafc;
}

.swatch {
    display: inline-block;
    width: 28px;
    height: 20px;
    border: 1px solid rgba(0,0,0,0.16);
    border-radius: 4px;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(15, 23, 42, 0.36);
}

.modal-card {
    position: relative;
    width: min(420px, 100%);
    padding: 26px;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.22);
}

.modal-card h3 {
    margin: 0 0 10px;
    font-size: 22px;
}

.modal-card p {
    margin: 0;
    color: #64748b;
    line-height: 1.7;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 12px;
    border: 0;
    background: transparent;
    font-size: 25px;
    cursor: pointer;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.modal-actions a {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 7px;
    font-weight: 800;
}

.modal-actions .primary-link {
    color: #fff;
    background: #111827;
    border-color: #111827;
}

.page {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 30px 0 42px;
}

.site-header {
    text-align: center;
    margin-bottom: 22px;
}

.site-header h1 {
    margin: 0 0 12px;
}

.top-nav,
.auth-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.top-nav a,
.auth-links a {
    color: #2563eb;
    font-weight: 700;
}

.panel,
.auth-card,
.admin-panel,
.stat-card {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
}

.auth-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
}

.auth-card {
    width: min(460px, 100%);
    padding: 24px;
}

.auth-form {
    display: grid;
    gap: 14px;
}

.field {
    display: grid;
    gap: 6px;
}

.field span {
    color: #64748b;
    font-size: 14px;
}

.field input {
    width: 100%;
    height: 38px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
}

button.primary,
.auth-form button.primary {
    color: #fff;
    background: #111827;
    border-color: #111827;
}

.notice {
    padding: 10px 12px;
    border-radius: 6px;
    line-height: 1.5;
    text-align: center;
}

.notice.success { color: #166534; background: #dcfce7; }
.notice.error { color: #991b1b; background: #fee2e2; }
.notice.warn { color: #854d0e; background: #fef3c7; }

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

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

.stat-card,
.admin-panel {
    padding: 16px;
}

.stat-card {
    display: grid;
    gap: 6px;
    text-align: center;
}

.stat-card strong {
    color: #2563eb;
    font-size: 30px;
}

.muted-text,
.stat-card span {
    color: #64748b;
}

.code-output {
    width: 100%;
    min-height: 150px;
    margin-top: 12px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-family: Consolas, monospace;
    resize: vertical;
}

.mono {
    font-family: Consolas, "Courier New", monospace;
}

@media (max-width: 980px) {
    .app-header {
        height: auto;
        min-height: 42px;
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
        padding: 8px;
    }

    .header-nav {
        width: 100%;
        overflow-x: auto;
        padding-bottom: 2px;
    }

    .generator-layout {
        grid-template-columns: 1fr;
    }

    .tool-sidebar {
        margin: 10px;
    }

    .canvas-workbench {
        margin: 0 10px 10px;
    }

    .canvas-shell {
        height: 62vh;
        min-height: 430px;
        border-radius: 14px;
    }

    .effect-pair {
        grid-template-columns: 1fr;
    }

    .effect-arrow {
        transform: rotate(90deg);
    }

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

@media (max-width: 620px) {
    .toggle-row,
    .segmented.four,
    .toolbar,
    .dashboard-grid,
    .dashboard-grid.two {
        grid-template-columns: 1fr;
    }

    .sample-frame {
        height: 260px;
    }

    .demo-face,
    .demo-pattern {
        transform: scale(0.86);
    }

    .effect-section,
    .features {
        padding: 28px 14px;
    }
}
