:root {
  --steel: #4682b4;
  --steel-700: #3f76a3;
  --steel-900: #2b4f6e;
  --ink: #0f172a;
  --text: #0b1020;
  --muted: #6b7a90;
  --card-bg: rgba(255, 255, 255, 0.78);
  --border: rgba(70, 130, 180, 0.25);
  --shadow: 0 10px 30px rgba(43, 79, 110, 0.25);
  --focus: 0 0 0 3px rgba(70, 130, 180, 0.35);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 800px at 100% -10%, #eaf3fb 0%, #f6f9fc 45%, #ffffff 100%);
  overflow-x: hidden;
}

/* ── Layout ──────────────────────────────────────────────────── */

.container {
  max-width: 1200px;
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(16px, 2vw, 24px);
  position: relative;
  display: grid;
  grid-template-columns: 390px 1fr;
  gap: 0 2rem;
  align-items: stretch;
  align-content: center;
}

.left-col {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 2rem;
  padding: 2rem 0;
}

/* ── Header / Branding ───────────────────────────────────────── */

.header {
  text-align: left;
  margin: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  justify-content: flex-start;
}

.logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--steel), #6aa4cf);
  color: white;
  font-weight: 700;
  font-size: 20px;
  box-shadow: var(--shadow);
}

h1 {
  margin: 0;
  font-size: clamp(28px, 3.5vw, 40px);
  color: var(--ink);
  letter-spacing: 0.2px;
}

h1 span {
  color: var(--steel);
}

.subtitle {
  color: var(--muted);
  margin: 0.5rem 0 0;
}

.footerdata {
  display: block;
  width: fit-content;
  max-width: 700px;
  margin: 0.5rem auto;
  color: var(--muted);
}

/* ── Card ────────────────────────────────────────────────────── */

.card {
  backdrop-filter: blur(8px);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: clamp(16px, 2.5vw, 28px);
}

/* ── Form elements ───────────────────────────────────────────── */

.label {
  font-weight: 600;
  color: var(--ink);
}

textarea {
  width: 100%;
  min-height: 140px;
  margin-top: 0.5rem;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  font-size: 16px;
  line-height: 1.4;
  background: #fff;
  transition: box-shadow 0.2s, border-color 0.2s;
}

textarea:focus {
  box-shadow: var(--focus);
  border-color: var(--steel);
}

.actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.actions-split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* ── Buttons ─────────────────────────────────────────────────── */

button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--steel);
  background: linear-gradient(180deg, var(--steel), var(--steel-700));
  color: #fff;
  padding: 9px 10px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.06s ease, filter 0.2s ease;
}

button:hover {
  filter: brightness(1.04);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.shortcut {
  margin-left: 6px;
  background: rgba(255, 255, 255, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.4);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 1rem;
}

.btn-text {
  font-size: 1.2rem;
  line-height: 1.2;
}

/* ── Spinner ─────────────────────────────────────────────────── */

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-top-color: #fff;
  animation: spin 1s linear infinite;
  opacity: 0;
  pointer-events: none;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Status / Divider ────────────────────────────────────────── */

.status {
  color: var(--muted);
  min-height: 1.25rem;
}

.divider {
  height: 1px;
  width: 100%;
  margin: 14px 0 10px;
  background: linear-gradient(90deg, transparent, rgba(70, 130, 180, 0.35), transparent);
}

/* ── Answer panel ────────────────────────────────────────────── */

.answer-title {
  margin: 0.25rem 0 0.5rem;
  font-size: 1.05rem;
  color: var(--ink);
}

.answer {
  white-space: pre-wrap;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  min-height: 150px;
  outline: none;
}

.answer:focus {
  box-shadow: var(--focus);
  border-color: var(--steel);
}

/* ── Footer ──────────────────────────────────────────────────── */

.footer {
  text-align: left;
  color: var(--muted);
  margin: 0;
}

/* ── Background decorative layers ───────────────────────────── */

.bg-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
}

.bg-grid {
  background-image:
    radial-gradient(circle at 16px 16px, rgba(70, 130, 180, 0.12) 1.5px, transparent 1.5px),
    radial-gradient(circle at 0 0, rgba(70, 130, 180, 0.05), transparent 45%);
  background-size: 32px 32px, 100% 100%;
}

.bg-glow {
  background:
    radial-gradient(600px 300px at 15% 20%, rgba(70, 130, 180, 0.20), transparent 60%),
    radial-gradient(700px 300px at 85% 10%, rgba(106, 164, 207, 0.18), transparent 60%),
    radial-gradient(800px 400px at 50% 110%, rgba(43, 79, 110, 0.16), transparent 60%);
}

/* ── Flip CTA ────────────────────────────────────────────────── */

.flip-cta-wrap {
  display: flex;
  justify-content: flex-start;
  margin: 0;
}

.flip-btn {
  border: 1px solid #37963c;
  background: linear-gradient(180deg, #4eab52, #328636);
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  font-size: 1.2rem;
  line-height: 1.2;
  transition: transform 0.06s ease, filter 0.2s ease;
}

.flip-btn:hover {
  filter: brightness(1.05);
}

.flip-btn:active {
  transform: translateY(1px);
}

/* ── 3-D flip container ──────────────────────────────────────── */

.flip-container {
  position: relative;
  perspective: 1200px;
  min-height: 600px;
  margin: 1rem 0;
}

.flip-container .card {
  position: absolute;
  inset: 0;
  transition: transform 0.28s ease-in-out, opacity 0.28s ease-in-out;
}

.card-front {
  display: flex;
  flex-direction: column;
  transform: rotateY(0deg);
}

.card-back {
  transform: rotateY(180deg);
  opacity: 0;
  pointer-events: none;
  max-height: 70vh;
  overflow-y: auto;
  padding-right: 1rem;
  scrollbar-width: thin;
}

.card-back::-webkit-scrollbar-thumb {
  background-color: rgba(70, 130, 180, 0.5);
  border-radius: 4px;
}

.flip-container.flipped .card-front {
  transform: rotateY(-180deg);
  opacity: 0;
  pointer-events: none;
}

.flip-container.flipped .card-back {
  transform: rotateY(0deg);
  opacity: 1;
  pointer-events: auto;
}

/* ── Back face content ───────────────────────────────────────── */

.back-grid {
  display: flex;
  flex-direction: column;
}

.hero-img {
  width: 100%;
  max-width: 700px;
  max-height: 600px;
}

.back-title {
  margin: 0 0 0.4rem;
  color: var(--ink);
  align-self: center;
}

.back-lead {
  color: var(--text);
  margin: 0 0 0.8rem;
}

.back-subtitle {
  margin: 0.4rem 0;
  color: var(--ink);
}

.bullet {
  margin: 0.2rem 0 0.6rem 1.1rem;
}

.numbered {
  margin: 0.2rem 0 0.2rem 1.1rem;
}

/* ── Chat interface ──────────────────────────────────────────── */

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.clear-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 4px 10px;
  font-size: 0.8rem;
  border-radius: 8px;
  box-shadow: none;
  font-weight: 400;
}

.clear-btn:hover {
  background: rgba(70, 130, 180, 0.08);
  filter: none;
}

.chat-window {
  flex: 1;
  min-height: 200px;
  overflow-y: auto;
  padding: 12px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
}

.empty-state ul {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.empty-state li {
  background: rgba(70, 130, 180, 0.08);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
}

.msg-wrapper {
  display: flex;
}

.msg-wrapper--user {
  justify-content: flex-end;
}

.msg-wrapper--ai {
  justify-content: flex-start;
}

.msg {
  max-width: 82%;
  padding: 10px 14px;
  line-height: 1.55;
  word-break: break-word;
  font-size: 0.95rem;
}

.msg-user {
  white-space: pre-wrap;
  background: linear-gradient(135deg, var(--steel), var(--steel-700));
  color: #fff;
  border-radius: 18px 18px 4px 18px;
}

.msg-ai {
  white-space: normal;
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 18px 18px 18px 4px;
}

/* Tighten markdown elements rendered inside AI bubbles */
.msg-ai p,
.msg-ai ul,
.msg-ai ol,
.msg-ai li {
  margin: 0;
}

.msg-ai ul,
.msg-ai ol {
  padding-left: 1.4rem;
}

.msg-ai li > p {
  display: contents;
}

.msg-ai li ~ li {
  margin-top: 0.2rem;
}

.msg-ai > * + * {
  margin-top: 0.4rem;
}

.msg-ai strong {
  font-weight: 600;
}

/* ── Typing indicator ────────────────────────────────────────── */

.msg-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  min-width: 56px;
}

.msg-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.2s infinite;
  will-change: transform, opacity;
}

.msg-typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.msg-typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* ── Chat input bar ──────────────────────────────────────────── */

.chat-input-bar {
  margin-top: 12px;
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.input-row textarea {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  resize: none;
  margin: 0;
  overflow-y: auto;
}

.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  flex-wrap: wrap;
  gap: 6px;
}

/* ── Mic / voice input button ────────────────────────────────── */

.mic-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--steel);
  padding: 0 12px;
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mic-btn:hover {
  background: rgba(70, 130, 180, 0.08);
  filter: none;
}

.mic-btn.recording {
  background: linear-gradient(180deg, #e25151, #c43d3d);
  border-color: #c43d3d;
  color: #fff;
  animation: mic-pulse 1.2s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(226, 81, 81, 0.55); }
  50%      { box-shadow: 0 0 0 8px rgba(226, 81, 81, 0); }
}

/* ── Dark mode ───────────────────────────────────────────────── */

@media (prefers-color-scheme: dark) {
  :root {
    --card-bg: rgba(18, 22, 30, 0.72);
    --text: #e8eef6;
    --ink: #f3f7fb;
    --muted: #a9b6c8;
    --border: rgba(106, 164, 207, 0.28);
  }

  body {
    background: radial-gradient(1200px 800px at 100% -10%, #0b1320 0%, #0f172a 45%, #0b1222 100%);
  }

  .answer {
    background: rgba(10, 14, 22, 0.6);
  }

  .logo {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  }

  .hero-img {
    border-color: rgba(106, 164, 207, 0.28);
  }

  .chat-window {
    background: rgba(10, 14, 22, 0.5);
  }

  .msg-ai {
    background: rgba(20, 26, 38, 0.8);
  }

  .empty-state li {
    background: rgba(70, 130, 180, 0.12);
  }
}

/* ── Responsive ──────────────────────────────────────────────── */

@media (max-width: 820px) {
  .back-grid {
    grid-template-columns: 1fr;
  }

  .hero-img {
    max-height: 220px;
  }

  .container {
    grid-template-columns: 1fr;
  }

  .left-col {
    padding: 1.5rem 0 0;
    gap: 1.25rem;
  }

  .header {
    text-align: center;
  }

  .footer {
    text-align: center;
  }

  .brand {
    justify-content: center;
  }

  .subtitle {
    margin-left: auto;
    margin-right: auto;
  }

  .flip-cta-wrap {
    justify-content: center;
  }
}
