:root {
    color-scheme: light;
    --bg: #eeeeee;
    --paper: #ffffff;
    --ink: #151515;
    --muted: #707070;
    --line: #ebebeb;
    --soft: #f6f6f6;
    --accent: #ffcc00;
    --error: #a52b27;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-synthesis: none;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); line-height: 1.5; }
button, input, textarea { font: inherit; }
button, a, input, textarea { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; border: 0; }
button:disabled { cursor: not-allowed; opacity: .45; }
button, input, textarea { transition: background .15s, border-color .15s; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--ink); outline-offset: 4px;
}
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 4px; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { line-height: 1.25; }
input, textarea {
    width: 100%; min-width: 0; min-height: 48px; border: 1px solid var(--line);
    border-radius: 16px; background: var(--paper); color: var(--ink);
    padding: 12px 16px; font-size: 16px;
}
input::placeholder, textarea::placeholder { color: #929292; }
input:disabled, textarea:disabled { background: var(--soft); }
textarea { resize: vertical; min-height: 64px; max-height: 160px; }
.app-shell {
    max-width: 1040px; min-height: 100svh; margin: auto;
    padding: env(safe-area-inset-top, 0px) 32px 0;
}
.masthead { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 28px 0 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 22px; letter-spacing: -.8px; font-weight: 700; }
.brand:hover { text-decoration: none; }
.brand small { display: block; font-size: 8px; letter-spacing: 1.8px; color: var(--muted); font-weight: 500; margin-top: 2px; }
.brand-mark { display: block; flex-shrink: 0; width: 44px; height: 44px; }
.status-pill {
    display: flex; align-items: center; gap: 7px; flex-shrink: 0; border: 1px solid var(--line);
    border-radius: 999px; padding: 8px 12px; font-size: 11px; background: var(--paper);
}
.status-dot { height: 6px; width: 6px; background: #999; border-radius: 50%; }
.online .status-dot { background: var(--ink); box-shadow: 0 0 0 3px #ffcc0033; }
.session-notice { font-size: 11px; color: var(--muted); padding: 8px 0 12px; overflow-wrap: anywhere; }
.error-banner {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    background: #fff2f0; border: 1px solid #f0d1cb; color: var(--error);
    border-radius: 16px; margin-bottom: 12px; padding: 8px 12px; font-size: 13px; overflow-wrap: anywhere;
}
.icon-button { background: transparent; color: inherit; font-size: 24px; min-width: 44px; min-height: 44px; flex-shrink: 0; }
.intro { padding: 12px 0 36px; text-align: center; }
.eyebrow, .card-number { font-size: 10px; letter-spacing: 1.7px; font-weight: 600; color: var(--muted); }
.intro h1 { font-size: clamp(30px, 4.4vw, 44px); font-weight: 600; letter-spacing: -1.7px; margin: 12px 0; }
.intro h1 em { font-style: normal; }
.intro p { font-size: 13px; line-height: 1.8; color: var(--muted); }
.hello-art { position: relative; width: 220px; height: 116px; margin: 0 auto 18px; user-select: none; }
.hello-bubble {
    position: absolute; top: 2px; left: 5px; display: flex; align-items: center; gap: 22px;
    padding: 13px 18px; background: var(--paper); border-radius: 20px 20px 20px 5px;
    font-size: 13px; transform: rotate(-7deg);
}
.hello-bubble i { font-style: normal; font-size: 18px; }
.hello-bubble.reply { top: 48px; left: auto; right: 0; background: var(--accent); border-radius: 20px 20px 5px 20px; transform: rotate(6deg); }
.hello-dots { position: absolute; bottom: 0; left: 32px; padding: 0 10px 4px; letter-spacing: 3px; font-size: 14px; border-radius: 999px; background: var(--paper); }
.lobby-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 20px; }
.lobby-card { min-width: 0; border-radius: 28px; padding: 28px 32px; background: var(--paper); }
.lobby-card h2 { font-size: 23px; font-weight: 600; margin: 12px 0 8px; letter-spacing: -.7px; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.7; }
.group-card form { margin-top: 22px; }
label { display: block; font-size: 12px; font-weight: 600; margin: 16px 0 7px; }
.optional { font-weight: 400; color: var(--muted); font-size: 11px; }
.room-name-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.field-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 12px; }
.field-hint { color: var(--muted); font-size: 10px; line-height: 1.7; margin: 8px 0 14px; }
.button {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 48px;
    border: 1px solid transparent; border-radius: 999px; font-size: 13px; font-weight: 600;
    padding: 12px 20px; white-space: nowrap;
}
.button:not(:disabled):hover { filter: brightness(.95); }
.primary { background: var(--accent); color: var(--ink); }
.dark { background: var(--ink); color: var(--paper); }
.secondary { background: var(--paper); color: var(--ink); border-color: var(--line); }
.full { width: 100%; margin-top: 8px; }
.compact { min-height: 44px; padding: 10px 16px; font-size: 12px; }
.stranger-card { display: flex; flex-direction: column; text-align: center; }
.stranger-card .card-number { text-align: left; }
.stranger-card .muted { max-width: 290px; align-self: center; margin-bottom: 24px; }
.stranger-card .full { margin-top: auto; }
.stranger-card .field-hint { margin: 14px 0 0; }
.match-art { height: 170px; flex-shrink: 0; display: grid; place-items: center; user-select: none; }
.match-bubble { display: grid; place-items: center; width: 104px; height: 68px; border-radius: 24px 24px 24px 8px; background: var(--accent); }
.match-bubble b { font-size: 30px; font-weight: 500; }
.match-dots { display: none; align-items: center; gap: 10px; }
.match-dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--ink); }
.searching .match-bubble b { display: none; }
.searching .match-dots { display: flex; }
.searching .match-dots i { animation: match-pulse 1.4s ease-in-out infinite; }
.searching .match-dots i:nth-child(2) { animation-delay: .18s; }
.searching .match-dots i:nth-child(3) { animation-delay: .36s; }
.matching-label { font-size: 13px; margin-bottom: 12px; }
@keyframes match-pulse { 0%, 70%, 100% { opacity: .35; transform: scale(.8); } 35% { opacity: 1; transform: scale(1); } }
.page-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 10px; padding: 18px 0 max(18px, env(safe-area-inset-bottom, 0px)); }
.app-shell.in-room { height: 100dvh; min-height: 0; display: flex; flex-direction: column; }
.in-room > .masthead, .in-room > .session-notice, .in-room > .error-banner, .in-room > .page-footer { flex-shrink: 0; }
/* Let controls scroll into view when editing and banners exhaust the viewport. */
.chat-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; background: var(--paper); border-radius: 28px; overflow: auto; }
.room-header { display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; gap: 16px; padding: 20px 24px; border-bottom: 1px solid var(--line); }
.room-header > div:first-child { min-width: 0; }
.room-header h1 { font-size: 20px; font-weight: 600; margin: 4px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-header .muted { font-size: 11px; }
.room-actions { display: flex; gap: 8px; flex-shrink: 0; }
.timeline { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 24px; display: flex; flex-direction: column; gap: 18px; scrollbar-width: thin; }
.empty-chat { margin: auto; text-align: center; padding: 24px 0; color: var(--muted); }
.empty-chat > span { display: block; font-size: 40px; color: var(--accent); margin-bottom: 12px; }
.empty-chat h3 { font-size: 16px; font-weight: 500; color: var(--ink); }
.empty-chat p { font-size: 12px; margin-top: 8px; }
.message { max-width: 82%; align-self: flex-start; min-width: 0; flex-shrink: 0; }
.message.own { align-self: flex-end; }
.message-meta { display: flex; gap: 8px; align-items: center; font-size: 10px; color: var(--muted); margin: 0 4px 6px; }
.own .message-meta { justify-content: flex-end; }
.message-bubble { border-radius: 5px 18px 18px; background: var(--soft); padding: 11px 15px; overflow: hidden; }
.own .message-bubble { border-radius: 18px 5px 18px 18px; background: var(--accent); }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.7; }
.message-image { display: block; max-width: min(100%, 420px); max-height: 380px; min-width: 1px; height: auto; object-fit: contain; border-radius: 8px; }
.message-tools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 3px; }
.own .message-tools { justify-content: flex-end; }
.reactions { display: flex; gap: 2px; }
.reaction { display: flex; align-items: center; justify-content: center; gap: 3px; padding: 6px; min-width: 44px; min-height: 44px; background: transparent; border: 1px solid transparent; border-radius: 999px; font-size: 13px; }
.reaction span { font-size: 10px; color: var(--muted); }
.reaction.selected { border-color: #dfba22; background: #fff7d6; opacity: 1; }
.reaction:not(:disabled):hover { background: var(--soft); }
.text-button { background: none; color: var(--muted); font-size: 11px; min-width: 44px; min-height: 44px; padding: 6px; }
.text-button:hover { color: var(--ink); text-decoration: underline; }
.text-button.danger { color: var(--error); }
.composer { flex-shrink: 0; padding: 14px 24px 6px; border-top: 1px solid var(--line); }
.composer textarea { background: var(--soft); font-size: 16px; }
.composer-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 8px; }
.composer-tools { display: flex; align-items: center; gap: 12px; min-width: 0; }
.composer-hint { font-size: 10px; color: var(--muted); }
.editing-notice { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 11px; padding-bottom: 8px; }
.offline-warning { font-size: 12px; color: var(--error); margin-bottom: 8px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
@media (max-width: 720px) {
    body { background: var(--paper); }
    .app-shell { padding-right: max(20px, env(safe-area-inset-right, 0px)); padding-left: max(20px, env(safe-area-inset-left, 0px)); }
    .masthead { padding: 20px 0 10px; }
    .brand { font-size: 20px; }
    .brand-mark { width: 40px; height: 40px; }
    .status-pill { font-size: 10px; padding: 7px 10px; }
    .intro { padding: 20px 0 30px; }
    .hello-bubble:not(.reply), .hello-dots { background: var(--soft); }
    .intro h1 { font-size: 32px; letter-spacing: -1.2px; }
    .lobby-grid { grid-template-columns: minmax(0, 1fr); gap: 16px; }
    .lobby-card { border: 1px solid var(--line); padding: 24px; border-radius: 24px; }
    .stranger-card { background: var(--soft); border-color: transparent; }
    .stranger-card .muted { max-width: none; }
    .match-art { height: 130px; }
    .page-footer { font-size: 10px; }
    .in-room .masthead { padding: 10px 0 6px; }
    .in-room .brand small { display: none; }
    .in-room .session-notice { font-size: 10px; padding: 4px 0 8px; }
    .in-room .page-footer { display: none; }
    .in-room { padding-bottom: max(8px, env(safe-area-inset-bottom, 0px)); }
    .chat-panel { border-radius: 0; }
    .room-header { padding: 12px 0; gap: 8px; }
    .room-header h1 { font-size: 18px; }
    .room-header .eyebrow { font-size: 8px; letter-spacing: 1px; }
    .room-actions { gap: 4px; }
    .room-actions .button { padding: 8px 12px; }
    .timeline { padding: 18px 0; }
    .message { max-width: 92%; }
    .composer { padding: 10px 0 0; }
    .composer-hint { display: none; }
    .composer .field-hint { font-size: 9px; margin: 6px 0 0; }
}
@media (max-height: 600px) {
    .in-room .masthead { padding: 6px 0; }
    .in-room .brand-mark { width: 32px; height: 32px; }
    .in-room .brand small, .in-room .room-header .eyebrow, .in-room .page-footer { display: none; }
    .in-room .session-notice { padding: 2px 0 6px; font-size: 10px; }
    .in-room .room-header { padding-top: 8px; padding-bottom: 8px; }
    .in-room .room-header h1 { font-size: 16px; margin: 0; }
    .in-room .composer { padding-top: 8px; padding-bottom: 0; }
    .in-room .composer textarea { min-height: 48px; height: 48px; }
    .in-room .composer .field-hint { margin: 4px 0 0; font-size: 9px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
