/* Apsara brand tokens, taken from apsaraofficial.com (Elementor global kit) */
:root {
  --aqua: #95E5EE;        /* primary */
  --teal: #00ADBB;        /* logo / strong accent */
  --teal-dark: #00838E;
  --ink: #2F2F2F;         /* secondary + text */
  --sun: #FFFE7D;         /* accent */
  --white: #FFFFFF;
  --mist: #EAFAFC;        /* page wash derived from aqua */
  --line: #CFEFF3;
  --coral: #FF5062;       /* site's red, used only for errors */
  --radius: 22px;
  --font: "Nunito Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --shadow: 0 2px 0 rgba(47, 47, 47, .9);
}

* { box-sizing: border-box; }
html { height: 100%; }
body { min-height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cg fill='none' stroke='%2300ADBB' stroke-width='2' stroke-linecap='round' opacity='.16'%3E%3Cpath d='M20 30l6 6M26 30l-6 6'/%3E%3Ccircle cx='120' cy='40' r='7'/%3E%3Cpath d='M60 110q10-12 20 0t20 0'/%3E%3Cpath d='M130 120l5 10 10 3-10 3-5 10-5-10-10-3 10-3z'/%3E%3Cpath d='M30 140l12-24'/%3E%3C/g%3E%3C/svg%3E"),
    var(--mist);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--white);
  border-bottom: 3px solid var(--aqua);
}
.brand { height: 28px; width: auto; }
.agent { display: flex; align-items: center; gap: 10px; margin-left: auto; margin-right: auto; }
.agent-face { width: 40px; height: 40px; }
.agent-name { font-weight: 900; font-size: 20px; line-height: 1; letter-spacing: -.01em; }
.agent-sub { white-space: nowrap; font-size: 12.5px; color: #5d6b6d; font-weight: 600; }
.ghost {
  border: 2px solid var(--line); background: var(--white); color: var(--ink);
  width: 38px; height: 38px; border-radius: 50%; font-size: 18px; font-weight: 800; cursor: pointer;
}
.ghost:hover { border-color: var(--teal); }

/* ---------- My Art ---------- */
.top-actions { display: flex; align-items: center; gap: 8px; }
.art-btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  font: inherit; font-weight: 900; font-size: 14.5px; color: var(--ink);
  padding: 7px 8px 7px 12px; border-radius: 999px; white-space: nowrap; flex: none;
  background: var(--sun); border: 2px solid var(--ink); box-shadow: 0 2px 0 var(--ink);
  transition: transform .08s, box-shadow .08s;
}
.art-btn:active { transform: translateY(2px); box-shadow: 0 0 0 var(--ink); }
.art-btn .count {
  min-width: 24px; height: 24px; padding: 0 6px; border-radius: 999px;
  background: var(--teal); color: var(--white); font-size: 13px; display: grid; place-items: center;
}
.art-btn.bump { animation: bump .5s; }
@keyframes bump { 30% { transform: scale(1.15) rotate(-4deg); } 60% { transform: scale(.96); } }

.scrim { position: fixed; inset: 0; background: rgba(47, 47, 47, .35); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 21;
  width: min(420px, 100%); background: var(--white);
  border-left: 3px solid var(--ink);
  display: flex; flex-direction: column;
  transform: translateX(105%); transition: transform .25s ease-out;
}
.drawer.open { transform: none; }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 16px 18px; padding-top: max(16px, env(safe-area-inset-top));
  border-bottom: 3px solid var(--aqua);
}
.drawer-title { font-weight: 900; font-size: 20px; }
.drawer-sub { font-size: 13px; color: #5d6b6d; font-weight: 600; }
.drawer-body { flex: 1; overflow-y: auto; background: var(--mist); padding: 14px; }
.gallery-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; align-content: start;
}
.section-title { font-weight: 900; font-size: 15px; margin: 22px 2px 10px; }
.drawer.empty .section-title { margin-top: 6px; }
.thumb {
  display: flex; flex-direction: column; gap: 6px; padding: 6px; cursor: pointer;
  background: var(--white); border: 2px solid var(--ink); border-radius: 16px; box-shadow: 0 3px 0 var(--ink);
  font: inherit; color: inherit; text-align: left;
  transition: transform .1s;
}
.thumb:hover, .thumb:focus-visible { transform: translateY(-2px) rotate(-1deg); outline: none; }
.thumb img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 11px; background: var(--mist); display: block; }
.thumb .t { font-size: 12.5px; font-weight: 700; line-height: 1.3; padding: 0 4px 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.thumb .n { font-size: 11px; font-weight: 900; color: var(--teal-dark); padding: 0 4px; }
.gallery-empty { display: none; flex-direction: column; align-items: center; text-align: center; padding: 18px 20px 6px; color: #5d6b6d; font-weight: 700; }
.drawer.empty #gallery-grid { display: none; }
.drawer.empty .gallery-empty { display: flex; }

.viewer {
  width: min(560px, calc(100% - 24px)); max-height: calc(100% - 24px); overflow-y: auto;
  border: 3px solid var(--ink); border-radius: 24px; box-shadow: 0 6px 0 var(--ink);
  padding: 18px; color: var(--ink); background: var(--white);
}
.viewer::backdrop { background: rgba(47, 47, 47, .55); }
.viewer img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 16px; border: 2.5px solid var(--ink); display: block; margin-top: 30px; }
.viewer-close { position: absolute; top: 12px; right: 12px; }
.viewer-meta { font-size: 12.5px; color: #5d6b6d; font-weight: 600; }
.viewer .actions .btn { font-size: 15px; padding: 10px 16px; }

/* ---------- Chat ---------- */
.chat {
  flex: 1;
  width: 100%; max-width: 760px; margin: 0 auto;
  padding: 20px 14px 140px;
  display: flex; flex-direction: column; gap: 14px;
}
.row { display: flex; gap: 10px; align-items: flex-end; animation: pop .28s ease-out both; }
.row.user { justify-content: flex-end; }
.avatar { width: 36px; height: 36px; flex: none; }
.bubble {
  max-width: min(88%, 600px);
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 16.5px; line-height: 1.5;
}
.kalpi .bubble {
  background: var(--white);
  border: 2px solid var(--ink);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow);
}
.user .bubble {
  background: var(--teal); color: var(--white);
  border-bottom-right-radius: 6px;
  font-weight: 700;
}
.kalpi .bubble.wide { max-width: 100%; width: 100%; }
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.hi { background: linear-gradient(transparent 55%, var(--sun) 55%); padding: 0 2px; }

@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- Story cards ---------- */
.cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 10px;
}
.card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  padding: 12px 14px; border-radius: 18px; cursor: pointer;
  background: var(--mist); border: 2px solid var(--line);
  font: inherit; color: inherit; text-align: left;
  transition: transform .12s, border-color .12s, background .12s;
}
.card:hover, .card:focus-visible { transform: translateY(-2px); border-color: var(--teal); background: #fff; outline: none; }
.card .emo { font-size: 28px; line-height: 1; }
.card .t { font-weight: 800; font-size: 15px; }
.card .s { font-size: 12.5px; color: #5d6b6d; }

/* ---------- Mad-lib story ---------- */
.story {
  font-size: 22px; line-height: 2.1; font-weight: 700;
  padding: 6px 2px 2px;
}
.blank {
  font: inherit; font-weight: 900; color: var(--teal-dark);
  border: 0; border-bottom: 3px dashed var(--teal);
  background: rgba(149, 229, 238, .22);
  border-radius: 8px 8px 0 0;
  padding: 0 6px; margin: 0 2px;
  min-width: 5ch; text-align: center;
  transition: background .15s, border-color .15s;
}
.blank::placeholder { color: #8bb9be; font-weight: 700; font-size: .72em; }
.blank:focus { outline: none; background: var(--sun); border-bottom-style: solid; border-color: var(--ink); }
.blank.filled { background: rgba(255, 254, 125, .55); border-bottom-style: solid; }
.blank.missing { animation: wiggle .4s; border-color: var(--coral); }
@keyframes wiggle { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

.picks { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; min-height: 38px; }
.picks .label { font-size: 13px; font-weight: 700; color: #5d6b6d; align-self: center; margin-right: 2px; }
.chip {
  font: inherit; font-size: 14.5px; font-weight: 700; cursor: pointer;
  padding: 7px 13px; border-radius: 999px;
  background: var(--white); color: var(--ink); border: 2px solid var(--ink);
  box-shadow: 0 2px 0 var(--ink);
  transition: transform .08s, box-shadow .08s, background .12s;
}
.chip:hover { background: var(--sun); }
.chip:active { transform: translateY(2px); box-shadow: 0 0 0 var(--ink); }
.chip[aria-pressed="true"] { background: var(--aqua); }

.styles { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 2px dashed var(--line); }
.styles .label { width: 100%; font-size: 13px; font-weight: 700; color: #5d6b6d; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.btn {
  font: inherit; font-weight: 900; font-size: 17px; cursor: pointer;
  padding: 13px 22px; border-radius: 999px;
  border: 2.5px solid var(--ink); background: var(--teal); color: var(--white);
  box-shadow: 0 4px 0 var(--ink);
  transition: transform .08s, box-shadow .08s, filter .12s;
  display: inline-flex; align-items: center; gap: 8px; text-decoration: none;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.secondary { background: var(--white); color: var(--ink); font-size: 15px; padding: 10px 16px; }
.btn.sun { background: var(--sun); color: var(--ink); }
.btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; box-shadow: 0 4px 0 var(--ink); }

/* ---------- Generating ---------- */
.sketching { display: flex; align-items: center; gap: 14px; }
.canvas-anim {
  width: 92px; height: 92px; flex: none; border-radius: 16px; background: var(--mist);
  border: 2px dashed var(--teal); position: relative; overflow: hidden;
}
.canvas-anim svg { position: absolute; inset: 0; }
.canvas-anim .scribble { stroke-dasharray: 260; stroke-dashoffset: 260; animation: draw 2.4s ease-in-out infinite; }
.canvas-anim .pen { animation: pen 2.4s ease-in-out infinite; transform-origin: 0 0; }
@keyframes draw { 60%, 100% { stroke-dashoffset: 0; } }
@keyframes pen {
  0% { transform: translate(14px, 60px); } 20% { transform: translate(34px, 30px); }
  40% { transform: translate(52px, 62px); } 60% { transform: translate(74px, 32px); } 100% { transform: translate(74px, 32px); }
}
.dots span { display: inline-block; animation: bounce 1s infinite; }
.dots span:nth-child(2) { animation-delay: .15s; } .dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 50% { transform: translateY(-4px); } }
.tip { font-size: 13.5px; color: #5d6b6d; margin-top: 4px; }

/* ---------- Result ---------- */
.result img {
  display: block; width: 100%; height: auto; aspect-ratio: 1; object-fit: cover;
  border-radius: 16px; border: 2.5px solid var(--ink); background: var(--mist);
}
.caption { font-weight: 800; font-size: 17px; margin: 12px 0 4px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700;
  padding: 3px 10px; border-radius: 999px; background: var(--mist); color: var(--teal-dark); border: 1.5px solid var(--line);
}
.result .actions .btn { font-size: 15px; padding: 10px 16px; }
.soon { font-size: 11px; font-weight: 900; background: var(--ink); color: var(--sun); padding: 2px 7px; border-radius: 999px; }

.err { border-color: var(--coral) !important; }

/* ---------- Composer ---------- */
.composer {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(14px, env(safe-area-inset-bottom));
  width: calc(100% - 24px); max-width: 740px;
  display: flex; align-items: center; gap: 8px;
  padding: 8px; border-radius: 999px;
  background: var(--white); border: 2.5px solid var(--ink); box-shadow: 0 4px 0 var(--ink);
}
.composer input {
  flex: 1; min-width: 0; border: 0; outline: none; font: inherit; font-size: 16.5px; font-weight: 600;
  padding: 10px 6px; background: transparent; color: var(--ink);
}
.composer input::placeholder { color: #8a9a9c; }
.dice, .send {
  flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; font-size: 22px;
}
.dice { background: var(--sun); border: 2px solid var(--ink); }
.dice:hover { transform: rotate(-12deg); }
.send { background: var(--teal); color: var(--white); }
.send:hover { background: var(--teal-dark); }

@media (max-width: 520px) {
  .brand { height: 22px; }
  .agent-sub { display: none; }
  .art-label { display: none; }
  .agent { margin-left: 0; }
  .topbar { gap: 10px; padding-left: 12px; padding-right: 12px; }
  .story { font-size: 19px; }
  .cards { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .card { padding: 10px 12px; }
  .card .s { display: none; }
  .row.kalpi:has(.wide) .avatar { display: none; }
  .bubble { max-width: 92%; }
}

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

@media print {
  body * { visibility: hidden; }
  .print-me, .print-me * { visibility: visible; }
  .print-me { position: fixed; inset: 0; margin: auto; width: 100%; }
}
