* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
:root { --bg: #14121c; --panel: #1e1b2a; --line: #322d45; --text: #ece9f5; --dim: #9d96b5; --accent: #a78bfa; }
html, body { height: 100%; background: var(--bg); color: var(--text); font: 17.5px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:disabled { opacity: .4; }
.err { color: #ff8b8b; font-size: 15.5px; }

#login { height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
#loginForm { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 16px; text-align: center; }
.hello { font-size: 28px; font-weight: 700; margin-bottom: 8px; }
label { color: var(--dim); }
#code { background: var(--panel); border: 2px solid var(--line); border-radius: 16px; color: var(--accent); font-size: 30px; letter-spacing: .5em; text-align: center; padding: 14px 0 14px .5em; outline: none; }
#code:focus { border-color: var(--accent); }
#loginError { min-height: 1.5em; }
#loginForm button { background: var(--accent); color: #14121c; font-weight: 700; border-radius: 14px; padding: 15px; }

#main { height: 100dvh; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; }
header { display: flex; align-items: center; gap: 6px; padding: calc(6px + env(safe-area-inset-top)) 8px 6px; border-bottom: 1px solid var(--line); }
header button { font-size: 23px; width: 46px; height: 44px; }
#title { flex: 1; text-align: center; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#log { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 14px; overscroll-behavior: contain; }
.empty { margin: auto; text-align: center; color: var(--dim); max-width: 280px; }
.msg { max-width: 100%; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; max-width: 85%; background: #3a3158; border-radius: 18px 18px 4px 18px; padding: 10px 14px; white-space: pre-wrap; }
.msg.user img { display: block; max-width: 100%; max-height: 260px; border-radius: 10px; margin-bottom: 6px; }
.msg.assistant { align-self: stretch; }
.md > * + * { margin-top: .7em; }
.md ul, .md ol { padding-left: 1.35em; }
.md li + li { margin-top: .25em; }
.md h1, .md h2, .md h3, .md h4 { font-size: 1.08em; line-height: 1.35; }
.md pre { background: #0d0c13; border-radius: 10px; padding: 10px 12px; overflow-x: auto; font-size: 14.5px; }
.md code { font-family: ui-monospace, Menlo, monospace; font-size: .9em; background: #0d0c13; border-radius: 5px; padding: 1px 4px; }
.md pre code { padding: 0; background: none; }
.md table { display: block; overflow-x: auto; border-collapse: collapse; font-size: 15.5px; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; }
.md a { color: var(--accent); }
.md blockquote { border-left: 3px solid var(--line); padding-left: 10px; color: var(--dim); }

details { margin-bottom: 8px; color: var(--dim); font-size: 15px; }
summary { cursor: pointer; padding: 2px 0; }
details div { white-space: pre-wrap; border-left: 2px solid var(--line); padding-left: 10px; margin-top: 6px; max-height: 240px; overflow-y: auto; }
.state { color: var(--dim); display: flex; align-items: center; gap: 9px; }
.state::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: pulse 1.1s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: .25; } to { opacity: 1; } }
.actions { display: flex; gap: 16px; margin-top: 6px; font-size: 14.5px; color: var(--dim); }
.retry { border: 1px solid var(--accent); color: var(--accent); border-radius: 10px; padding: 7px 14px; margin-top: 8px; }

#notice { padding: 4px 14px; }
footer { border-top: 1px solid var(--line); padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
.row { display: flex; align-items: flex-end; gap: 6px; }
#photo, #send { width: 46px; height: 46px; border-radius: 50%; flex: none; font-size: 24px; }
#photo { background: var(--panel); }
#send { background: var(--accent); color: #14121c; font-weight: 800; }
#input { flex: 1; min-width: 0; resize: none; font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 9px 15px; max-height: 150px; outline: none; }
#preview { position: relative; display: inline-block; margin: 0 0 8px 4px; }
#preview img { height: 84px; border-radius: 10px; display: block; }
#dropPhoto { position: absolute; top: -8px; right: -8px; background: #000c; border-radius: 50%; width: 28px; height: 28px; font-size: 14px; }

#backdrop { position: fixed; inset: 0; background: #000a; z-index: 5; }
#drawer { position: fixed; top: 0; bottom: 0; left: 0; width: min(84vw, 330px); background: var(--panel); z-index: 6; transform: translateX(-105%); transition: transform .2s; display: flex; flex-direction: column; padding: calc(12px + env(safe-area-inset-top)) 10px calc(12px + env(safe-area-inset-bottom)); gap: 10px; }
#drawer.open { transform: none; }
#newChat { background: var(--accent); color: #14121c; font-weight: 700; border-radius: 12px; padding: 12px; }
#list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.item { display: flex; align-items: center; border-radius: 10px; flex: none; }
.item.current { background: #302a47; }
.item .open { flex: 1; min-width: 0; text-align: left; padding: 11px 10px; font-size: 16.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .del { padding: 11px 12px; color: var(--dim); }
#logout { color: var(--dim); font-size: 15.5px; padding: 8px; }
