:root {
  --bg: #071a24;
  --bg-soft: #0b2430;
  --card: #0f2d3a;
  --card-2: #123644;
  --ink: #f2fbfc;
  --muted: #9fd8dd;
  --accent: #2fd3d8;
  --accent-2: #1aa6ad;
  --danger: #ff6b6b;
  --radius: 16px;
  --tab-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(47, 211, 216, 0.16), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(47, 211, 216, 0.08), transparent 60%),
    var(--bg);
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 820px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 0 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(14px);
  background: rgba(7, 26, 36, 0.72);
  border-bottom: 1px solid rgba(47, 211, 216, 0.12);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo { width: 38px; height: 38px; border-radius: 12px; object-fit: cover; border: 1px solid rgba(47, 211, 216, 0.45); }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand-text strong { font-size: 16px; letter-spacing: 0.2px; }
.brand-text span { font-size: 11.5px; color: var(--muted); }

.balance {
  border: 1px solid rgba(47, 211, 216, 0.35);
  background: rgba(47, 211, 216, 0.1);
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

main { flex: 1; display: flex; flex-direction: column; padding: 12px 14px calc(var(--tab-h) + 78px); }

.tab-panel { display: none; flex-direction: column; gap: 12px; }
.tab-panel.is-active { display: flex; }

.messages { display: flex; flex-direction: column; gap: 10px; padding: 4px 0 8px; }
.msg { max-width: 88%; padding: 10px 13px; border-radius: 16px; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, var(--accent-2), #147b83); color: #fff; border-bottom-right-radius: 6px; }
.msg.bot { align-self: flex-start; background: var(--card); border: 1px solid rgba(47, 211, 216, 0.12); border-bottom-left-radius: 6px; }
.msg.bot code { background: rgba(0, 0, 0, 0.28); padding: 1px 5px; border-radius: 6px; font-size: 13px; }
.msg.typing { color: var(--muted); font-style: italic; }

.quick { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 0 6px; }
.quick button {
  border: 1px solid rgba(47, 211, 216, 0.28);
  background: rgba(47, 211, 216, 0.08);
  color: var(--ink);
  padding: 7px 11px;
  border-radius: 999px;
  font-size: 12.5px;
  cursor: pointer;
}

.card {
  background: var(--card);
  border: 1px solid rgba(47, 211, 216, 0.14);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card h2 { margin: 0; font-size: 17px; }
.card p.hint { margin: 0; color: var(--muted); font-size: 12.5px; }

textarea {
  width: 100%;
  resize: none;
  border-radius: 12px;
  border: 1px solid rgba(47, 211, 216, 0.22);
  background: var(--bg-soft);
  color: var(--ink);
  padding: 11px 12px;
  font: inherit;
  outline: none;
}
textarea:focus { border-color: rgba(47, 211, 216, 0.6); }

button.primary, button.secondary, button.ghost {
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}
button.primary { background: var(--accent); color: #04212a; }
button.primary:disabled { opacity: 0.55; }
button.secondary { background: rgba(47, 211, 216, 0.14); color: var(--ink); border: 1px solid rgba(47, 211, 216, 0.3); }
button.ghost { background: transparent; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  border: 1px solid rgba(47, 211, 216, 0.25);
  background: transparent;
  color: var(--muted);
  padding: 7px 11px;
  border-radius: 999px;
  font-size: 12.5px;
  cursor: pointer;
}
.chips button.is-active { background: rgba(47, 211, 216, 0.18); color: var(--ink); border-color: var(--accent); }

.row { display: flex; gap: 14px; flex-wrap: wrap; }
.radio { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13.5px; }
.radio input { accent-color: var(--accent); }

.result { display: flex; flex-direction: column; gap: 10px; }
.result img { width: 100%; border-radius: var(--radius); border: 1px solid rgba(47, 211, 216, 0.2); }
.result audio { width: 100%; }
.result .meta { color: var(--muted); font-size: 12.5px; }

.link { color: var(--accent); text-align: center; font-size: 13.5px; }

.composer {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
  width: min(100%, 820px);
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(7, 26, 36, 0), rgba(7, 26, 36, 0.96) 40%);
  z-index: 9;
}
.composer textarea {
  flex: 1;
  max-height: 132px;
  border-radius: 14px;
  padding: 11px 13px;
}
.send {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #04212a;
  font-size: 18px;
  cursor: pointer;
  flex: 0 0 auto;
}
.send:disabled { opacity: 0.5; }

.tabs {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(100%, 820px);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(8, 30, 40, 0.96);
  border-top: 1px solid rgba(47, 211, 216, 0.14);
  backdrop-filter: blur(14px);
  z-index: 10;
}
.tab {
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 18px;
  cursor: pointer;
}
.tab span { font-size: 11px; }
.tab.is-active { color: var(--accent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + 88px);
  transform: translateX(-50%) translateY(12px);
  background: #0f333f;
  border: 1px solid rgba(47, 211, 216, 0.35);
  color: var(--ink);
  padding: 9px 14px;
  border-radius: 12px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 30;
  max-width: 86vw;
  text-align: center;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 10, 14, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 40;
}
.modal.is-hidden { display: none; }
.modal-card {
  width: min(100%, 460px);
  background: var(--card);
  border: 1px solid rgba(47, 211, 216, 0.22);
  border-radius: 18px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-card h2 { margin: 0; font-size: 17px; }
.modal-card p { margin: 0; color: var(--muted); font-size: 13.5px; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; }

@media (min-width: 700px) {
  .messages { padding: 12px 6px; }
  main { padding-left: 24px; padding-right: 24px; }
}
