:root {
    --side: #0f2b23;
    --side-t: #dfe8e3;
    --bg: #f5f3ef;
    --surface: #fffdf8;
    --line: #e6e1d6;
    --ink: #13302a;
    --mute: #5d6b65;
    --accent: #1f5c47;
    --accent-ink: #fff;
    --accent-soft: #e1efe8;
    --draft: #efe9da;
    --draft-t: #6b5a2b;
    --danger: #8e2b22;
    --danger-soft: #f8e9e6;
    --ok: #2f7d4f;
    --star: #c58a00;
    --warn: #9a5b00;
    --ai: #e4e9f5;
    --ai-t: #2a3d73;
    --focus: #3b82f6;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #121a17;
        --surface: #1a2420;
        --line: #2b3832;
        --ink: #e8efeb;
        --mute: #9fb0a8;
        --accent: #7cc7a2;
        --accent-ink: #0d1a14;
        --accent-soft: #20372d;
        --draft: #3a3320;
        --draft-t: #e6d28f;
        --danger: #e58a7f;
        --danger-soft: #3a1f1c;
        --star: #f0b429;
        --warn: #f0b429;
        --ai: #25304f;
        --ai-t: #b9c8f5;
    }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body.is-auth { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr, .visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.side { background: var(--side); color: var(--side-t); padding: 24px 18px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side b, .side .brand { font-size: 19px; color: #fff; text-decoration: none; }
.side small, .acc { display: block; opacity: .8; font-size: 13px; }
.side nav { margin-top: 28px; display: grid; gap: 4px; }
.side a, .side .link-button { color: var(--side-t); text-decoration: none; padding: 10px 14px; border-radius: 8px; background: none; border: 0; font: inherit; text-align: left; cursor: pointer; }
.side a:hover, .side a.on, .side .link-button:hover { background: #ffffff1f; }
.side .sp { flex: 1; }
.side form { margin: 0; }
.bar, .scrim { display: none; }
.workspace { min-width: 0; }
main { padding: 32px clamp(20px, 4vw, 56px) 64px; min-width: 0; max-width: 1200px; }
.guest-canvas { min-height: 100vh; display: grid; place-items: center; padding: 24px; }

.head, .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
h1 { margin: 0; font-size: clamp(26px, 3vw, 34px); letter-spacing: -.01em; line-height: 1.2; }
.top h1 { font-size: clamp(26px, 3.2vw, 38px); line-height: 1.15; max-width: 24ch; }
.sub { color: var(--mute); font-size: 15px; margin: 2px 0 0; }
.crumbs { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; justify-content: space-between; font-size: 14px; color: var(--mute); margin-bottom: 14px; }
.crumbs-path { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; min-width: 0; }
.crumbs a { font-weight: 600; text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.crumbs [aria-current="page"] { overflow-wrap: anywhere; }

.btn, .link-button { font: inherit; font-weight: 600; cursor: pointer; }
.btn { font-size: 15px; min-height: 44px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:hover { border-color: var(--accent); }
.btn.pri, .guest-canvas .btn { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-quiet { background: transparent; color: var(--accent); border-color: transparent; }
.btn[disabled], .is-pending { opacity: .7; cursor: progress; }
.spinner { width: 1em; height: 1em; flex: 0 0 auto; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: admin-spin .7s linear infinite; }
.pending-label { margin-left: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib.is-pending .spinner, .image-more.is-pending .spinner, .ia.is-pending .spinner { width: 16px; height: 16px; }

.tabs { display: flex; gap: 4px; margin: 22px 0 16px; padding: 6px 8px; background-image: linear-gradient(var(--line), var(--line)); background-repeat: no-repeat; background-size: 100% 1px; background-position: left calc(100% - 6px); }
.tab { font: inherit; font-weight: 600; background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 14px; min-height: 44px; color: var(--mute); text-decoration: none; white-space: nowrap; display: inline-flex; align-items: center; }
.tab[aria-current="page"] { color: var(--ink); border-color: var(--accent); }
.tab em { font-style: normal; font-size: 13px; margin-left: 6px; padding: 1px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.tools { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.search { flex: 1 1 280px; }
.search input, .tools select, input[type=text], input[type=url], input[type=password], input[type=search], select, textarea { font: inherit; width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); padding: 0 14px; }
textarea { padding: 12px 14px; min-height: 220px; line-height: 1.6; resize: vertical; }
input:hover, textarea:hover, select:hover { border-color: #8aa89b; }
[aria-invalid=true] { border-color: var(--danger); }
.count, .hint, .muted { color: var(--mute); }
.count { font-size: 14px; margin: 0 0 12px; }
.hint { font-size: 14px; margin: 0; }
.check .hint, .check small { display: block; font-weight: 400; margin-top: 2px; }

.list { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.row { display: grid; grid-template-columns: 128px minmax(0, 1fr) auto auto; gap: 8px 20px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.row:hover { border-color: var(--accent); }
.thumb { width: 128px; aspect-ratio: 3 / 2; border-radius: 10px; object-fit: cover; background: var(--accent-soft); display: block; }
.info { min-width: 0; }
.title { font-weight: 700; font-size: 17px; line-height: 1.35; color: var(--ink); text-decoration: none; display: block; }
.title:hover { text-decoration: underline; }
.facts { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--mute); font-size: 14px; margin-top: 6px; }
.facts span + span::before { content: "·"; margin-right: 14px; }
.state { display: grid; justify-items: start; gap: 6px; min-width: 150px; }
.pill, .chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.pill i, .chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.pill.draft { background: var(--draft); color: var(--draft-t); }
.pill.draft i { background: var(--draft-t); }
.pill.feat { background: transparent; color: var(--star); border: 1px solid currentColor; }
.chip.ai { background: var(--ai); color: var(--ai-t); }
.link { font: inherit; font-size: 14px; font-weight: 600; color: var(--accent); background: none; border: 0; padding: 6px 0; min-height: 36px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.acts { display: flex; gap: 6px; align-items: center; }
.acts form, .seg form { margin: 0; }
.ib { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: transparent; color: var(--ink); cursor: pointer; display: grid; place-items: center; text-decoration: none; padding: 0; }
.ib:hover { background: var(--accent-soft); border-color: var(--accent); }
.ib[aria-pressed=true], .ib.is-active { color: var(--star); border-color: var(--star); }
.ib[aria-pressed=true] svg, .ib.is-active svg { fill: currentColor; }
.ib.del { color: var(--danger); margin-left: 6px; }
.ib.del:hover { background: var(--danger-soft); border-color: var(--danger); }
.empty { text-align: center; padding: 56px 20px; border: 1px dashed var(--line); border-radius: 16px; color: var(--mute); }
.empty b { display: block; color: var(--ink); font-size: 18px; margin-bottom: 4px; }

.grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 32px; align-items: start; }
.hero, .hero img, .image-open.hero { width: 100%; aspect-ratio: 16 / 8; border-radius: 18px; object-fit: cover; background: var(--accent-soft); display: block; position: relative; }
.image-open.hero { padding: 0; border: 0; cursor: zoom-in; }
.image-open.hero .chip { position: absolute; left: 14px; top: 14px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); margin: 20px 0 8px; border-block: 1px solid var(--line); }
.stats div { padding: 16px 0 16px 20px; border-left: 1px solid var(--line); }
.stats div:first-child { border-left: 0; padding-left: 0; }
.stats dt { font-size: 13px; color: var(--mute); text-transform: uppercase; letter-spacing: .06em; }
.stats dd { margin: 2px 0 0; font-size: 26px; font-weight: 700; }
article { max-width: 68ch; padding-top: 16px; }
article .lead { font-size: 19px; line-height: 1.55; }
article p { margin: 0 0 1.1em; }
.rail { position: sticky; top: 20px; display: grid; gap: 16px; }
.panel, .card, .auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 20px; }
.auth-card { width: min(100%, 420px); }
.panel h2, .sec > h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--mute); margin: 0 0 16px; font-weight: 700; }
.sec { padding: 0 0 28px; margin-bottom: 28px; border-bottom: 1px solid var(--line); }
.sec:last-of-type { border-bottom: 0; }
.f { display: grid; gap: 6px; margin-bottom: 18px; }
label { font-weight: 600; }
label i { color: var(--danger); font-style: normal; }
.err, .field-error, .alert-error { color: var(--danger); font-weight: 600; }
.err, .field-error { font-size: 14px; margin: 0; }
.alert { padding: 10px 12px; border-radius: 10px; margin-bottom: 16px; }
.alert-success { background: var(--accent-soft); }
.alert-error { background: var(--danger-soft); }
.row2, .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.meter { display: flex; justify-content: flex-end; font-size: 14px; color: var(--mute); }
.meter.warn b { color: var(--warn); }
.urlrow, .source-row { display: flex; gap: 10px; }
.urlrow input, .source-row input { flex: 1; min-width: 0; }
details.adv { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
details.adv > summary { cursor: pointer; font-weight: 700; padding: 14px 16px; min-height: 48px; list-style: none; }
details.adv > summary::-webkit-details-marker { display: none; }
details.adv > div { padding: 0 16px 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chips label { font-weight: 500; font-size: 14px; display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 99px; min-height: 40px; }
.chips label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 600; }
.check input, .chips input { width: 18px; height: 18px; accent-color: var(--accent); }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 12px; padding: 4px; gap: 4px; }
.seg form { display: contents; }
.seg button { font: inherit; font-weight: 600; min-height: 44px; border: 0; border-radius: 9px; background: transparent; color: var(--mute); cursor: pointer; }
.seg button[aria-pressed=true] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px #0002; }
.panel .btn, .panel form { width: 100%; }
.panel form .btn { width: 100%; }
.src { word-break: break-all; font-size: 14px; color: var(--mute); margin: 0 0 12px; }
.protect { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.protect span { font-size: 13px; padding: 3px 10px; border-radius: 99px; border: 1px solid var(--line); }
.kv, .details { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; margin: 12px 0 0; }
.kv dt, .details dt { color: var(--mute); }
.kv dd, .details dd { margin: 0; text-align: right; }
.danger { border-color: var(--danger-soft); background: var(--danger-soft); }
.hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

.img, .image-drop-zone { position: relative; aspect-ratio: 3 / 2; border-radius: 12px; overflow: hidden; background: var(--accent-soft); border: 1px dashed var(--line); }
.image-drop-zone .card-preview, .image-drop-zone .image-open { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border: 0; padding: 0; background: transparent; }
.image-open { display: block; width: 100%; margin: 0; cursor: zoom-in; }
.image-open[hidden], .image-drop-zone .image-open[hidden], #image-more[hidden], #image-remove[hidden], #image-save-current[hidden], .generate-row[hidden], #library-title-field[hidden], #image-library-saved[hidden], .library-grid[hidden], #image-library-empty[hidden], #image-generate-error[hidden], .page-progress[hidden], .image-modal[hidden], #image-ai-tag[hidden] { display: none; }
.image-drop-zone .chip { position: absolute; left: 10px; top: 10px; z-index: 1; }
.card-preview-empty { min-height: 100%; display: grid; place-items: center; text-align: center; color: var(--mute); padding: 16px; }
.image-file-input { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
.imgacts, .image-toolbar { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) 44px; gap: 8px; margin: 12px 0; }
.imgacts > *, .image-toolbar > * { min-width: 0; }
.ia, .image-tool { display: grid; justify-items: center; align-content: center; gap: 2px; min-height: 60px; padding: 8px 4px; font: inherit; font-size: 13px; font-weight: 600; border: 1px solid var(--line); border-radius: 10px; background: transparent; color: var(--ink); cursor: pointer; text-align: center; }
.ia.is-pending { place-items: center; align-content: center; overflow: hidden; }
.ia:hover, .image-tool:hover, .image-tool[aria-expanded=true] { background: var(--accent-soft); border-color: var(--accent); }
.more-menu { position: relative; }
.image-more { min-height: 60px; }
.more-panel { position: absolute; right: 0; top: calc(100% + 6px); z-index: 6; min-width: 220px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 6px; }
.more-panel button { display: block; width: 100%; text-align: left; font: inherit; padding: 10px 12px; border: 0; background: none; color: var(--ink); border-radius: 8px; cursor: pointer; min-height: 44px; }
.more-panel button:hover, .more-panel button:focus { background: var(--accent-soft); }
#image-remove { color: var(--danger); }
.generate-row, .button-row, .btns { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 8px; max-height: 240px; overflow: auto; margin-top: 8px; }
.library-grid-page { max-height: none; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.library-thumb, .library-card { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 6px; text-align: left; }
.library-thumb { cursor: pointer; width: 100%; }
.library-thumb img, .library-card img, .library-card .image-open img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 6px; display: block; }
.library-thumb span, .library-card h3 { display: block; margin: 6px 0 0; font-size: .9rem; }
.library-thumb.is-selected { border-color: var(--accent); }
.library-card > form, .rename { margin-top: 10px; }
.saved-note, .image-status.is-saved { color: var(--accent); font-weight: 700; }
.image-status.is-unsaved { color: var(--warn); }
.image-status.is-library { color: var(--ai-t); }
.pos { display: grid; grid-template-columns: repeat(3, 44px); gap: 6px; margin: 10px 0; }
.pos label { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 8px; display: grid; place-items: center; }
.pos label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); }
.focus-controls input[type=range] { width: 100%; padding: 0; min-height: 32px; }
.save-bar { position: sticky; bottom: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 8px calc(-1 * clamp(20px, 4vw, 56px)) 0; padding: 14px clamp(20px, 4vw, 56px) calc(14px + env(safe-area-inset-bottom, 0px)); background: var(--bg); border-top: 1px solid var(--line); }
.save-bar .state { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--mute); font-size: 15px; }
.save-bar .state i { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.save-bar.dirty .state { color: var(--ink); font-weight: 600; }
.save-bar.dirty .state i { background: var(--warn); }
.meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; align-items: center; color: var(--mute); }

.page-progress { position: fixed; top: 0; left: 0; right: 0; z-index: 80; pointer-events: none; }
.page-progress-bar { height: 3px; overflow: hidden; background: rgba(28, 61, 48, .18); }
.page-progress-bar::after { content: ""; display: block; height: 100%; width: 35%; background: var(--accent); animation: admin-progress 1.1s ease-in-out infinite; }
.page-progress-status { width: max-content; max-width: calc(100% - 24px); margin: 0 auto; padding: 3px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: var(--accent); color: var(--accent-ink); font-size: .75rem; font-weight: 650; border-radius: 0 0 8px 8px; }
.page-progress-status:empty { display: none; }
.image-modal { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 16px; }
.image-modal-backdrop { position: absolute; inset: 0; background: rgba(15, 43, 35, .55); }
.image-modal-panel { position: relative; width: min(960px, 100%); max-height: calc(100vh - 32px); overflow: auto; display: flex; flex-direction: column; gap: 12px; padding: 16px; background: var(--surface); border-radius: 16px; }
.image-modal-panel img { width: 100%; max-height: min(72vh, 720px); object-fit: contain; background: var(--accent-soft); border-radius: 8px; }
body.image-modal-open, body.nav-open { overflow: hidden; }
.rename summary { cursor: pointer; }

@media (max-width: 1100px) {
    .row { grid-template-columns: 112px minmax(0, 1fr); }
    .thumb { width: 112px; }
    .state, .acts { grid-column: 1 / -1; }
    .state { grid-auto-flow: column; justify-content: start; align-items: center; }
    .acts { border-top: 1px solid var(--line); padding-top: 10px; }
    .ib.del { margin-left: auto; }
    .grid { grid-template-columns: 1fr; }
    .rail { position: static; }
}
@media (max-width: 900px) {
    body.is-auth { grid-template-columns: 1fr; }
    .bar { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 30; background: var(--side); color: #fff; padding: calc(env(safe-area-inset-top, 0px) + 6px) 12px 6px 8px; min-height: 60px; }
    .burger { width: 48px; height: 48px; border: 0; background: transparent; border-radius: 10px; cursor: pointer; display: grid; place-content: center; gap: 5px; }
    .burger span { display: block; width: 22px; height: 2px; background: #fff; border-radius: 2px; transition: transform .25s, opacity .2s; }
    .burger[aria-expanded=true] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
    .burger[aria-expanded=true] span:nth-child(2) { opacity: 0; }
    .burger[aria-expanded=true] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
    .side { position: fixed; z-index: 50; top: 0; left: 0; width: min(84vw, 300px); height: 100dvh; padding-top: calc(env(safe-area-inset-top, 0px) + 24px); overflow-y: auto; transform: translateX(-100%); visibility: hidden; transition: transform .28s ease, visibility 0s .28s; }
    .side.open { transform: none; visibility: visible; transition: transform .28s ease; box-shadow: 8px 0 32px #0006; }
    .side a, .side .link-button { min-height: 48px; display: flex; align-items: center; }
    .scrim { display: block; position: fixed; inset: 0; z-index: 40; background: #000a; opacity: 0; pointer-events: none; transition: opacity .25s; }
    .scrim.open { opacity: .55; pointer-events: auto; }
    main { padding-top: 20px; }
    .top h1 { max-width: none; }
}
@media (max-width: 720px) {
    .tabs { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; scroll-padding-inline: 8px; overscroll-behavior-x: contain; }
    .tab { scroll-margin-inline: 8px; }
    .tabs::-webkit-scrollbar { display: none; width: 0; height: 0; }
}
@media (max-width: 640px) {
    .head .btn, .top .btn { width: 100%; }
    .row { grid-template-columns: 88px minmax(0, 1fr); }
    .thumb { width: 88px; }
    .stats dd { font-size: 20px; }
    .row2, .form-row, .urlrow, .source-row { grid-template-columns: 1fr; flex-direction: column; }
    .imgacts, .image-toolbar { grid-template-columns: 1fr 1fr; }
    .save-bar, .btns { align-items: stretch; }
    .btns .btn { flex: 1; }
    .state { grid-auto-flow: row; }
}
@media (max-width: 420px) {
    .image-modal { padding: 8px; }
    .image-modal-panel .button-row .btn { flex: 1 1 120px; }
}
@keyframes admin-spin { to { transform: rotate(360deg); } }
@keyframes admin-progress { 0% { transform: translateX(-120%); } 100% { transform: translateX(320%); } }
@media (prefers-reduced-motion: reduce) {
    .side, .scrim, .burger span, .row { transition: none; }
    .spinner, .page-progress-bar::after { animation: none; }
    .page-progress-bar::after { width: 100%; }
}
