:root {
  color-scheme: light;
  font-family: Inter, ui-rounded, "Segoe UI", system-ui, sans-serif;
  color: #332d4f;
  background: #fff6df;
  font-synthesis: none;
  --ink: #332d4f;
  --cream: #fffaf0;
  --coral: #ff6b6b;
  --sun: #ffc857;
  --blue: #5b8def;
  --mint: #48c9a5;
  --lilac: #9b7bd6;
}

html[data-theme="ocean"] { --ink: #203654; --cream: #f6fbff; --coral: #4386e8; --sun: #73d6e6; --blue: #315fae; --mint: #56c9b5; --lilac: #829fe8; }
html[data-theme="berry"] { --ink: #462b55; --cream: #fff8fc; --coral: #d95b9e; --sun: #e9a6d0; --blue: #8a65ce; --mint: #d787b8; --lilac: #a879dc; }
html[data-theme="woodland"] { --ink: #273e35; --cream: #fbfaf1; --coral: #e6814f; --sun: #e9bd5d; --blue: #528f86; --mint: #70b978; --lilac: #8e9f72; }

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  min-width: 300px;
  background:
    radial-gradient(circle at 8% 13%, color-mix(in srgb, var(--coral) 22%, transparent) 0 5rem, transparent 5.1rem),
    radial-gradient(circle at 91% 8%, color-mix(in srgb, var(--sun) 30%, transparent) 0 7rem, transparent 7.1rem),
    radial-gradient(circle at 88% 89%, color-mix(in srgb, var(--blue) 20%, transparent) 0 9rem, transparent 9.1rem),
    radial-gradient(#e2cfa9 1px, transparent 1.5px),
    #fff6df;
  background-size: auto, auto, auto, 24px 24px, auto;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
.app-shell { min-height: 100%; display: grid; place-items: center; padding: 26px; }
.wake-screen { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px; background: color-mix(in srgb, var(--cream) 90%, transparent); backdrop-filter: blur(8px); }
.wake-screen[hidden] { display: none; }
.wake-card { width: min(100%, 430px); padding: 34px 28px 29px; border: 2.5px solid var(--ink); border-radius: 30px 24px 34px 26px; background: #fff; box-shadow: 9px 10px 0 var(--ink); text-align: center; }
.wake-heart { width: 76px; height: 68px; display: grid; place-items: center; margin: 0 auto 19px; border: 2px solid var(--ink); border-radius: 22px 27px 21px 25px; color: #fff; background: var(--coral); box-shadow: 5px 5px 0 var(--sun); font-size: 2rem; animation: wake-bob 1.15s ease-in-out infinite alternate; }
.wake-card h2 { margin: 0; color: var(--ink); font-size: 1.55rem; letter-spacing: -.035em; }
.wake-card p { min-height: 2.8em; margin: 10px auto 15px; color: #675f7a; line-height: 1.45; }
.wake-dots { display: flex; justify-content: center; gap: 7px; margin-bottom: 21px; }
.wake-dots span { width: 10px; height: 10px; border: 1.5px solid var(--ink); border-radius: 50%; background: var(--sun); animation: wake-dot .9s ease-in-out infinite alternate; }
.wake-dots span:nth-child(2) { background: var(--coral); animation-delay: .16s; }
.wake-dots span:nth-child(3) { background: var(--blue); animation-delay: .32s; }
.wake-card button { border: 0; padding: 7px 10px; color: #695f7d; background: transparent; font-weight: 800; }
.wake-card button:hover { color: var(--coral); }
@keyframes wake-bob { to { transform: translateY(-8px) rotate(3deg); } }
@keyframes wake-dot { to { transform: translateY(-6px); } }
.join-view { width: min(100%, 460px); text-align: center; }

.brand-mark { width: 112px; margin: 0 auto 8px; filter: drop-shadow(5px 6px 0 rgba(51, 45, 79, .13)); }
.brand-mark svg { display: block; width: 100%; overflow: visible; }
.logo-roof { fill: none; stroke: var(--ink); stroke-width: 8; stroke-linecap: round; stroke-linejoin: round; }
.logo-home { fill: var(--sun); stroke: var(--ink); stroke-width: 5; stroke-linejoin: round; }
.logo-heart { fill: var(--coral); stroke: var(--ink); stroke-width: 4; stroke-linejoin: round; }
.logo-dot.one { fill: var(--mint); }
.logo-dot.two { fill: var(--blue); }
.logo-spark { fill: var(--lilac); stroke: var(--ink); stroke-width: 3; stroke-linejoin: round; }

.eyebrow { margin: 0 0 4px; color: #6a608b; font-size: .72rem; font-weight: 900; letter-spacing: .15em; text-transform: uppercase; }
h1 { margin: 0; color: var(--ink); font-size: clamp(3rem, 10vw, 4.7rem); letter-spacing: -.075em; line-height: .95; }
h1 span { color: var(--coral); }
.intro { margin: 14px auto; max-width: 410px; color: #675f7a; font-size: 1rem; line-height: 1.55; }
.joy-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; margin: 0 0 22px; }
.joy-chips span { padding: 6px 10px; border: 1.5px solid var(--ink); border-radius: 999px; background: #fff; box-shadow: 2px 2px 0 var(--ink); font-size: .72rem; font-weight: 800; transform: rotate(-1deg); }
.joy-chips span:nth-child(2) { background: #fff0b9; transform: rotate(1.5deg); }
.joy-chips span:nth-child(3) { background: #ffe0df; transform: rotate(-.5deg); }
.theme-button { border: 1.7px solid var(--ink); color: var(--ink); background: #fff; box-shadow: 2px 2px 0 var(--ink); font-weight: 850; }
.theme-button:hover { background: color-mix(in srgb, var(--sun) 35%, white); transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--ink); }
.welcome-theme-button { margin: -7px 0 20px; padding: 7px 11px; border-radius: 999px; font-size: .72rem; }

.card { display: grid; position: relative; text-align: left; padding: 27px; border: 2.5px solid var(--ink); border-radius: 25px 25px 34px 22px; background: rgba(255, 255, 255, .94); box-shadow: 8px 9px 0 var(--ink); }
.card::before { content: ""; position: absolute; top: -9px; left: 38px; width: 68px; height: 18px; background: rgba(91, 141, 239, .42); transform: rotate(-3deg); }
label { margin: 0 0 7px; color: #463e65; font-size: .82rem; font-weight: 900; }
input, textarea { width: 100%; color: var(--ink); border: 2px solid #c9bfd9; border-radius: 14px; background: #fffcf7; outline: none; transition: border-color .15s, box-shadow .15s, transform .15s; }
input { height: 50px; padding: 0 14px; margin-bottom: 18px; }
input:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(91, 141, 239, .16); }
#family-code { margin-bottom: 0; text-transform: uppercase; letter-spacing: .08em; }
.field-note { margin: 7px 2px 21px; color: #827a92; font-size: .75rem; }
.card > button { min-height: 52px; display: flex; align-items: center; justify-content: center; gap: 10px; border: 2px solid var(--ink); border-radius: 15px; color: var(--ink); background: var(--sun); box-shadow: 4px 4px 0 var(--ink); font-weight: 900; transition: transform .12s, box-shadow .12s; }
.card > button:hover { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }
.card > button:disabled { opacity: .55; cursor: wait; }
.card > button span { font-size: 1.2rem; }
.error { min-height: 1.2em; margin: 14px 0 -5px; color: #bc3749; text-align: center; font-size: .82rem; }

.chat-view { width: min(100%, 980px); height: min(880px, calc(100vh - 46px)); min-height: 500px; display: grid; grid-template-rows: auto 1fr auto auto auto; overflow: hidden; border: 3px solid var(--ink); border-radius: 28px; background: var(--cream); box-shadow: 10px 11px 0 rgba(51, 45, 79, .92); }
.chat-view[hidden], .join-view[hidden] { display: none; }
.chat-header { min-height: 88px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 14px 21px; border-bottom: 2px solid var(--ink); background: linear-gradient(105deg, color-mix(in srgb, var(--sun) 34%, white) 0 44%, color-mix(in srgb, var(--coral) 20%, white) 100%); }
.room-brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.room-home { width: 47px; height: 43px; display: grid; place-items: center; flex: none; position: relative; z-index: 0; border: 2px solid var(--ink); border-radius: 8px 8px 14px 14px; color: #fff; background: var(--coral); box-shadow: 3px 3px 0 var(--ink); font-size: 1.15rem; }
.room-home::before { content: ""; position: absolute; top: -9px; width: 31px; height: 20px; z-index: -1; border: 2px solid var(--ink); background: var(--blue); transform: rotate(45deg); }
.chat-header h2 { overflow: hidden; margin: 0; font-size: 1.35rem; letter-spacing: -.025em; text-overflow: ellipsis; white-space: nowrap; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.header-theme-button { width: 35px; height: 35px; padding: 0; border-radius: 11px; font-size: 1rem; }
.status { color: #625978; font-size: .76rem; white-space: nowrap; }
.status::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 6px; border: 1.5px solid var(--ink); border-radius: 50%; background: var(--sun); }
.status.online::before { background: var(--mint); }
.text-button { border: 0; padding: 7px; color: #695f7d; background: none; font-size: .78rem; font-weight: 800; }
.text-button:hover { color: var(--coral); }
.users-button { display: none; border: 2px solid var(--ink); padding: 7px 10px; border-radius: 10px; color: var(--ink); background: #fff; box-shadow: 2px 2px 0 var(--ink); font-size: .72rem; font-weight: 900; }

.chat-content { min-width: 0; min-height: 0; display: grid; grid-template-columns: 220px minmax(0, 1fr); position: relative; overflow: hidden; }
.user-sidebar { min-height: 0; overflow-y: auto; padding: 21px 14px; border-right: 2px solid var(--ink); background: color-mix(in srgb, var(--lilac) 17%, white); }
.sidebar-heading { display: flex; align-items: center; justify-content: space-between; margin: 0 5px 15px; }
.sidebar-heading h3 { margin: 0; color: #514474; font-size: .76rem; letter-spacing: .07em; text-transform: uppercase; }
.user-count { display: inline-grid; place-items: center; min-width: 23px; height: 23px; margin-left: 5px; padding: 0 6px; border: 1.5px solid var(--ink); border-radius: 50%; color: var(--ink); background: var(--sun); font-size: .68rem; }
.close-users-button { display: none; width: 30px; height: 30px; border: 1.5px solid var(--ink); border-radius: 50%; color: var(--ink); background: #fff; font-size: 1.2rem; line-height: 1; }
.user-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.user-item { min-width: 0; display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; align-items: center; gap: 9px; padding: 8px; border: 1.5px solid transparent; border-radius: 14px; }
.user-item:hover { border-color: var(--ink); background: rgba(255, 255, 255, .65); transform: rotate(-.4deg); }
.user-avatar { width: 36px; height: 36px; display: grid; place-items: center; border: 2px solid var(--ink); border-radius: 12px 12px 15px 10px; color: var(--ink); background: var(--sun); box-shadow: 2px 2px 0 var(--ink); font-size: .82rem; font-weight: 900; text-transform: uppercase; }
.user-item:nth-child(4n+2) .user-avatar { background: color-mix(in srgb, var(--coral) 58%, white); transform: rotate(2deg); }
.user-item:nth-child(4n+3) .user-avatar { background: color-mix(in srgb, var(--blue) 52%, white); transform: rotate(-2deg); }
.user-item:nth-child(4n+4) .user-avatar { background: color-mix(in srgb, var(--mint) 58%, white); transform: rotate(1deg); }
.user-name { min-width: 0; overflow: hidden; color: #443a62; font-size: .83rem; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.self-label { padding: 2px 5px; border-radius: 5px; color: var(--ink); background: color-mix(in srgb, var(--lilac) 27%, white); font-size: .6rem; font-weight: 900; text-transform: uppercase; }

.messages { min-width: 0; min-height: 0; overflow-y: auto; padding: 25px; background-color: #fffaf0; background-image: radial-gradient(circle, rgba(91, 141, 239, .19) 1.5px, transparent 1.7px), radial-gradient(circle, rgba(255, 107, 107, .16) 1px, transparent 1.2px); background-position: 0 0, 12px 12px; background-size: 28px 28px; }
.empty-state { height: 100%; display: grid; place-content: center; justify-items: center; color: #766d87; text-align: center; }
.empty-state span { display: grid; place-items: center; width: 70px; height: 62px; border: 2px solid var(--ink); border-radius: 19px 24px 18px 23px; background: #fff; box-shadow: 5px 5px 0 var(--sun); font-size: 2rem; transform: rotate(-3deg); }
.empty-state h3 { margin: 15px 0 4px; color: var(--ink); font-size: 1.05rem; }
.empty-state p { margin: 0; max-width: 330px; font-size: .8rem; line-height: 1.5; }
.message { display: flex; flex-direction: column; align-items: flex-start; margin: 0 0 14px; }
.message.mine { align-items: flex-end; }
.message-meta { display: flex; align-items: center; gap: 5px; margin: 0 7px 4px; color: #81778f; font-size: .68rem; font-weight: 700; }
.message.mine .message-meta .sender { display: none; }
.reply-action { visibility: hidden; border: 0; padding: 2px 5px; border-radius: 6px; color: #716681; background: transparent; font-size: .66rem; font-weight: 800; }
.message:hover .reply-action, .message:focus-within .reply-action { visibility: visible; }
.reply-action:hover { color: var(--ink); background: color-mix(in srgb, var(--lilac) 18%, white); }
.bubble { max-width: min(76%, 570px); padding: 10px 14px; border: 1.7px solid var(--ink); border-radius: 7px 18px 18px 18px; color: var(--ink); background: #fff; box-shadow: 3px 3px 0 rgba(51, 45, 79, .14); line-height: 1.42; overflow-wrap: anywhere; white-space: pre-wrap; }
.message.mine .bubble { border-radius: 18px 7px 18px 18px; background: color-mix(in srgb, var(--sun) 66%, white); box-shadow: 3px 3px 0 rgba(51, 45, 79, .2); }
.reply-quote { width: 100%; display: grid; gap: 1px; margin: 0 0 8px; padding: 7px 9px; overflow: hidden; border: 0; border-left: 4px solid var(--coral); border-radius: 7px; color: var(--ink); background: color-mix(in srgb, var(--lilac) 13%, white); text-align: left; }
.reply-quote strong { color: var(--coral); font-size: .7rem; }
.reply-quote span { overflow: hidden; font-size: .73rem; opacity: .75; text-overflow: ellipsis; white-space: nowrap; }
.message-text { white-space: pre-wrap; }
.message.flash .bubble { animation: reply-flash .8s ease; }
@keyframes reply-flash { 0%, 100% { transform: none; } 35% { transform: scale(1.025); box-shadow: 0 0 0 5px color-mix(in srgb, var(--coral) 25%, transparent); } }

.reply-context { min-width: 0; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 9px 17px; border-top: 2px solid var(--ink); background: color-mix(in srgb, var(--lilac) 13%, white); }
.reply-context[hidden] { display: none; }
.reply-context-mark { width: 29px; height: 29px; display: grid; place-items: center; border-radius: 9px; color: var(--ink); background: color-mix(in srgb, var(--sun) 60%, white); font-weight: 900; }
.reply-context > div { min-width: 0; display: grid; }
.reply-context strong { color: var(--coral); font-size: .72rem; }
.reply-context span:not(.reply-context-mark) { overflow: hidden; color: #716981; font-size: .72rem; text-overflow: ellipsis; white-space: nowrap; }
.reply-context button { width: 30px; height: 30px; border: 0; border-radius: 50%; color: var(--ink); background: transparent; font-size: 1.2rem; }
.reply-context button:hover { background: rgba(255, 255, 255, .7); }
.reply-context:not([hidden]) + .composer { border-top: 0; }

.composer { position: relative; display: grid; grid-template-columns: auto 1fr auto; align-items: end; gap: 10px; padding: 14px 16px; border-top: 2px solid var(--ink); background: #fff; }
.composer textarea { max-height: 130px; min-height: 50px; resize: none; padding: 13px 15px; border-color: #bfb4d1; line-height: 1.35; }
.emoji-control { position: relative; }
.emoji-button { width: 50px; height: 50px; border: 2px solid var(--ink); border-radius: 15px; color: var(--ink); background: color-mix(in srgb, var(--lilac) 15%, white); box-shadow: 2px 2px 0 var(--ink); font-size: 1.38rem; }
.emoji-button:hover, .emoji-button[aria-expanded="true"] { background: color-mix(in srgb, var(--lilac) 30%, white); transform: rotate(-3deg); }
.emoji-button:focus-visible, .emoji-choice:focus-visible { outline: 4px solid rgba(91, 141, 239, .26); outline-offset: 2px; }
.emoji-picker { position: absolute; bottom: 63px; left: 0; z-index: 5; width: min(340px, calc(100vw - 32px)); display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; padding: 11px; border: 2px solid var(--ink); border-radius: 20px; background: #fffaf0; box-shadow: 6px 7px 0 var(--ink); }
.emoji-picker[hidden] { display: none; }
.emoji-choice { aspect-ratio: 1; display: grid; place-items: center; min-width: 0; border: 0; border-radius: 10px; background: transparent; font-size: 1.35rem; }
.emoji-choice:hover { background: #fff0bd; transform: scale(1.12) rotate(4deg); }
.send-button { width: 50px; height: 50px; display: grid; place-items: center; flex: none; border: 2px solid var(--ink); border-radius: 15px; color: #fff; background: var(--coral); box-shadow: 3px 3px 0 var(--ink); transition: transform .12s, box-shadow .12s; }
.send-button:hover { transform: translate(1px, 1px); box-shadow: 2px 2px 0 var(--ink); }
.send-button svg { width: 22px; fill: currentColor; }
.send-button:disabled { opacity: .45; cursor: default; }
.chat-error { min-height: 0; margin: 0; padding: 0 18px; color: #b93649; background: #fff; font-size: .75rem; }
.chat-error:not(:empty) { padding-bottom: 10px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

.theme-dialog { width: min(520px, calc(100vw - 30px)); padding: 24px; border: 2.5px solid var(--ink); border-radius: 24px; color: var(--ink); background: var(--cream); box-shadow: 8px 9px 0 var(--ink); }
.theme-dialog::backdrop { background: rgba(35, 29, 55, .48); backdrop-filter: blur(3px); }
.theme-dialog-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; }
.theme-dialog-heading h2 { margin: 0; font-size: 1.45rem; }
.close-theme-button { width: 34px; height: 34px; flex: none; border: 2px solid var(--ink); border-radius: 50%; color: var(--ink); background: #fff; font-size: 1.3rem; line-height: 1; }
.theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 11px; margin: 22px 0 13px; }
.theme-choice { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 11px; position: relative; padding: 13px; border: 2px solid color-mix(in srgb, var(--ink) 32%, white); border-radius: 16px; color: var(--ink); background: #fff; text-align: left; }
.theme-choice:hover, .theme-choice[aria-pressed="true"] { border-color: var(--ink); box-shadow: 3px 3px 0 var(--ink); transform: translate(-1px, -1px); }
.theme-choice[aria-pressed="true"]::after { content: "✓"; position: absolute; top: 5px; right: 8px; color: var(--coral); font-weight: 900; }
.theme-choice strong { align-self: end; font-size: .88rem; }
.theme-choice small { color: #756d85; font-size: .68rem; }
.theme-swatch { grid-row: 1 / 3; display: flex; align-items: center; width: 54px; }
.theme-swatch i { width: 23px; height: 35px; display: block; margin-right: -8px; border: 1.5px solid #332d4f; border-radius: 12px; }
.sunny-swatch i:nth-child(1) { background: #ff6b6b; }.sunny-swatch i:nth-child(2) { background: #ffc857; }.sunny-swatch i:nth-child(3) { background: #5b8def; }
.ocean-swatch i:nth-child(1) { background: #4386e8; }.ocean-swatch i:nth-child(2) { background: #73d6e6; }.ocean-swatch i:nth-child(3) { background: #56c9b5; }
.berry-swatch i:nth-child(1) { background: #d95b9e; }.berry-swatch i:nth-child(2) { background: #e9a6d0; }.berry-swatch i:nth-child(3) { background: #8a65ce; }
.woodland-swatch i:nth-child(1) { background: #e6814f; }.woodland-swatch i:nth-child(2) { background: #e9bd5d; }.woodland-swatch i:nth-child(3) { background: #70b978; }
.theme-note { margin: 0; color: #7b728b; text-align: center; font-size: .7rem; }

@media (max-width: 600px) {
  .app-shell { padding: 0; }
  .join-view { padding: 24px 19px 34px; }
  .brand-mark { width: 92px; }
  .joy-chips { margin-bottom: 20px; }
  .card { padding: 24px; box-shadow: 6px 7px 0 var(--ink); }
  .chat-view { width: 100%; height: 100dvh; min-height: 0; border: 0; border-radius: 0; box-shadow: none; }
  .chat-header { gap: 8px; padding: max(14px, env(safe-area-inset-top)) 13px 13px; border-bottom-width: 2px; }
  .room-home { width: 40px; height: 38px; }
  .room-home::before { top: -7px; width: 27px; height: 17px; }
  .chat-header h2 { max-width: 120px; font-size: 1.05rem; }
  .header-actions { gap: 6px; }
  .users-button { display: block; }
  .chat-content { grid-template-columns: minmax(0, 1fr); }
  .user-sidebar { position: absolute; inset: 0 auto 0 0; z-index: 4; width: min(290px, 84vw); border-right: 2px solid var(--ink); box-shadow: 9px 0 0 rgba(51, 45, 79, .15); transform: translateX(-105%); transition: transform .2s ease; }
  .user-sidebar.open { transform: translateX(0); }
  .close-users-button { display: block; }
  .messages { padding: 18px 13px; }
  .bubble { max-width: 88%; }
  .reply-action { visibility: visible; }
  .composer { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .emoji-picker { grid-template-columns: repeat(7, 1fr); }
  .status { display: none; }
  .header-theme-button { width: 32px; height: 32px; }
  .theme-dialog { padding: 20px; }
  .theme-grid { grid-template-columns: 1fr; }
}

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