:root {
  --snoeproze: #f41f91;
  --suikerspin: #fe98d8;
  --jet: #162327;
  --ivory: #fcfbf5;
  --sky: #7dc4ea;
  --mint: #2ec98a;
  --straw: #f53d7a;
  --mist: #ecebe5;   /* light grey for visitor bubbles, asked for by Amir */
  --ease: cubic-bezier(.2, .8, .2, 1);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--ivory); color: var(--jet); font-family: Karla, system-ui, sans-serif; font-weight: 400; font-size: 16px; line-height: 1.5; }
button, input { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--jet); text-decoration-color: var(--snoeproze); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg { stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Spekkie rig ---------- */
.spk-stage { position: relative; aspect-ratio: 1 / 1; width: 100%; }
.spk-rig, .spk-rig div, .spk-rig img, .spk-rig svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.spk-move { transform-origin: 51.04% 51.52%; will-change: transform; }
.spk-scale { transform-origin: 51.04% 71.77%; will-change: transform; }
.spk-candy { user-select: none; -webkit-user-drag: none; cursor: pointer; }
.spk-tint { -webkit-mask-image: var(--spk-candy); mask-image: var(--spk-candy); -webkit-mask-size: 100% 100%; mask-size: 100% 100%; opacity: 0; pointer-events: none; }
.spk-sky { background: var(--sky); } .spk-mint { background: var(--mint); } .spk-straw { background: var(--straw); }
.spk-face, .spk-orbit { pointer-events: none; overflow: visible; }

/* ---------- Shell: chat | panel | rail ---------- */
body.chat { overflow: hidden; }
.shell { display: flex; height: 100dvh; }

.chatcol { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; align-items: center; padding: 0 20px 18px; }
.chatcol > * { width: 100%; max-width: 680px; }

/* Avatar: big in the middle at the start, small at the top once the conversation starts */
.avatar { display: flex; flex-direction: column; align-items: center; }
.stage-box { position: relative; will-change: transform; }
.stage-box .spk-stage { width: 100%; }
.nameplate { display: none; flex-direction: column; align-items: center; line-height: 1.2; }
.nameplate strong { font-weight: 800; font-size: 15px; }
.status { font-size: 13px; min-height: 16px; }

.chatcol.intro .avatar { flex: 1 1 auto; justify-content: flex-end; min-height: 0; padding-top: 24px; }
.chatcol.intro .stage-box { width: min(100%, 38dvh, 420px); }
.chatcol.active .avatar { flex: none; padding-top: 12px; }
.chatcol.active .stage-box { width: 128px; margin: -38px 0 -40px; }
.chatcol.active .nameplate { display: flex; }

/* Welcome and functions */
.welcome { flex: none; text-align: center; padding: 8px 0 22px; }
.welcome h1 { font-weight: 800; font-size: 28px; margin: 0 0 16px; }
.functions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; text-align: left; }
.fn-card { display: flex; flex-direction: column; gap: 6px; padding: 14px; background: var(--ivory); border: 2px solid var(--jet); border-radius: 16px; cursor: pointer; text-align: left; transition: border-color .15s, transform .15s var(--ease); }
.fn-card:hover { border-color: var(--snoeproze); transform: translateY(-2px); }
.fn-card strong { font-weight: 700; font-size: 16px; }
.fn-card .desc { font-size: 14px; line-height: 1.35; }
.fn-text { display: flex; flex-direction: column; gap: 2px; }
.fn-icon { flex: none; width: 38px; height: 38px; border-radius: 10px; background: var(--snoeproze); display: grid; place-items: center; }
.fn-icon svg { width: 22px; height: 22px; fill: none; stroke: var(--ivory); stroke-width: 2; }
.chatcol.active .welcome { display: none; }

/* Conversation */
.log { display: none; flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 14px 2px 10px; scroll-behavior: smooth; }
.chatcol.active .log { display: block; }
.msg { margin: 8px 0; max-width: 82%; padding: 10px 16px; border-radius: 20px; width: fit-content; animation: pop .35s var(--ease); }
.msg p { margin: 0 0 8px; } .msg p:last-child { margin-bottom: 0; }
.msg ul { margin: 4px 0 8px; padding-left: 20px; }
.msg.user { margin-left: auto; background: var(--mist); border-bottom-right-radius: 6px; }
.msg.assistant { background: var(--suikerspin); border-bottom-left-radius: 6px; }
.msg.error { background: var(--ivory); border: 2px solid var(--straw); }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }

.tool { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 14px; font-weight: 700; }
.tool-links { margin: 2px 0 8px; padding-left: 20px; font-size: 14px; }
.tool-dots { display: inline-flex; gap: 4px; }
.tool-dots i, .cloud-dots i { width: 8px; height: 8px; border-radius: 6px; background: var(--snoeproze); display: block; animation: dot 1s infinite ease-in-out; }
.tool-dots i:nth-child(2), .cloud-dots i:nth-child(2) { animation-delay: .15s; }
.tool-dots i:nth-child(3), .cloud-dots i:nth-child(3) { animation-delay: .3s; }
.tool.ok .tool-dots i { animation: none; background: var(--mint); }
.tool.failed .tool-dots i { animation: none; background: var(--straw); }
@keyframes dot { 0%, 100% { transform: translateY(0); opacity: .5; } 50% { transform: translateY(-4px); opacity: 1; } }

.panel-chip { display: flex; align-items: center; gap: 10px; margin: 8px 0; padding: 8px 14px 8px 8px; background: var(--ivory); border: 2px solid var(--jet); border-radius: 16px; cursor: pointer; font-weight: 700; text-align: left; animation: pop .35s var(--ease); }
.panel-chip:hover { border-color: var(--snoeproze); }
.panel-chip .fn-icon { width: 32px; height: 32px; }
.panel-chip .fn-icon svg { width: 18px; height: 18px; }
.panel-chip small { display: block; font-weight: 400; font-size: 13px; }

/* Composer */
.composer { flex: none; display: flex; align-items: center; gap: 6px; background: var(--ivory); border: 2px solid var(--jet); border-radius: 36px; padding: 6px 6px 6px 18px; }
.composer:focus-within { border-color: var(--snoeproze); }
.composer input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; padding: 9px 0; font-size: 16px; }
.fnchip { flex: none; display: inline-flex; align-items: center; gap: 6px; background: var(--suikerspin); border-radius: 36px; padding: 4px 6px 4px 12px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.fnchip[hidden] { display: none; }
.fnchip button { border: 0; background: none; width: 20px; height: 20px; border-radius: 10px; cursor: pointer; display: grid; place-items: center; padding: 0; }
.fnchip button svg { width: 14px; height: 14px; fill: none; stroke: var(--jet); stroke-width: 2.4; }
.icon-btn { flex: none; width: 40px; height: 40px; border: 0; border-radius: 36px; background: transparent; display: grid; place-items: center; cursor: pointer; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--jet); stroke-width: 2; }
.icon-btn:hover { background: var(--mist); }
.icon-btn.mic { cursor: default; }
.icon-btn.mic svg { stroke: var(--suikerspin); }
.icon-btn.mic:hover { background: transparent; }
.send { flex: none; width: 44px; height: 44px; border-radius: 36px; border: 0; background: var(--snoeproze); display: grid; place-items: center; cursor: pointer; }
.send svg { width: 22px; height: 22px; fill: none; stroke: var(--ivory); stroke-width: 2.6; }
.send:disabled { background: var(--suikerspin); cursor: default; }

/* Speech bubble and thought cloud */
.speech { position: absolute; left: 51%; bottom: 72%; transform: translateX(-50%) scale(.6); transform-origin: 50% 100%; background: var(--ivory); border: 2.5px solid var(--jet); border-radius: 24px; padding: 10px 18px; font-weight: 700; font-size: 17px; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .25s ease, transform .35s cubic-bezier(.3, 1.6, .5, 1); }
.speech::after { content: ""; position: absolute; left: 50%; bottom: -10px; width: 16px; height: 16px; margin-left: -8px; background: var(--ivory); border-right: 2.5px solid var(--jet); border-bottom: 2.5px solid var(--jet); transform: rotate(45deg); }
.speech.show { opacity: 1; transform: translateX(-50%) scale(1); }
.chatcol.active .speech { display: none; }
.cloud { position: absolute; left: 52%; top: -16%; width: 64%; max-width: 330px; aspect-ratio: 240 / 170; opacity: 0; transform: scale(.5); transform-origin: 10% 95%; pointer-events: none; transition: opacity .25s ease, transform .4s cubic-bezier(.3, 1.5, .5, 1); }
.cloud.show { opacity: 1; transform: scale(1); }
.cloud-shape { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.cloud .trail { opacity: 0; transition: opacity .2s ease; }
.cloud.show .t2 { opacity: 1; } .cloud.show .t1 { opacity: 1; transition-delay: .08s; }
.cloud-text { position: absolute; left: 12%; right: 10%; top: 12%; height: 62%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center; font-weight: 700; font-size: 16px; line-height: 1.2; }
.cloud-label:empty { display: none; }
.cloud-dots { display: inline-flex; gap: 6px; }
.chatcol.active .cloud { left: 74%; top: 6%; width: 64px; }
.chatcol.active .cloud-label { display: none; }
.chatcol.active .cloud-dots i { width: 5px; height: 5px; }
.chatcol.active .cloud-dots { gap: 3px; }

/* ---------- Side panel ---------- */
.panel { flex: 0 0 0; min-width: 0; overflow: hidden; transition: flex-basis .5s var(--ease); }
.panel.open { flex-basis: min(50vw, 720px); }
.panel-card { height: calc(100dvh - 24px); margin: 12px 0; width: calc(min(50vw, 720px) - 12px); display: flex; flex-direction: column; border: 2px solid var(--jet); border-radius: 24px; background: var(--ivory); overflow: hidden; }
.panel-head { flex: none; display: flex; align-items: center; gap: 12px; padding: 14px 12px 14px 16px; border-bottom: 2px solid var(--suikerspin); }
.panel-icon { flex: none; width: 42px; height: 42px; border-radius: 12px; background: var(--snoeproze); display: grid; place-items: center; }
.panel-icon svg { width: 24px; height: 24px; fill: none; stroke: var(--ivory); stroke-width: 2; }
.panel-titles { flex: 1; min-width: 0; }
.panel-titles h2 { margin: 0; font-weight: 800; font-size: 20px; line-height: 1.2; }
.panel-titles p { margin: 2px 0 0; font-size: 14px; }
.panel-titles p:empty { display: none; }
.panel-body { flex: 1; overflow-y: auto; padding: 22px 28px 40px; }
.panel-body > * { animation: rise .45s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.panel-body h3 { font-weight: 800; font-size: 19px; margin: 22px 0 8px; }
.panel-body h3:first-child { margin-top: 0; }
.panel-body p { margin: 0 0 12px; }
.panel-body ul.b-list { list-style: none; margin: 0 0 14px; padding: 0; }
.panel-body ul.b-list li { position: relative; padding-left: 22px; margin: 6px 0; }
.panel-body ul.b-list li::before { content: ""; position: absolute; left: 4px; top: .6em; width: 8px; height: 8px; border-radius: 6px; background: var(--snoeproze); }
.panel-body .b-check { list-style: none; margin: 0 0 14px; padding: 0; }
.panel-body .b-check label { display: flex; gap: 12px; align-items: flex-start; padding: 8px 10px; border-radius: 10px; cursor: pointer; }
.panel-body .b-check label:hover { background: var(--mist); }
.panel-body .b-check input { appearance: none; flex: none; width: 22px; height: 22px; margin: 1px 0 0; border: 2px solid var(--jet); border-radius: 6px; display: grid; place-items: center; cursor: pointer; }
.panel-body .b-check input:checked { background: var(--mint); border-color: var(--mint); }
.panel-body .b-check input:checked::after { content: ""; width: 6px; height: 11px; border: solid var(--ivory); border-width: 0 2.5px 2.5px 0; transform: translateY(-1px) rotate(45deg); }
.panel-body ol.b-steps { list-style: none; margin: 0 0 14px; padding: 0; counter-reset: s; }
.panel-body ol.b-steps li { counter-increment: s; position: relative; padding: 4px 0 14px 46px; }
.panel-body ol.b-steps li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 32px; height: 32px; border-radius: 16px; background: var(--snoeproze); color: var(--ivory); font-weight: 800; display: grid; place-items: center; }
.panel-body ol.b-steps li:not(:last-child)::after { content: ""; position: absolute; left: 15px; top: 36px; bottom: 2px; width: 2px; background: var(--suikerspin); }
.panel-body blockquote { margin: 0 0 14px; padding: 4px 0 4px 18px; border-left: 4px solid var(--suikerspin); font-weight: 700; font-size: 18px; }
.panel-body .b-callout { margin: 0 0 14px; padding: 14px 16px; background: var(--suikerspin); border-radius: 16px; }

/* History and functions lists in the panel */
.hist-item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 14px; margin: 0 0 8px; border: 2px solid var(--jet); border-radius: 16px; background: var(--ivory); cursor: pointer; }
.hist-item:hover { border-color: var(--snoeproze); }
.hist-item strong { display: block; font-weight: 700; }
.hist-item span.when { font-size: 13px; }
.empty-note { margin: 0; }

/* ---------- Rail ---------- */
.rail { flex: none; width: 64px; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 16px 0; }
.rail-gap { flex: 1; }
.rail-btn { width: 44px; height: 44px; border: 0; border-radius: 14px; background: transparent; display: grid; place-items: center; cursor: pointer; }
.rail-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--jet); stroke-width: 2; }
.rail-btn:hover, .rail-btn.on { background: var(--suikerspin); }

/* ---------- Phone ---------- */
@media (max-width: 900px) {
  .rail { position: fixed; top: 8px; right: 8px; z-index: 20; width: auto; flex-direction: row; padding: 4px; gap: 2px; background: var(--ivory); border-radius: 18px; }
  .rail-gap { display: none; }
  .rail-btn { width: 40px; height: 40px; }
  .chatcol { padding: 0 12px 12px; }
  .chatcol.active .avatar { padding-top: 48px; }
  .chatcol.intro .avatar { padding-top: 56px; }
  .functions { grid-template-columns: 1fr; gap: 8px; }
  .fn-card { flex-direction: row; align-items: center; gap: 12px; padding: 10px 12px; }
  .welcome h1 { font-size: 22px; }
  .panel { position: fixed; inset: 0; z-index: 10; flex: none; transform: translateX(100%); transition: transform .45s var(--ease); background: var(--ivory); }
  .panel.open { transform: none; flex-basis: auto; }
  .panel-card { width: auto; height: 100dvh; margin: 0; border: 0; border-radius: 0; padding-top: 52px; }
  .panel-body { padding: 18px 18px 40px; }
  .msg { max-width: 90%; }
}

/* ---------- Login ---------- */
body.login { display: grid; place-items: center; min-height: 100dvh; padding: 16px; }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-card h1 { font-weight: 800; font-size: 40px; margin: 0 0 6px; }
.login-card p { margin: 0 0 16px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; }
.login-card input { text-align: center; letter-spacing: 2px; font-weight: 700; padding: 12px 16px; border: 2px solid var(--jet); border-radius: 16px; background: var(--ivory); outline: 0; }
.login-card input:focus { border-color: var(--snoeproze); }
.login-card button { padding: 12px 16px; border: 0; border-radius: 16px; background: var(--snoeproze); color: var(--ivory); font-weight: 700; cursor: pointer; }
.login-card button:disabled { background: var(--suikerspin); }
.msg-line { min-height: 24px; margin-top: 12px; font-weight: 700; }

@media (prefers-reduced-motion: reduce) {
  .tool-dots i, .cloud-dots i { animation: none; opacity: 1; }
  .log { scroll-behavior: auto; }
  .msg, .panel-chip, .panel-body > * { animation: none; }
  .speech, .cloud, .cloud .trail, .panel, .fn-card { transition: opacity .2s ease; }
}
.icon-btn[hidden] { display: none; }
