:root {
    color-scheme: light;
    --bg: #f4f1ea;
    --surface: #fffefa;
    --surface-soft: #e9e4da;
    --surface-raised: #fffefa;
    --ink: #171915;
    --muted: #686b63;
    --faint: #92948b;
    --line: #d4d0c7;
    --accent: #f06445;
    --accent-soft: #fff2ed;
    --accent-ink: #171915;
    --visitor: #1b1e1a;
    --visitor-ink: #fffefa;
    --assistant: #fffefa;
    --danger: #9b3225;
    --overlay: rgb(18 24 20 / 42%);
    --shadow: 0 18px 60px rgb(40 39 30 / 12%);
    --bubble-shadow: 0 1px 2px rgb(40 39 30 / 4%);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #1b1e1a;
    --surface: #272d25;
    --surface-soft: #343b30;
    --surface-raised: #272d25;
    --ink: #fffefa;
    --muted: #c0c5bb;
    --faint: #929b8d;
    --line: #50594a;
    --accent: #f06445;
    --accent-soft: #3b2b25;
    --accent-ink: #171915;
    --visitor: #f4f1ea;
    --visitor-ink: #171915;
    --assistant: #30372d;
    --danger: #f0a092;
    --overlay: rgb(0 0 0 / 62%);
    --shadow: 0 18px 60px rgb(0 0 0 / 32%);
    --bubble-shadow: 0 4px 16px rgb(0 0 0 / 18%);
}

*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; background: var(--bg); }
body {
    margin: 0;
    min-width: 320px;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    background: var(--bg);
    color: var(--ink);
    font-family: "Helvetica Neue", "Segoe UI", Arial, sans-serif;
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}
button, textarea { font: inherit; }
button { color: inherit; cursor: pointer; }
button, a { touch-action: manipulation; }
button:disabled, textarea:disabled { cursor: not-allowed; opacity: .48; }
button:focus-visible, a:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}
button { border: 0; }
img { display: block; max-width: 100%; }
svg { display: block; }
[hidden] { display: none !important; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.app-shell { width: 100%; height: 100%; background: var(--bg); }
.view { width: 100%; height: 100%; }
.icon-button {
    width: 44px;
    height: 44px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    padding: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    transition: color .2s ease, background-color .2s ease, transform .2s ease;
}
.icon-button:active { transform: scale(.92); }
.icon-button svg {
    width: 21px;
    height: 21px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.eyebrow {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    color: var(--muted);
    font-size: 11px;
    font-weight: 650;
    letter-spacing: .14em;
    line-height: 1.4;
    text-transform: uppercase;
}
.eyebrow::before { content: ""; width: 22px; height: 1px; flex: 0 0 auto; background: var(--accent); }
.primary-button {
    min-height: 50px;
    padding: 13px 22px;
    border-radius: 15px;
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 600;
    transition: transform .2s ease, opacity .2s ease;
}
.primary-button:active { transform: scale(.98); }
.text-button { min-height: 44px; padding: 8px 16px; background: transparent; color: var(--muted); }

.library-view { display: flex; flex-direction: column; overflow: hidden; }
.library-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: calc(70px + var(--safe-top));
    padding: calc(10px + var(--safe-top)) 14px 10px 22px;
}
.brand { display: inline-flex; align-items: center; color: var(--ink); text-decoration: none; }
.brand-logo { display: block; width: 196px; height: auto; }
.brand-logo-dark { display: none; }
:root[data-theme="dark"] .brand-logo-light { display: none; }
:root[data-theme="dark"] .brand-logo-dark { display: block; }
.library-content { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 24px 18px 32px; }
.library-heading { margin: 0 2px 30px; animation: rise-in .5s cubic-bezier(.22, 1, .36, 1) both; }
.library-heading h1 {
    max-width: 360px;
    margin: 0 0 12px;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(34px, 9vw, 44px);
    font-weight: 400;
    letter-spacing: -.04em;
    line-height: 1.08;
}
.library-empty {
    max-width: 330px;
    margin: clamp(36px, 10vh, 90px) auto 20px;
    color: var(--muted);
    text-align: center;
    animation: rise-in .55s .08s cubic-bezier(.22, 1, .36, 1) both;
}
.qr-illustration {
    width: 76px;
    height: 76px;
    display: grid;
    place-items: center;
    margin: 0 auto 22px;
    border: 1px solid var(--line);
    border-radius: 24px;
    background: var(--surface);
    color: var(--accent);
    transform: rotate(-3deg);
}
.qr-illustration svg { width: 48px; height: 48px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.library-empty h2 { margin: 0 0 9px; color: var(--ink); font-family: Georgia, "Times New Roman", serif; font-size: 24px; font-weight: 400; }
.library-empty p { margin: 0; font-size: 14px; line-height: 1.55; }
.conversation-list { display: grid; gap: 10px; }
.conversation-card {
    width: 100%;
    display: grid;
    grid-template-columns: 70px minmax(0, 1fr) 20px;
    align-items: center;
    gap: 14px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--surface);
    color: var(--ink);
    text-align: left;
    box-shadow: var(--bubble-shadow);
    animation: rise-in .45s cubic-bezier(.22, 1, .36, 1) both;
    transition: transform .2s ease, border-color .2s ease, background-color .2s ease;
}
.conversation-card:active { transform: scale(.985); }
.conversation-card-image {
    width: 70px;
    height: 82px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 12px;
    background: var(--surface-soft);
    color: var(--muted);
    font-family: Georgia, "Times New Roman", serif;
    font-size: 26px;
}
.conversation-card-image img { width: 100%; height: 100%; object-fit: cover; }
.conversation-card-copy { min-width: 0; }
.conversation-card-title { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; font-size: 15px; font-weight: 600; line-height: 1.35; }
.conversation-card-artist { display: block; margin-top: 5px; overflow: hidden; color: var(--muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.conversation-card-exhibition { display: block; margin-top: 9px; overflow: hidden; color: var(--faint); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.conversation-card > svg { width: 18px; height: 18px; fill: none; stroke: var(--faint); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.conversation-card-status { display: inline-block; margin-left: 5px; color: var(--danger); }
.library-footer { padding: 10px 24px calc(14px + var(--safe-bottom)); color: var(--faint); font-size: 10px; line-height: 1.4; text-align: center; }

.conversation-view { display: flex; flex-direction: column; }
.chat-header {
    position: relative;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 5px;
    min-height: calc(68px + var(--safe-top));
    padding: calc(8px + var(--safe-top)) 8px 8px;
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg) 90%, transparent);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
}
.artwork-summary {
    min-width: 0;
    flex: 1;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 0 3px;
    background: transparent;
    text-align: left;
}
.artwork-thumbnail {
    width: 42px;
    height: 46px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 10px;
    background: var(--surface-soft);
    color: var(--muted);
    font-family: Georgia, "Times New Roman", serif;
    font-size: 19px;
}
.artwork-thumbnail img { width: 100%; height: 100%; object-fit: cover; }
.artwork-heading { min-width: 0; display: flex; flex: 1; flex-direction: column; gap: 4px; }
.artwork-title, .artwork-subtitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.artwork-title { font-size: 14px; font-weight: 600; letter-spacing: -.01em; }
.artwork-subtitle { color: var(--muted); font-size: 11px; }
.theme-icon-sun { display: none; }
:root[data-theme="dark"] .theme-icon-sun { display: block; }
:root[data-theme="dark"] .theme-icon-moon { display: none; }
.offline-banner { padding: 7px 16px; background: var(--surface-soft); color: var(--muted); font-size: 11px; line-height: 1.4; text-align: center; }
.messages-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 22px 14px 18px;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: var(--line) transparent;
}
.conversation-loading { max-width: 300px; margin: 15vh auto 0; text-align: center; }
.loading-artwork { width: 56px; height: 66px; margin: 0 auto 22px; border-radius: 13px; background: var(--surface-soft); }
.loading-line { height: 9px; margin: 10px auto; border-radius: 10px; background: var(--surface-soft); }
.loading-line-short { width: 55%; }
.loading-artwork, .loading-line { animation: skeleton 1.4s ease-in-out infinite alternate; }
.state-card { max-width: 340px; margin: 12vh auto 0; text-align: center; animation: rise-in .4s ease both; }
.state-mark { width: 52px; height: 52px; display: grid; place-items: center; margin: 0 auto 20px; border: 1px solid var(--line); border-radius: 17px; color: var(--accent); font-family: Georgia, serif; font-size: 28px; }
.state-card h2 { margin: 0 0 10px; font-family: Georgia, "Times New Roman", serif; font-size: 26px; font-weight: 400; line-height: 1.2; }
.state-card p { margin: 0 0 22px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.state-card .primary-button, .state-card .text-button { width: 100%; }
.empty-conversation { max-width: 380px; margin: clamp(32px, 9vh, 90px) auto 34px; color: var(--muted); text-align: center; animation: rise-in .55s cubic-bezier(.22, 1, .36, 1) both; }
.empty-line { width: 30px; height: 1px; display: block; margin: 0 auto 20px; background: var(--accent); }
.empty-conversation > p { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 22px; line-height: 1.4; }
.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; margin-top: 24px; }
.suggestions button {
    min-height: 38px;
    padding: 8px 13px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    transition: color .2s ease, border-color .2s ease, background-color .2s ease;
}
.messages { display: flex; flex-direction: column; }
.message { display: flex; flex-direction: column; align-items: flex-start; margin: 0 0 13px; animation: message-in .38s cubic-bezier(.22, 1, .36, 1) both; }
.message.visitor { align-items: flex-end; }
.bubble {
    max-width: min(88%, 590px);
    padding: 11px 14px 7px;
    border: 1px solid var(--line);
    border-radius: 6px 19px 19px 19px;
    background: var(--assistant);
    box-shadow: var(--bubble-shadow);
    line-height: 1.48;
}
.visitor .bubble { border: 0; border-radius: 19px 6px 19px 19px; background: var(--visitor); color: var(--visitor-ink); }
.message-body { overflow-wrap: anywhere; font-size: 15px; white-space: pre-wrap; }
.message-body.markdown { white-space: normal; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p { margin: 0 0 10px; }
.markdown h1, .markdown h2, .markdown h3 { margin: 16px 0 7px; font-size: 17px; line-height: 1.35; }
.markdown h1 { font-size: 19px; }
.markdown ul, .markdown ol { margin: 7px 0 10px; padding-left: 21px; }
.markdown li + li { margin-top: 5px; }
.markdown blockquote { margin: 11px 0; padding-left: 11px; border-left: 2px solid var(--line); color: var(--muted); }
.markdown code { padding: 1px 4px; border-radius: 4px; background: var(--surface-soft); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9em; }
.markdown pre { margin: 10px 0; padding: 11px; overflow-x: auto; border-radius: 9px; background: var(--surface-soft); white-space: pre; }
.markdown pre code { padding: 0; background: transparent; }
.markdown a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.markdown hr { margin: 14px 0; border: 0; border-top: 1px solid var(--line); }
.message-time { align-self: flex-end; margin: 4px 0 0 9px; font-size: 9px; line-height: 1.2; opacity: .56; }
.message-error { max-width: 85%; margin: -3px 0 14px; color: var(--danger); font-size: 11px; }
.typing { width: fit-content; display: flex; gap: 5px; margin: 3px 0 12px; padding: 14px 17px; border: 1px solid var(--line); border-radius: 6px 19px 19px 19px; background: var(--assistant); }
.typing span { width: 5px; height: 5px; border-radius: 50%; background: var(--muted); animation: typing-pulse 1s infinite alternate; }
.typing span:nth-child(2) { animation-delay: .18s; }
.typing span:nth-child(3) { animation-delay: .36s; }
.composer-wrap {
    position: relative;
    z-index: 4;
    padding: 9px 10px calc(10px + var(--safe-bottom));
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg) 94%, transparent);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
}
.composer { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea {
    width: 100%;
    min-height: 46px;
    max-height: 126px;
    flex: 1;
    resize: none;
    border: 1px solid var(--line);
    border-radius: 23px;
    padding: 12px 16px;
    outline: 0;
    background: var(--surface);
    color: var(--ink);
    font-size: 16px;
    line-height: 1.35;
    transition: border-color .2s ease;
    -webkit-appearance: none;
}
.composer textarea::placeholder { color: var(--faint); }
.composer textarea:focus { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
.send-button {
    width: 46px;
    height: 46px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    padding: 0;
    border-radius: 50%;
    background: var(--accent);
    color: #ffffff;
    transition: transform .2s ease, opacity .2s ease;
}
.send-button:not(:disabled):active { transform: scale(.91); }
.send-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.archived-notice { padding: 4px 10px 3px; color: var(--muted); font-size: 12px; line-height: 1.5; text-align: center; }

dialog {
    color: var(--ink);
    font: inherit;
}
dialog::backdrop { background: var(--overlay); -webkit-backdrop-filter: blur(5px); backdrop-filter: blur(5px); }
.sheet-dialog {
    width: min(100%, 520px);
    max-width: none;
    max-height: min(88dvh, 780px);
    margin: auto auto 0;
    padding: 0;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 26px 26px 0 0;
    background: var(--surface-raised);
    box-shadow: var(--shadow);
}
.sheet-dialog[open] { animation: sheet-in .36s cubic-bezier(.22, 1, .36, 1) both; }
.sheet-handle { width: 36px; height: 4px; margin: 9px auto 0; border-radius: 4px; background: var(--line); }
.sheet-close { position: absolute; z-index: 2; top: 14px; right: 14px; background: color-mix(in srgb, var(--surface-raised) 86%, transparent); }
.details-image-wrap {
    height: min(42dvh, 390px);
    display: grid;
    place-items: center;
    margin-top: -38px;
    overflow: hidden;
    background: var(--surface-soft);
    color: var(--muted);
    font-family: Georgia, serif;
    font-size: 64px;
}
.details-image-wrap img { width: 100%; height: 100%; object-fit: contain; }
.details-content { padding: 25px 22px calc(28px + var(--safe-bottom)); }
.details-content h2 {
    margin: 8px 0 7px;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 29px;
    font-weight: 400;
    letter-spacing: -.025em;
    line-height: 1.15;
}
.details-artist { margin: 0; color: var(--muted); line-height: 1.5; }
.artwork-facts { display: grid; gap: 0; margin: 24px 0 0; }
.artwork-facts > div { display: grid; grid-template-columns: 90px 1fr; gap: 14px; padding: 12px 0; border-top: 1px solid var(--line); font-size: 13px; line-height: 1.45; }
.artwork-facts dt { color: var(--muted); }
.artwork-facts dd { margin: 0; }
.details-archived { margin: 20px 0 0; padding: 13px; border-radius: 12px; background: var(--surface-soft); color: var(--muted); font-size: 12px; line-height: 1.5; }
.toast {
    position: fixed;
    z-index: 50;
    left: 50%;
    bottom: calc(84px + var(--safe-bottom));
    width: max-content;
    max-width: calc(100% - 32px);
    transform: translateX(-50%);
    padding: 11px 15px;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: var(--surface-raised);
    color: var(--ink);
    box-shadow: var(--shadow);
    font-size: 12px;
    line-height: 1.45;
    text-align: center;
    animation: toast-in .25s ease both;
}
.noscript { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 30px; background: var(--bg); text-align: center; }

@media (hover: hover) {
    .icon-button:hover { background: var(--surface-soft); color: var(--ink); }
    .conversation-card:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); transform: translateY(-2px); }
    .suggestions button:hover { border-color: var(--accent); color: var(--accent); }
}
@media (min-width: 700px) {
    body { padding: 0 20px; }
    .app-shell { max-width: 760px; margin: 0 auto; border-right: 1px solid var(--line); border-left: 1px solid var(--line); }
    .library-header { padding-right: 22px; padding-left: 30px; }
    .library-content { padding: 42px 34px; }
    .library-heading h1 { max-width: 450px; }
    .library-heading > p:last-child { max-width: 400px; }
    .conversation-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .messages-scroll { padding: 26px 26px 20px; }
    .composer-wrap { padding-right: 22px; padding-left: 22px; }
    .bubble { max-width: min(82%, 590px); }
    .sheet-dialog { margin-bottom: 20px; border-bottom: 1px solid var(--line); border-radius: 26px; }
    .details-image-wrap { border-radius: 26px 26px 0 0; }
}
@media (max-width: 370px) {
    .chat-header { gap: 1px; }
    .back-button, #themeToggle { width: 39px; }
    .artwork-summary { gap: 8px; }
    .artwork-thumbnail { width: 37px; height: 42px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
@keyframes rise-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes message-in { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes sheet-in { from { opacity: 0; transform: translateY(35px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes typing-pulse { from { opacity: .35; transform: translateY(1px); } to { opacity: 1; transform: translateY(-1px); } }
@keyframes skeleton { from { opacity: .45; } to { opacity: 1; } }
