:root {
  --bg: #141417;
  --bg-elevated: #1a1a1f;
  --surface: #1e1e24;
  --surface-2: #26262e;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #f2f2f5;
  --text-muted: #a8a8b3;
  --text-soft: #7e7e8a;
  --accent: #6d5bd0;
  --accent-hover: #8576e8;
  --accent-pressed: #5a4ab8;
  --accent-glow: rgba(109, 91, 208, 0.35);
  --danger: #f08888;
  --radius: 14px;
  --radius-sm: 10px;
  --tap: 44px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", sans-serif;
  max-width: 820px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 120% 80% at 50% -20%, rgba(109, 91, 208, 0.18), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(109, 91, 208, 0.08), transparent 50%);
  color: var(--text);
  line-height: 1.55;
  letter-spacing: 0.01em;
}

header {
  margin-bottom: 6px;
}

header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #ffffff 0%, #d4ccf5 45%, #9b8ce8 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sub {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin: 4px 0 0;
}

.disc {
  color: var(--text-soft);
  font-size: 0.78rem;
  text-align: center;
  margin: 10px 0 14px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  display: inline-block;
  width: 100%;
  box-sizing: border-box;
}

nav {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  position: sticky;
  top: 8px;
  z-index: 20;
  padding: 5px;
  margin-bottom: 4px;
  border-radius: calc(var(--radius) + 2px);
  background: rgba(26, 26, 31, 0.72);
  border: 1px solid var(--border-strong);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

nav::-webkit-scrollbar {
  display: none;
}

nav button {
  margin: 0;
  flex: 1 0 auto;
  min-height: 40px;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  transition: color 0.2s, background 0.2s, box-shadow 0.2s, transform 0.15s;
}

nav button.on {
  background: linear-gradient(145deg, var(--accent-hover), var(--accent));
  color: #fff;
  box-shadow: 0 4px 14px var(--accent-glow);
}

nav button:not(.on):hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

nav button:active {
  transform: scale(0.97);
}

main {
  animation: fade-in 0.35s ease;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  main {
    animation: none;
  }

  nav button:active,
  .card:active,
  #send:active:not(:disabled) {
    transform: none;
  }
}

#q,
#apiurl {
  padding: 12px 16px;
  width: 100%;
  font-size: 16px;
  min-height: var(--tap);
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: rgba(30, 30, 36, 0.6);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  transition: border-color 0.2s, box-shadow 0.2s;
}

#q:focus,
#apiurl:focus {
  border-color: rgba(109, 91, 208, 0.5);
  box-shadow: 0 0 0 3px rgba(109, 91, 208, 0.15);
}

#tab-shelf {
  margin-top: 8px;
}

#cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.card {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-height: var(--tap);
  background: linear-gradient(165deg, rgba(38, 38, 46, 0.9), rgba(28, 28, 34, 0.95));
  color: inherit;
  cursor: pointer;
  font: inherit;
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}

.card:hover {
  border-color: rgba(109, 91, 208, 0.45);
  box-shadow: var(--shadow-md), 0 0 0 1px rgba(109, 91, 208, 0.12);
  transform: translateY(-2px);
}

.card:active {
  transform: translateY(0);
}

.card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card-name {
  font-size: 1.08rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 8px;
}

.tag {
  font-size: 0.72rem;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  border: 1px solid var(--border);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-job {
  flex: 1;
  min-width: 0;
}

.tag-pers {
  white-space: normal;
  line-height: 1.35;
  background: rgba(109, 91, 208, 0.12);
  border-color: rgba(109, 91, 208, 0.25);
  color: #c4baf0;
}

.card-starter {
  font-size: 0.84rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#tab-chat {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 148px);
  padding-bottom: 4px;
}

#who {
  color: var(--text-muted);
  margin: 8px 0 10px;
  font-size: 0.875rem;
  flex-shrink: 0;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
}

#log {
  flex: 1;
  min-height: 200px;
  max-height: none;
  overflow: auto;
  padding: 12px 8px 16px;
  margin: 0;
  border-radius: var(--radius);
  background: rgba(20, 20, 24, 0.5);
  border: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}

.msg {
  margin: 10px 0;
  padding: 11px 15px;
  border-radius: 18px;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: min(90%, 28rem);
  line-height: 1.6;
  font-size: 0.9375rem;
}

.msg.user {
  background: linear-gradient(145deg, #7a6ae8, var(--accent));
  color: #fff;
  margin-left: auto;
  text-align: left;
  border-bottom-right-radius: 6px;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.msg.assistant {
  background: var(--surface-2);
  color: var(--text);
  margin-right: auto;
  border-bottom-left-radius: 6px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.msg.loading {
  color: var(--text-muted);
  font-style: italic;
  background: transparent;
  border: 1px dashed var(--border);
  box-shadow: none;
}

.msg.error {
  border: 1px solid rgba(240, 136, 136, 0.35);
  background: rgba(42, 28, 32, 0.8);
}

.msg .narration {
  color: var(--text-soft);
  font-style: italic;
}

.retry-btn {
  margin-top: 10px;
  min-height: 36px;
  padding: 7px 16px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: border-color 0.2s, background 0.2s;
}

.retry-btn:hover {
  border-color: var(--accent);
  background: rgba(109, 91, 208, 0.15);
  color: #ddd6ff;
}

#sendrow {
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 15;
  padding: 12px 0 max(12px, env(safe-area-inset-bottom));
}

body.tab-chat-active #tab-chat {
  padding-bottom: 96px;
}

body.tab-chat-active #sendrow {
  position: fixed;
  left: 0;
  right: 0;
  max-width: 820px;
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
}

.send-inner {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 6px 6px 18px;
  border-radius: 999px;
  background: rgba(26, 26, 31, 0.88);
  border: 1px solid var(--border-strong);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-md);
}

#msg {
  flex: 1;
  padding: 10px 0;
  border-radius: 0;
  font-size: 16px;
  min-height: 32px;
  line-height: 1.45;
  resize: none;
  border: none;
  background: transparent;
  box-shadow: none;
}

#msg:focus {
  outline: none;
  border: none;
  box-shadow: none;
}

#send {
  flex-shrink: 0;
  background: linear-gradient(145deg, var(--accent-hover), var(--accent));
  color: #fff;
  border: none;
  border-radius: 50%;
  width: var(--tap);
  height: var(--tap);
  font-size: 1.15em;
  cursor: pointer;
  box-shadow: 0 4px 14px var(--accent-glow);
  transition: transform 0.15s, box-shadow 0.2s, opacity 0.15s;
}

#send:hover:not(:disabled) {
  box-shadow: 0 6px 20px rgba(109, 91, 208, 0.45);
}

#send:active:not(:disabled) {
  transform: scale(0.94);
}

#send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.msg-count {
  display: block;
  text-align: right;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-soft);
  margin-top: 6px;
  padding-right: 8px;
  font-variant-numeric: tabular-nums;
}

.msg-count.near-limit {
  color: var(--danger);
}

input,
textarea,
select {
  font-size: 16px;
  background: rgba(30, 30, 36, 0.7);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: rgba(109, 91, 208, 0.55);
  box-shadow: 0 0 0 3px rgba(109, 91, 208, 0.18);
}

#tab-post h3 {
  margin: 24px 0 12px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-soft);
}

#tab-post h3:first-child {
  margin-top: 8px;
}

#tab-post label {
  display: block;
  margin: 12px 0;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
}

#tab-post input,
#tab-post textarea,
#tab-post select {
  width: 100%;
  padding: 12px 14px;
  margin-top: 6px;
}

#tab-post .row {
  display: flex;
  gap: 10px;
}

#tab-post .row label {
  flex: 1;
}

.post-warn {
  margin: 14px 0 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(60, 45, 30, 0.5);
  border: 1px solid rgba(230, 180, 120, 0.25);
  color: #f0d4b0;
  font-size: 0.875rem;
}

.post-warn:empty,
.post-warn[hidden] {
  display: none;
}

.btn-secondary,
#postbtn,
#saveapi {
  min-height: var(--tap);
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 22px;
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 600;
  margin-top: 10px;
  margin-right: 8px;
  transition: transform 0.15s, box-shadow 0.2s, filter 0.2s;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

#postbtn,
#saveapi {
  background: linear-gradient(145deg, var(--accent-hover), var(--accent));
  color: #fff;
  box-shadow: 0 4px 16px var(--accent-glow);
}

#postbtn:hover,
#saveapi:hover,
.btn-secondary:hover {
  filter: brightness(1.08);
}

#postbtn:active,
#saveapi:active,
.btn-secondary:active {
  transform: scale(0.98);
}

#postmsg {
  margin-top: 10px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.post-preview {
  margin: 14px 0;
  padding: 14px;
  border: 1px dashed rgba(109, 91, 208, 0.35);
  border-radius: var(--radius);
  background: rgba(109, 91, 208, 0.06);
}

.preview-label {
  margin: 0 0 12px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.card-preview {
  pointer-events: none;
}

#tab-conn p {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

#tos {
  font-size: 0.85em;
  color: var(--text-muted);
}

@media (min-width: 640px) {
  body.tab-chat-active #sendrow {
    position: sticky;
  }

  #tab-chat {
    min-height: 60vh;
  }

  nav button {
    flex: 1;
  }
}
#chatbtns{margin:4px 0}#chatbtns button{margin-right:6px;padding:6px 12px;border:1px solid #444;background:#222;color:#e8e8ea;border-radius:8px;cursor:pointer}.card-head{display:flex;justify-content:space-between;align-items:center}.card-chats{font-size:.8em;color:#999}

/* ---- visual polish: avatars, motion, accents ---- */
.avatar{display:inline-flex;align-items:center;justify-content:center;flex-shrink:0;width:38px;height:38px;border-radius:50%;font-weight:700;font-size:1.05rem;color:#fff;background:linear-gradient(145deg,var(--accent-hover),var(--accent-pressed));box-shadow:0 3px 10px var(--accent-glow);margin-right:10px}
.avatar-sm{width:30px;height:30px;font-size:.9rem;margin-right:10px;margin-top:2px}
.card{position:relative;overflow:hidden}
.card::before{content:"";position:absolute;top:0;left:0;right:0;height:3px;background:linear-gradient(90deg,var(--accent),transparent 70%);opacity:.7}
.card-head{gap:8px}
.card-head .card-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.msg{animation:msg-in .25s ease}
@keyframes msg-in{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}
.msg.assistant{display:flex;align-items:flex-start}
.msg.assistant .msg-body{flex:1;min-width:0}
.typing{display:inline-flex;gap:5px;padding:6px 2px}
.typing span{width:7px;height:7px;border-radius:50%;background:var(--text-muted);animation:blink 1.2s infinite}
.typing span:nth-child(2){animation-delay:.2s}
.typing span:nth-child(3){animation-delay:.4s}
@keyframes blink{0%,60%,100%{opacity:.25}30%{opacity:1}}
@media (prefers-reduced-motion: reduce){.msg{animation:none}.typing span{animation:none}}

/* ---- usability pass: status, skeleton, empty, copy ---- */
.status{font-size:.8em;padding:2px 10px;border-radius:999px;margin-left:6px}
.status.checking{background:rgba(255,255,255,.06);color:var(--text-muted)}
.status.online{background:rgba(80,200,120,.15);color:#7ddba0}
.status.offline{background:rgba(240,136,136,.15);color:var(--danger)}
.count{color:var(--text-soft);font-size:.8em;margin:6px 0 0}
.card.skeleton{pointer-events:none;min-height:120px}
.sk{height:100%;min-height:104px;border-radius:8px;background:linear-gradient(100deg,rgba(255,255,255,.04) 40%,rgba(255,255,255,.1) 50%,rgba(255,255,255,.04) 60%);background-size:200% 100%;animation:shimmer 1.4s infinite}
@keyframes shimmer{to{background-position:-200% 0}}
.empty{grid-column:1/-1;text-align:center;color:var(--text-muted);padding:32px 12px;border:1px dashed var(--border-strong);border-radius:var(--radius)}
.empty .btn-secondary{margin-top:10px}
#who{display:flex;align-items:center;gap:8px}
.copy-btn{margin-left:8px;background:transparent;border:none;cursor:pointer;opacity:.45;font-size:.85em;padding:2px}
.copy-btn:hover{opacity:1}
#chatbtns #back{border-color:var(--accent)}
@media (prefers-reduced-motion: reduce){.sk{animation:none}}
