:root {
  --ink: #10231f;
  --leaf: #1f6f5b;
  --leaf-deep: #0f3f35;
  --foam: #e8f3ef;
  --mist: #c5ddd4;
  --sand: #f4efe6;
  --amber: #d97706;
  --bubble-me: #dceee7;
  --bubble-kk: #ffffff;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(16, 35, 31, 0.18);
  --radius: 22px;
  --font: "DM Sans", sans-serif;
  --display: "Instrument Serif", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 10% -10%, #9fd6c4 0%, transparent 55%),
    radial-gradient(900px 600px at 100% 0%, #f0d7a8 0%, transparent 50%),
    linear-gradient(160deg, #f7f4ee 0%, #e7f0eb 45%, #d7e8e1 100%);
  overflow: hidden;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(16, 35, 31, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(16, 35, 31, 0.035) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(circle at center, black 30%, transparent 80%);
  pointer-events: none;
  animation: drift 28s linear infinite;
}

@keyframes drift {
  from { transform: translateY(0); }
  to { transform: translateY(28px); }
}

.app {
  max-width: 780px;
  height: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 18px 16px 14px;
  position: relative;
  z-index: 1;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 4px 16px;
  animation: rise 0.6s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.brand { display: flex; gap: 14px; align-items: center; }
.avatar {
  width: 52px; height: 52px; border-radius: 16px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--leaf), var(--leaf-deep));
  color: white; font-weight: 700; letter-spacing: 0.04em;
  box-shadow: 0 10px 24px rgba(31, 111, 91, 0.35);
}

h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.8rem, 4vw, 2.35rem);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1;
}
h1 em { font-style: italic; color: var(--leaf-deep); }
.sub { margin: 6px 0 0; color: #4a635c; font-size: 0.92rem; }

.ghost, .primary, .composer button {
  font: inherit; cursor: pointer; border: 0;
}
.ghost {
  background: rgba(255,255,255,0.55);
  border: 1px solid rgba(16,35,31,0.12);
  color: var(--ink);
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  backdrop-filter: blur(8px);
}
.ghost:hover { background: white; }

.chat {
  overflow-y: auto;
  padding: 8px 4px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.kk-burst {
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  max-width: min(78%, 520px);
}

.kk-burst .msg.kk {
  max-width: 100%;
  box-shadow: 0 8px 22px rgba(16, 35, 31, 0.10);
}

.msg {
  max-width: min(78%, 520px);
  padding: 0.72rem 0.95rem;
  border-radius: 18px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  animation: pop 0.28s ease both;
  box-shadow: 0 1px 0 rgba(16,35,31,0.04);
}
@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.msg.me {
  align-self: flex-end;
  background: var(--bubble-me);
  border-bottom-right-radius: 6px;
}
.msg.kk {
  align-self: flex-start;
  background: var(--bubble-kk);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow);
}
.msg.system {
  align-self: center;
  background: transparent;
  box-shadow: none;
  color: #5b716a;
  font-size: 0.88rem;
  text-align: center;
  max-width: 90%;
}
.msg .meta {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.72rem;
  opacity: 0.55;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px;
  background: rgba(255,255,255,0.72);
  border: 1px solid rgba(16,35,31,0.08);
  border-radius: 20px;
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  animation: rise 0.7s ease both;
}
.composer input {
  border: 0; outline: 0; background: transparent;
  font: inherit; font-size: 1rem; color: var(--ink);
  padding: 0.55rem 0.35rem;
}
.composer button, .primary {
  background: var(--leaf);
  color: white;
  padding: 0.7rem 1.15rem;
  border-radius: 14px;
  font-weight: 600;
}
.composer button:hover, .primary:hover { background: var(--leaf-deep); }
.primary.accent { background: var(--ink); }
.primary.accent:hover { background: #000; }
.composer button:disabled { opacity: 0.5; cursor: wait; }

.drawer {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(16, 35, 31, 0.42);
  display: grid; place-items: end center;
  padding: 16px;
}
.drawer[hidden] { display: none; }
.drawer-panel {
  width: min(560px, 100%);
  max-height: min(88vh, 820px);
  overflow: auto;
  background: var(--sand);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  animation: rise 0.35s ease both;
}
.drawer-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.drawer-head h2 {
  margin: 0; font-family: var(--display); font-weight: 400; font-size: 1.8rem;
}
.steps {
  color: #4a635c; padding-left: 1.2rem; margin: 0 0 1rem;
  line-height: 1.5;
}
.field { display: grid; gap: 0.4rem; margin: 0.85rem 0; }
.field span { font-size: 0.88rem; font-weight: 600; }
.field input[type="text"], .field input[type="file"] {
  width: 100%; font: inherit; padding: 0.7rem 0.8rem;
  border-radius: 12px; border: 1px solid rgba(16,35,31,0.15);
  background: white;
}
.hint { margin: 0 0 0.8rem; color: #5b716a; font-size: 0.88rem; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.log {
  margin-top: 14px; background: #10231f; color: #d7ebe3;
  padding: 12px; border-radius: 12px; min-height: 64px;
  white-space: pre-wrap; font-size: 0.82rem; overflow: auto;
}

@media (max-width: 640px) {
  .msg { max-width: 88%; }
  h1 { font-size: 1.7rem; }
}
