:root {
    color-scheme: light;
    --ink: #171916;
    --muted: #5d635e;
    --rail: #29463e;
    --paper: #f3f1e9;
    --accent: #7f2f22;
}

* { box-sizing: border-box; }

html {
    font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(circle at 20% 20%, rgba(40, 55, 45, .05) 0 1px, transparent 2px),
        var(--paper);
    line-height: 1.75;
    overflow-x: hidden;
}

.artwork-page { min-height: 100vh; display: grid; grid-template-columns: 7.5rem minmax(0, 1fr); }

.brand-rail {
    position: sticky;
    top: 0;
    align-self: start;
    height: 100vh;
    min-height: 100vh;
    padding: 2.5rem 0;
    color: white;
    background: var(--rail);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
}

.brand-rail span, .brand-rail strong {
    writing-mode: vertical-rl;
    letter-spacing: .08em;
    font-size: 1.25rem;
}
.brand-rail strong { font-size: 1.4rem; }

.site-brands {
    position: fixed;
    z-index: 1;
    top: 2rem;
    bottom: 2rem;
    right: 2.5rem;
    max-width: 18rem;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: space-between;
    gap: .75rem;
    text-align: right;
}
.site-brands img {
    display: block;
    width: auto;
    max-width: 12rem;
    max-height: 4.5rem;
    object-fit: contain;
}
.supporting-brand {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: .65rem;
    color: var(--muted);
    font-size: .82rem;
}
.supporting-brand img {
    max-width: 8rem;
    max-height: 2.75rem;
}

.artwork-shell {
    width: min(1600px, 100%);
    min-height: 100vh;
    margin: auto;
    padding: clamp(2.5rem, 5vw, 6rem);
    display: grid;
    grid-template-columns: minmax(340px, .85fr) minmax(420px, 1.35fr);
    gap: clamp(3rem, 6vw, 7rem);
    align-items: start;
}

.artwork-media {
    width: 100%;
    max-width: 34rem;
    justify-self: start;
}

.artwork-media img {
    width: 100%;
    max-height: 70vh;
    object-fit: contain;
    display: block;
    background: #fff;
    padding: .6rem;
    box-shadow: 0 12px 35px rgba(0, 0, 0, .12);
}
.public-image-gallery { display: grid; gap: 1.25rem; }

.image-placeholder {
    aspect-ratio: 4 / 5;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, .55);
    color: var(--muted);
}

.artwork-content header {
    padding-left: 1.5rem;
    border-left: 2px solid var(--accent);
}

.english-name { margin: 0; font-size: clamp(1.15rem, 2.4vw, 2rem); letter-spacing: .24em; font-weight: 700; }
h1 { margin: .4rem 0 0; font-size: clamp(1.8rem, 3.2vw, 3rem); }
h2 { font-size: 1rem; letter-spacing: .12em; }
.artwork-content { min-width: 0; overflow-wrap: anywhere; }

.metadata { margin: 2rem 0; }
.metadata div { display: grid; grid-template-columns: 6rem 1fr; }
.metadata dt { color: var(--muted); }
.metadata dd { margin: 0; font-weight: 600; }
.status { color: white; background: var(--accent); border-radius: 999px; padding: .2rem .75rem; }
.prose {
    margin-top: 1.25rem;
    white-space: pre-line;
}
.prose h2 {
    margin: 0;
    font-size: clamp(1.05rem, 1.15vw, 1.25rem);
    letter-spacing: .14em;
}
.prose p {
    margin: .55rem 0 0;
    font-size: clamp(1.05rem, 1.25vw, 1.35rem);
    line-height: 1.9;
    letter-spacing: .07em;
}
.creative-concept { margin-top: .8rem; }
.rich-editor {
    border: 1px solid #a6aaa6;
    border-radius: .3rem;
    overflow: hidden;
    background: white;
}
.rich-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    padding: .5rem;
    border-bottom: 1px solid #d4d0c5;
    background: #f1f0eb;
}
.rich-toolbar button {
    padding: .35rem .6rem;
    color: var(--ink);
    background: white;
    border: 1px solid #c8c5bc;
    font-size: .9rem;
}
.color-tools {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    margin-left: .25rem;
}
.rich-toolbar .color-swatch {
    width: 1.65rem;
    height: 1.65rem;
    padding: 0;
    border: 2px solid white;
    border-radius: 50%;
    box-shadow: 0 0 0 1px #8d8d88;
}
.color-black { background: #171b1a !important; }
.color-red { background: #a12622 !important; }
.color-blue { background: #225f92 !important; }
.color-green { background: #276b50 !important; }
.color-gold { background: #9a681b !important; }
.rich-content {
    min-height: 11rem;
    padding: .8rem;
    outline: none;
}
.rich-content:focus { box-shadow: inset 0 0 0 2px #527b70; }
.rich-source { display: none; }
.rich-output {
    margin-top: .55rem;
    font-size: clamp(1.05rem, 1.25vw, 1.35rem);
    line-height: 1.9;
    letter-spacing: .07em;
}
.rich-output p, .rich-output > div { margin: .45rem 0; }
.rich-output a { text-decoration: underline; overflow-wrap: anywhere; }
.rich-output ul {
    list-style: disc;
    margin: .5rem 0;
    padding-left: 1.75rem;
}
.rich-output ol {
    list-style: decimal;
    margin: .5rem 0;
    padding-left: 1.75rem;
}
.rich-output li { margin: .2rem 0; }
.rich-content [data-color="black"], .rich-output [data-color="black"] { color: #171b1a; }
.rich-content [data-color="red"], .rich-output [data-color="red"] { color: #a12622; }
.rich-content [data-color="blue"], .rich-output [data-color="blue"] { color: #225f92; }
.rich-content [data-color="green"], .rich-output [data-color="green"] { color: #276b50; }
.rich-content [data-color="gold"], .rich-output [data-color="gold"] { color: #9a681b; }
.form-actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1rem; }
.image-settings-form { display: grid; gap: .55rem; width: 100%; }
.image-settings-form input[type="text"], .image-settings-form input:not([type]) { width: 100%; }
.artwork-preview-dialog {
    width: min(76rem, 94vw);
    max-height: 92vh;
    padding: 0;
    border: 0;
    border-radius: .5rem;
    color: var(--ink);
    background: var(--paper);
}
.artwork-preview-dialog::backdrop { background: rgb(0 0 0 / 55%); }
.preview-dialog-header {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: .8rem 1rem;
    border-bottom: 1px solid #cbc6b8;
    background: white;
}
.preview-full-page { position: relative; min-height: 80vh; }
.preview-full-page .brand-rail { position: sticky; }
.preview-full-page .site-brands { position: absolute; }
.preview-full-page .artwork-shell { min-height: 80vh; }
.message-page { width: min(42rem, 90%); margin: 15vh auto; text-align: center; }

a { color: #204f43; }
button, .button {
    border: 0;
    border-radius: .35rem;
    padding: .75rem 1.2rem;
    color: white;
    background: var(--rail);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
}
.button-secondary { color: var(--rail); background: transparent; border: 1px solid var(--rail); }
.button-danger { background: #8f2525; }
.form-page { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1rem; }
.form-card {
    width: min(30rem, 100%);
    padding: clamp(1.5rem, 5vw, 3rem);
    background: white;
    box-shadow: 0 15px 45px rgba(0, 0, 0, .08);
    display: grid;
    gap: .65rem;
}
.form-card label { margin-top: .5rem; font-weight: 700; }
.form-card input:not([type="checkbox"]), .form-card select {
    width: 100%;
    border: 1px solid #a6aaa6;
    border-radius: .3rem;
    padding: .75rem;
    font: inherit;
    background: white;
}
.form-card button { margin-top: 1rem; }
.checkbox { display: flex; gap: .5rem; align-items: center; }
.validation { color: #9b1c1c; }
.validation-errors {
    padding: .8rem 1rem;
    color: #861b1b;
    background: #fff0f0;
    border: 2px solid #b52a2a;
    border-radius: .25rem;
}
.validation-errors ul { margin: .35rem 0 0; padding-left: 1.25rem; }
.password-requirements {
    margin-top: .35rem;
    padding: .75rem 1rem;
    color: #3f4842;
    background: #eef4f1;
    border-left: 4px solid var(--rail);
    font-size: .9rem;
}
.password-requirements ul { margin: .25rem 0 0; padding-left: 1.25rem; }
.validation-summary-valid,
.field-validation-valid { display: none; }
.admin-page { width: min(70rem, 92%); margin: 4rem auto; }
.artwork-admin-page { width: min(108rem, 96%); }
.admin-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.eyebrow { letter-spacing: .2em; color: var(--muted); }
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1rem; }
.admin-card { padding: 1.5rem; background: white; border: 1px solid #dedbd2; }
.admin-link { color: inherit; text-decoration: none; }
.notice { padding: .8rem 1rem; background: #dfefe8; border-left: 4px solid var(--rail); }
.table-wrap { overflow-x: auto; background: white; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .9rem 1rem; border-bottom: 1px solid #e3e1da; text-align: left; vertical-align: middle; }
.artwork-thumbnail-cell { width: 6rem; }
.artwork-thumbnail-link { display: inline-block; }
.artwork-list-thumbnail {
    display: block;
    width: 5rem;
    height: 4rem;
    object-fit: cover;
    border: 1px solid #dedbd2;
    background: #f4f2eb;
}
.artwork-thumbnail-placeholder {
    display: grid;
    place-items: center;
    width: 5rem;
    height: 4rem;
    color: var(--muted);
    background: #f4f2eb;
    font-size: .85rem;
}
.artwork-name-link { color: inherit; text-decoration: none; }
.artwork-name-link:hover,
.artwork-name-link:focus-visible { color: var(--rail); text-decoration: underline; }
.artwork-actions-heading { min-width: 13rem; }
.artwork-admin-page td.actions {
    display: table-cell;
    min-width: 13rem;
    white-space: nowrap;
}
.artwork-admin-page td.actions a { display: inline-block; margin-right: .65rem; }
.artwork-filters {
    margin: 1.5rem 0 .75rem;
    padding: 1rem;
    background: white;
    border: 1px solid #dedbd2;
    display: grid;
    grid-template-columns: minmax(14rem, 2fr) minmax(10rem, 1fr) minmax(10rem, 1fr) auto;
    gap: 1rem;
    align-items: end;
}
.artwork-filters > div { display: grid; gap: .35rem; }
.artwork-filters input,
.artwork-filters select {
    width: 100%;
    min-height: 2.9rem;
    border: 1px solid #a6aaa6;
    border-radius: .3rem;
    padding: .65rem;
    background: white;
    font: inherit;
}
.filter-actions {
    display: flex !important;
    grid-template-columns: 1fr 1fr;
    gap: .5rem !important;
}
.result-count { color: var(--muted); }
.pagination {
    margin-top: 1.25rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
}
.publish-setting {
    padding: .85rem 1rem;
    background: #eef4f1;
    border-left: 4px solid var(--rail);
}
.sort-actions { display: flex; gap: .3rem; }
.sort-actions form { margin: 0; }
.compact-button {
    min-width: 2.2rem;
    min-height: 2.2rem;
    padding: .25rem .5rem;
}
.back-to-gallery {
    display: inline-block;
    margin-bottom: 1.25rem;
}
.gallery-page { width: min(90rem, 92%); margin: 0 auto; padding: 3rem 0 5rem; }
.gallery-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
    margin-bottom: 2rem;
}
.gallery-brands { display: flex; align-items: center; gap: 1.5rem; }
.gallery-brands img { max-width: 10rem; max-height: 4rem; object-fit: contain; }
.public-filters {
    display: grid;
    grid-template-columns: minmax(14rem, 2fr) minmax(9rem, 1fr) minmax(9rem, 1fr) auto auto;
    gap: .75rem;
    align-items: center;
    padding: 1rem;
    background: white;
    border: 1px solid #dedbd2;
}
.public-filters input,
.public-filters select {
    width: 100%;
    min-height: 2.9rem;
    border: 1px solid #a6aaa6;
    border-radius: .3rem;
    padding: .65rem;
    background: white;
    font: inherit;
}
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
    gap: 1.5rem;
}
.gallery-card {
    display: block;
    color: inherit;
    text-decoration: none;
    background: rgba(255, 255, 255, .78);
    border: 1px solid #dedbd2;
    transition: transform .18s ease, box-shadow .18s ease;
}
.gallery-card:hover,
.gallery-card:focus-visible {
    transform: translateY(-3px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, .1);
}
.gallery-card img,
.gallery-placeholder {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    display: grid;
    place-items: center;
    background: #ebe9e1;
}
.gallery-card-content { padding: 1rem; }
.gallery-card-content h2 { margin: 0; font-size: 1.25rem; }
.gallery-card-content p { margin: .25rem 0; color: var(--muted); }
.gallery-empty { padding: 3rem; text-align: center; background: white; }
.load-more { margin-top: 2rem; text-align: center; }
.category-create {
    margin: 1.5rem 0;
    padding: 1rem;
    background: white;
    border: 1px solid #dedbd2;
    display: flex;
    align-items: end;
    gap: 1rem;
}
.category-create > div { flex: 1; display: grid; gap: .35rem; }
.category-create input {
    width: 100%;
    border: 1px solid #a6aaa6;
    border-radius: .3rem;
    padding: .7rem;
    font: inherit;
}
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: .8rem; }
.editor-page { width: min(76rem, 94%); margin: 3rem auto; }
.editor-form { display: grid; gap: 1.5rem; }
.editor-form fieldset {
    border: 1px solid #d4d0c5;
    background: rgba(255, 255, 255, .65);
    padding: clamp(1rem, 3vw, 2rem);
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem 1.5rem;
}
.editor-form legend { padding: 0 .5rem; font-size: 1.2rem; font-weight: 800; }
.field-with-toggle { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .75rem; align-items: end; }
.field-with-toggle > div { display: grid; gap: .35rem; }
.field-with-toggle input:not([type="checkbox"]),
.field-with-toggle select,
.field-with-toggle textarea,
.editor-form input[type="file"] {
    width: 100%;
    border: 1px solid #a6aaa6;
    border-radius: .3rem;
    padding: .7rem;
    font: inherit;
    background: white;
}
.field-wide { grid-column: 1 / -1; }
.image-manager { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid #d4d0c5; }
.image-manager-header {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 1rem;
    margin-bottom: 1rem;
    padding: .65rem 0;
    background: var(--paper);
}
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: 1rem; }
.image-card { background: white; padding: .75rem; border: 2px solid transparent; }
.image-card.is-dragging { opacity: .55; border-color: var(--accent); }
.image-card.is-pending-delete {
    opacity: .48;
    border-color: #a12622;
    background: #eee9e4;
}
.image-card.is-pending-delete img { filter: grayscale(1); }
.pending-delete-label {
    color: #8f2525;
    font-size: .85rem;
    font-weight: 700;
}
.image-card img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; margin-bottom: .75rem; }
.drag-handle {
    margin: -.25rem 0 .5rem;
    color: var(--muted);
    cursor: grab;
    user-select: none;
    text-align: center;
    font-size: .85rem;
}
.drag-handle:active { cursor: grabbing; }
.compact-action { width: auto; padding: .4rem .7rem; font-size: .88rem; }
.image-settings-form + form {
    margin-top: .75rem;
    padding-top: .65rem;
    border-top: 1px solid #e0ddd5;
}
.new-image-settings {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
    gap: .8rem;
    margin-top: .75rem;
}
.new-image-card {
    display: grid;
    gap: .5rem;
    padding: .75rem;
    border: 1px solid #d4d0c5;
    background: white;
}
.new-image-card img { width: 100%; height: 10rem; object-fit: contain; }
.new-image-card label { display: grid; gap: .3rem; }
.new-image-card input { width: 100%; padding: .55rem; font: inherit; }
@media (max-width: 760px) {
    .image-manager-header { align-items: stretch; flex-direction: column; }
}
.qr-panel {
    margin: 1.5rem 0;
    padding: 1.25rem;
    background: white;
    border: 1px solid #d4d0c5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
}
.qr-panel img { width: 13rem; height: 13rem; image-rendering: pixelated; }
.setting-field { display: grid; gap: .35rem; }
.setting-field input {
    width: 100%;
    border: 1px solid #a6aaa6;
    border-radius: .3rem;
    padding: .7rem;
    font: inherit;
    background: white;
}
.logo-setting-preview {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
}
.logo-setting-preview img {
    width: auto;
    max-width: 14rem;
    max-height: 6rem;
    object-fit: contain;
    background: white;
    padding: .5rem;
    border: 1px solid #d4d0c5;
}

@media (max-width: 900px) {
    .editor-form fieldset { grid-template-columns: 1fr; }
    .field-wide { grid-column: auto; }
    .admin-header { align-items: flex-start; flex-direction: column; }
    .qr-panel { align-items: flex-start; flex-direction: column; }
    .artwork-filters { grid-template-columns: 1fr 1fr; }
    .artwork-filters > div:first-child { grid-column: 1 / -1; }
    .public-filters { grid-template-columns: 1fr 1fr; }
    .public-filters input { grid-column: 1 / -1; }
    .gallery-header { align-items: flex-start; }
}

@media (max-width: 900px) {
    .artwork-page {
        display: flex;
        flex-direction: column;
    }
    .brand-rail {
        position: static;
        order: 0;
        width: 100%;
        min-height: auto;
        height: 4rem;
        padding: 0 1.25rem;
        flex-direction: row;
        justify-content: space-between;
        gap: .75rem;
        overflow: hidden;
    }
    .brand-rail span, .brand-rail strong {
        writing-mode: horizontal-tb;
        flex: 0 0 auto;
        max-width: calc(50% - .375rem);
        white-space: nowrap;
        line-height: 1;
    }
    .brand-rail span { font-size: clamp(.95rem, 5vw, 1.25rem); }
    .brand-rail strong {
        margin-left: auto;
        font-size: clamp(1.05rem, 5.5vw, 1.4rem);
    }
    .site-brands {
        position: static;
        order: 2;
        width: 100%;
        max-width: none;
        padding: 0 1.5rem 1.5rem;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 2rem;
        text-align: left;
    }
    .primary-brand,
    .supporting-brand { min-width: 0; }
    .site-brands img { max-width: 40vw; }
    .supporting-brand {
        justify-content: flex-end;
        text-align: right;
    }
    .artwork-shell {
        order: 1;
        min-height: auto;
        padding: 1.5rem;
        grid-template-columns: 1fr;
        gap: 2rem;
    }
    .artwork-media {
        width: min(100%, 34rem);
        margin: 0 auto;
    }
    .artwork-media img { max-height: 68vh; }
}

@media (max-width: 480px) {
    .artwork-shell { padding: 1.25rem; }
    .artwork-content header { padding-left: 1rem; }
    .english-name { letter-spacing: .14em; }
    .metadata div { grid-template-columns: 5.5rem minmax(0, 1fr); }
    .artwork-filters { grid-template-columns: 1fr; }
    .artwork-filters > div:first-child { grid-column: auto; }
    .gallery-page { padding-top: 1.5rem; }
    .gallery-header { flex-direction: column; }
    .public-filters { grid-template-columns: 1fr; }
    .public-filters input { grid-column: auto; }
    .gallery-grid { grid-template-columns: 1fr; }
}

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