:root {
  color-scheme: dark;
  --bg: #05070d;
  --text: rgba(244, 247, 255, 0.95);
  --muted: rgba(230, 238, 255, 0.55);
  --faint: rgba(230, 238, 255, 0.32);
  --accent: #8ab8ff;
  --danger: #fca5a5;

  --glass: rgba(255, 255, 255, 0.05);
  --glass-strong: rgba(255, 255, 255, 0.09);
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.1);
  --glass-blur: blur(28px) saturate(170%);
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.35);

  --radius: 20px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

::selection { background: rgba(138, 184, 255, 0.3); }

button { font-family: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid rgba(138, 184, 255, 0.6);
  outline-offset: 2px;
}

/* Ambient background */
.bg-orbs {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(59, 91, 219, 0.12), transparent),
    var(--bg);
}
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.5;
}
.orb-1 {
  width: 620px; height: 620px;
  top: -220px; left: -160px;
  background: radial-gradient(circle at 35% 35%, #2f5fd6, transparent 68%);
  animation: drift-1 30s ease-in-out infinite alternate;
}
.orb-2 {
  width: 540px; height: 540px;
  bottom: -200px; right: -140px;
  background: radial-gradient(circle at 40% 40%, #6d4fc4, transparent 68%);
  animation: drift-2 36s ease-in-out infinite alternate;
}
.orb-3 {
  width: 420px; height: 420px;
  top: 40%; left: 55%;
  background: radial-gradient(circle at 50% 50%, #1f7f8f, transparent 68%);
  opacity: 0.32;
  animation: drift-3 42s ease-in-out infinite alternate;
}
@keyframes drift-1 { to { transform: translate(90px, 70px) scale(1.1); } }
@keyframes drift-2 { to { transform: translate(-80px, -60px) scale(1.08); } }
@keyframes drift-3 { to { transform: translate(-110px, 50px) scale(0.92); } }
@media (prefers-reduced-motion: reduce) {
  .orb { animation: none; }
  * { transition: none !important; }
}

/* Shared glass surface */
.home-header, .feature-card, .auth-card, .sidebar, .main, .chat-form {
  background: var(--glass);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow), var(--glass-highlight);
}

.text-gradient {
  background: linear-gradient(115deg, #a5c8ff 10%, #c9b8ff 55%, #8fe3f2 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* Home screen */
.home-screen {
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.home-header {
  position: sticky;
  top: 16px;
  z-index: 50;
  width: calc(100% - 48px);
  max-width: 960px;
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 10px 24px;
  border-radius: 999px;
}
.home-header-logo {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.home-header-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}
.nav-link-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  padding: 8px 14px;
  border-radius: 999px;
  transition: color 0.2s, background 0.2s;
}
.nav-link-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.nav-cta-btn {
  background: rgba(255, 255, 255, 0.92);
  color: #0b0e18;
  border: none;
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}
.nav-cta-btn:hover {
  background: #fff;
  transform: translateY(-1px);
  box-shadow: 0 8px 28px rgba(165, 200, 255, 0.25);
}
.nav-cta-btn:active { transform: translateY(0); }
.nav-cta-btn.large { padding: 14px 32px; font-size: 15px; }

.hero {
  width: 100%;
  max-width: 760px;
  text-align: center;
  padding: 110px 24px 70px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.hero-badge {
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0.2px;
  color: var(--muted);
  padding: 7px 16px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-highlight);
}
.hero-title {
  font-size: 52px;
  font-weight: 700;
  line-height: 1.18;
  margin: 0;
  letter-spacing: -1.5px;
}
.hero-sub {
  margin: 0;
  color: var(--muted);
  font-size: 17px;
  font-weight: 400;
  max-width: 480px;
  line-height: 1.65;
}
.home-actions { margin-top: 14px; }

.features {
  width: 100%;
  max-width: 960px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  padding: 0 24px 100px;
}
.feature-card {
  border-radius: var(--radius);
  padding: 26px 24px;
  text-align: left;
  transition: transform 0.25s, background 0.25s, border-color 0.25s;
}
.feature-card:hover {
  transform: translateY(-3px);
  background: var(--glass-strong);
  border-color: rgba(255, 255, 255, 0.16);
}
.feature-icon {
  font-size: 20px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-highlight);
  margin-bottom: 16px;
}
.feature-card h3 { margin: 0 0 6px; font-size: 15px; font-weight: 600; }
.feature-card p { margin: 0; font-size: 13.5px; color: var(--muted); line-height: 1.6; }

@media (max-width: 720px) {
  .features { grid-template-columns: 1fr; }
  .hero { padding-top: 80px; }
  .hero-title { font-size: 36px; letter-spacing: -1px; }
}

/* Auth screen */
.auth-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  border-radius: 24px;
  padding: 32px;
  width: 360px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.auth-card h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.auth-sub { margin: 0 0 12px; color: var(--muted); font-size: 13.5px; }
.auth-card input {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.auth-card input::placeholder { color: var(--faint); }
.auth-card input:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(138, 184, 255, 0.5);
  box-shadow: 0 0 0 4px rgba(138, 184, 255, 0.12);
}
.auth-actions { display: flex; gap: 10px; margin-top: 6px; }
.auth-actions button {
  flex: 1;
  padding: 11px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
}
#login-btn {
  background: rgba(255, 255, 255, 0.92);
  color: #0b0e18;
}
#login-btn:hover {
  background: #fff;
  transform: translateY(-1px);
  box-shadow: 0 8px 28px rgba(165, 200, 255, 0.25);
}
#register-btn {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-highlight);
}
#register-btn:hover { background: rgba(255, 255, 255, 0.11); }
.oauth-section { display: flex; flex-direction: column; gap: 12px; }
.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--faint);
  font-size: 12px;
  margin-top: 2px;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--glass-border);
}
.oauth-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 11px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--glass-highlight);
  transition: background 0.2s;
}
.oauth-btn:hover { background: rgba(255, 255, 255, 0.11); }
.oauth-btn svg { color: #f97b3d; }
.auth-error { color: var(--danger); font-size: 13px; min-height: 16px; margin: 0; }
.back-link {
  background: none;
  border: none;
  color: var(--faint);
  font-size: 13px;
  cursor: pointer;
  padding: 0;
  text-align: left;
  margin-bottom: 6px;
  transition: color 0.2s;
}
.back-link:hover { color: var(--text); }

/* App layout */
.app {
  display: flex;
  height: 100vh;
  padding: 14px;
  gap: 14px;
}
.sidebar {
  width: 264px;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 10px;
}
.new-chat-btn {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 10px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--glass-highlight);
  transition: background 0.2s;
}
.new-chat-btn:hover { background: rgba(255, 255, 255, 0.11); }
.settings-open-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: none;
  color: var(--faint);
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.2s, color 0.2s;
}
.settings-open-btn:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.conversation-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 4px -4px;
  padding: 0 4px;
}
.conversation-item {
  padding: 9px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  transition: background 0.15s, color 0.15s;
}
.conversation-item > span:first-child { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.conversation-item:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.conversation-item.active {
  background: rgba(255, 255, 255, 0.09);
  color: var(--text);
  box-shadow: var(--glass-highlight);
}
.conversation-item .del {
  font-size: 11px;
  color: var(--faint);
  transition: opacity 0.15s, color 0.15s;
}
.conversation-item .del:hover { color: var(--danger); }
/* Hover-to-reveal only on pointers that actually support hover (mouse/trackpad);
   touch devices get no hover event, so keep the delete button visible there
   instead of making it unreachable. */
@media (hover: hover) {
  .conversation-item .del { opacity: 0; }
  .conversation-item:hover .del { opacity: 1; }
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.03);
  overflow: hidden;
}
/* Context usage bar: how much of the model's context window this conversation
   has used, with a one-click /compact action once it's getting full. */
.context-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px 0;
  flex-shrink: 0;
}
.context-bar { position: relative; }
.context-bar-track {
  flex: 1;
  max-width: 220px;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  display: flex;
}
.context-seg { height: 100%; width: 0%; transition: width 0.4s ease; }
.seg-system { background: #c9b8ff; }
.seg-tools { background: #8fe3f2; }
.seg-messages { background: var(--accent); }
.seg-free { background: rgba(255, 255, 255, 0.18); }
.context-bar.warn .seg-messages { background: #f5b563; }
.context-bar.critical .seg-messages { background: var(--danger); }

/* Hover breakdown popover: what is taking up the context window */
.context-pop {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 20px;
  z-index: 30;
  min-width: 210px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(18, 22, 34, 0.95);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
}
.context-bar:hover .context-pop { display: block; }
.pop-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  padding: 3px 0;
  font-variant-numeric: tabular-nums;
}
.pop-row b { margin-left: auto; color: var(--text); font-weight: 600; }
.pop-row.pop-free { border-top: 1px solid var(--glass-border); margin-top: 4px; padding-top: 7px; }
.pop-dot {
  width: 8px;
  height: 8px;
  border-radius: 3px;
  flex-shrink: 0;
}
.context-bar-label {
  font-size: 11px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.context-bar.warn .context-bar-label { color: #f5b563; }
.context-bar.critical .context-bar-label { color: var(--danger); }
.compact-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  background: none;
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.compact-btn:hover { background: rgba(255, 255, 255, 0.07); color: var(--text); }
.compact-btn:disabled { opacity: 0.35; cursor: default; }
.context-bar.critical .compact-btn {
  border-color: rgba(252, 165, 165, 0.4);
  color: var(--danger);
  animation: compact-pulse 1.6s ease-in-out infinite;
}
@keyframes compact-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(252, 165, 165, 0.35); }
  50% { box-shadow: 0 0 0 5px rgba(252, 165, 165, 0); }
}

/* Compact summary bubble replacing the old transcript after /compact */
.compact-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--accent);
  margin-bottom: 6px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px 12px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.msg {
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  animation: msg-in 0.3s ease;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
}
.msg-role {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 6px;
}
.msg-user { align-items: flex-end; }
.msg-user .msg-role { display: none; }
.msg-content { line-height: 1.65; font-size: 14.5px; min-width: 0; }
.msg-user .msg-content {
  max-width: 78%;
  background: rgba(138, 184, 255, 0.1);
  border: 1px solid rgba(138, 184, 255, 0.18);
  border-radius: 18px 18px 6px 18px;
  padding: 11px 16px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.msg-content p { margin: 0 0 10px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content pre {
  background: rgba(2, 4, 10, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 14px 16px;
  overflow-x: auto;
}
.msg-content code { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 13px; }
.msg-content pre code { background: transparent; padding: 0; }
.msg-content p code, .msg-content li code {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 6px;
}
/* Inline tool call card (rendered at the point the tool was invoked) */
.tool-call {
  margin: 10px 0;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.035);
  width: fit-content;
  min-width: 280px;
  max-width: 100%;
  overflow: hidden;
  transition: border-color 0.2s, background 0.2s;
}
.tool-call:hover { border-color: rgba(255, 255, 255, 0.13); }
.tool-call.running {
  border-color: rgba(138, 184, 255, 0.25);
  background: rgba(138, 184, 255, 0.05);
}
.tool-call summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 8px 8px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.tool-call summary::-webkit-details-marker { display: none; }
.tc-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  background: rgba(138, 184, 255, 0.12);
  color: var(--accent);
}
.tc-icon svg { width: 14px; height: 14px; }
.tool-call.running .tc-icon { animation: tc-glow 1.4s ease-in-out infinite; }
@keyframes tc-glow {
  0%, 100% { background: rgba(138, 184, 255, 0.12); }
  50% { background: rgba(138, 184, 255, 0.28); }
}
.tool-call.aborted .tc-icon {
  background: rgba(252, 165, 165, 0.12);
  color: var(--danger);
}
.tc-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.tc-preview {
  font-size: 12px;
  color: var(--faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 260px;
}
.tc-preview:not(:empty)::before { content: '·'; margin-right: 8px; opacity: 0.6; }
.tc-status {
  margin-left: auto;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  color: var(--accent);
}
.tc-status svg { width: 13px; height: 13px; }
.tool-call.aborted .tc-status { color: var(--danger); }
.tc-chev {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  color: var(--faint);
  transition: transform 0.25s;
}
.tc-chev svg { width: 13px; height: 13px; }
.tool-call[open] .tc-chev { transform: rotate(180deg); }
.tool-spin {
  width: 11px;
  height: 11px;
  flex-shrink: 0;
  border: 1.5px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: tool-spin 0.8s linear infinite;
}
@keyframes tool-spin { to { transform: rotate(360deg); } }
/* 생각(reasoning) 카드 — 툴 카드 골격을 공유하고 보라 계열로만 구분한다 */
.thinking-block.running {
  border-color: rgba(196, 167, 255, 0.25);
  background: rgba(196, 167, 255, 0.05);
}
.thinking-block .tc-icon { background: rgba(196, 167, 255, 0.12); color: #c8b1ff; }
.thinking-block.running .tc-icon { animation: think-glow 1.4s ease-in-out infinite; }
@keyframes think-glow {
  0%, 100% { background: rgba(196, 167, 255, 0.12); }
  50% { background: rgba(196, 167, 255, 0.3); }
}
.thinking-block .tc-status { color: #c8b1ff; }
.thinking-block .tool-spin { border-top-color: #c8b1ff; }
.tool-body {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(2, 4, 10, 0.25);
}
.msg-content .tool-body pre {
  margin: 0;
  padding: 0;
  background: none;
  border: none;
  border-radius: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  color: var(--muted);
  max-height: 240px;
  overflow-y: auto;
}
.tool-args::before, .tool-result::before {
  display: block;
  content: '입력';
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.6px;
  color: var(--faint);
  margin-bottom: 4px;
}
.tool-result::before { content: '결과'; }

/* Per-message generation stats (tps/tokens) — only ever shown under the
   single most recent assistant message, never accumulated across history. */
.msg-stats {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
  font-size: 11px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  animation: msg-in 0.3s ease;
}
.msg-stats .dot { opacity: 0.5; }

/* Streaming status (생각 중 / 도구 실행 중) */
.status-note {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  padding: 4px 0;
  animation: msg-in 0.3s ease;
}
.status-dots { display: inline-flex; gap: 3px; }
.status-dots span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  animation: dot-pulse 1.2s infinite ease-in-out;
}
.status-dots span:nth-child(2) { animation-delay: 0.2s; }
.status-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-pulse {
  0%, 60%, 100% { opacity: 0.25; transform: scale(0.85); }
  30% { opacity: 1; transform: scale(1); }
}

/* Empty new-chat state */
.empty-hint {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  animation: msg-in 0.3s ease;
}
.empty-hint h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.4px;
}
.empty-hint p { margin: 0; font-size: 13.5px; color: var(--faint); }

/* Attached images inside messages */
.msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.msg-images img {
  max-width: 220px;
  max-height: 220px;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  display: block;
  cursor: zoom-in;
}
.msg-content:not(:has(.msg-md:not(:empty))) .msg-images { margin-bottom: 0; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  cursor: zoom-out;
  animation: msg-in 0.2s ease;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.ask-card {
  background: rgba(138, 184, 255, 0.06);
  border: 1px solid rgba(138, 184, 255, 0.22);
  border-radius: 16px;
  padding: 14px;
  margin: 12px 0 4px;
  max-width: 420px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  animation: msg-in 0.3s ease;
}
.ask-head {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 0 2px 12px;
}
.ask-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(138, 184, 255, 0.18);
  color: var(--accent);
  margin-top: 1px;
}
.ask-question { font-size: 14px; font-weight: 600; line-height: 1.5; }

/* Vertical, radio-style option list — reads better than pills once labels
   get longer or there are more than a couple of choices. */
.ask-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ask-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.ask-option:hover { background: rgba(138, 184, 255, 0.12); border-color: rgba(138, 184, 255, 0.35); }
.ask-option:active { transform: scale(0.99); }
.ask-option-dot {
  flex-shrink: 0;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 1.5px solid var(--faint);
  transition: border-color 0.15s, background 0.15s;
  position: relative;
}
.ask-option-dot::after {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: var(--accent);
  transform: scale(0);
  transition: transform 0.15s;
}
.ask-option:hover .ask-option-dot { border-color: rgba(138, 184, 255, 0.6); }
.ask-option-label { flex: 1; min-width: 0; }

.ask-card.answered .ask-option { opacity: 0.4; pointer-events: none; }
.ask-card.answered .ask-option.chosen {
  opacity: 1;
  background: rgba(138, 184, 255, 0.14);
  border-color: rgba(138, 184, 255, 0.5);
}
.ask-card.answered .ask-option.chosen .ask-option-dot { border-color: var(--accent); }
.ask-card.answered .ask-option.chosen .ask-option-dot::after { transform: scale(1); }

.ask-hint {
  font-size: 11.5px;
  color: var(--faint);
  margin: -6px 0 10px 2px;
}

/* Multi-select: checkbox-shaped indicator instead of a radio dot, options stay
   toggleable until the user hits "선택 완료" (single-select still auto-submits). */
.ask-multi .ask-option-dot { border-radius: 5px; }
.ask-multi .ask-option-dot::after { border-radius: 2px; inset: 4px; }
.ask-multi .ask-option:disabled { cursor: default; }
.ask-multi .ask-option.at-limit { opacity: 0.45; }
.ask-multi .ask-option.chosen {
  background: rgba(138, 184, 255, 0.14);
  border-color: rgba(138, 184, 255, 0.5);
}
.ask-multi .ask-option.chosen .ask-option-dot { border-color: var(--accent); }
.ask-multi .ask-option.chosen .ask-option-dot::after { transform: scale(1); }
.ask-card.answered.ask-multi .ask-option:not(.chosen) { opacity: 0.3; }

.ask-confirm {
  width: 100%;
  margin-top: 8px;
  padding: 9px;
  border-radius: 12px;
  border: none;
  background: rgba(255, 255, 255, 0.92);
  color: #0b0e18;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s, transform 0.15s;
}
.ask-confirm:hover:not(:disabled) { background: #fff; }
.ask-confirm:active:not(:disabled) { transform: scale(0.99); }
.ask-confirm:disabled { opacity: 0.3; cursor: default; }
.ask-card.answered .ask-confirm { display: none; }

.chat-form {
  display: flex;
  flex-direction: column;
  padding: 8px;
  margin: 8px auto 20px;
  width: calc(100% - 48px);
  max-width: 720px;
  border-radius: 26px;
  background: var(--glass-strong);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.chat-form:focus-within {
  border-color: rgba(138, 184, 255, 0.4);
  box-shadow: var(--shadow), var(--glass-highlight), 0 0 0 4px rgba(138, 184, 255, 0.1);
}
.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.chat-form textarea {
  flex: 1;
  resize: none;
  background: none;
  border: none;
  color: var(--text);
  padding: 10px 0;
  font-size: 14.5px;
  font-family: inherit;
  line-height: 1.5;
  max-height: 200px;
}
.chat-form textarea::placeholder { color: var(--faint); }
.chat-form textarea:focus { outline: none; }
.attach-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  color: var(--muted);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.attach-btn:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }
/* Think effort 선택 (모델이 답하기 전 생각하는 깊이) */
.think-effort {
  flex-shrink: 0;
  align-self: flex-end;
  height: 40px;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid transparent;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.04) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='rgba(230,238,255,0.45)' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right 11px center / 10px;
  color: var(--muted);
  font-size: 12.5px;
  font-family: inherit;
  padding: 0 27px 0 14px;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
  color-scheme: dark;
}
.think-effort:hover { background-color: rgba(255, 255, 255, 0.08); color: var(--text); }
.think-effort:focus { outline: none; border-color: rgba(138, 184, 255, 0.4); }
.think-effort option { background: #0b0e18; color: var(--text); }
.send-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.92);
  color: #0b0e18;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s, opacity 0.2s;
}
.send-btn:hover { background: #fff; transform: scale(1.05); }
.send-btn:disabled { opacity: 0.35; cursor: default; transform: none; }

/* Pending image previews in the composer */
.image-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 8px 10px;
}
.image-preview {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--glass-border);
}
.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.image-preview .remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  border: none;
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.image-preview .remove:hover { background: rgba(0, 0, 0, 0.85); }
.file-chip {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  font-size: 11px;
  line-height: 1.35;
  color: var(--text);
  background: linear-gradient(135deg, rgba(129, 140, 248, 0.28), rgba(45, 212, 191, 0.2));
  text-align: center;
  word-break: break-word;
  overflow: hidden;
}

@media (max-width: 720px) {
  .app { padding: 8px; gap: 8px; }
  .sidebar { width: 200px; }
  .chat-form { width: calc(100% - 24px); }
  .msg-user .msg-content { max-width: 92%; }
}

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 8px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.24); }

/* Suggestion chips on the empty new-chat screen */
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 540px;
  margin-top: 12px;
}
.suggestions-loading { font-size: 13px; color: var(--faint); }
.suggestion-chip {
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--glass-highlight);
  transition: background 0.2s, color 0.2s, border-color 0.2s, transform 0.2s;
  animation: msg-in 0.3s ease;
}
.suggestion-chip:hover {
  background: rgba(138, 184, 255, 0.12);
  border-color: rgba(138, 184, 255, 0.35);
  color: var(--text);
  transform: translateY(-1px);
}

/* Settings modal */
.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(2, 4, 10, 0.55);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: msg-in 0.2s ease;
}
.settings-modal {
  width: 560px;
  max-width: 100%;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  border-radius: 22px;
  background: rgba(16, 20, 32, 0.92);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow), var(--glass-highlight);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  overflow: hidden;
}
.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 0;
}
.settings-head h2 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -0.3px; }
.settings-close {
  background: none;
  border: none;
  color: var(--faint);
  font-size: 14px;
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  transition: background 0.2s, color 0.2s;
}
.settings-close:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }
.settings-tabs {
  display: flex;
  gap: 4px;
  padding: 14px 22px 0;
  border-bottom: 1px solid var(--glass-border);
}
.settings-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--faint);
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 12px 10px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.settings-tab:hover { color: var(--text); }
.settings-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.settings-page {
  padding: 18px 22px 22px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.settings-label { font-size: 13.5px; font-weight: 600; }
.settings-desc { margin: 0; font-size: 12.5px; color: var(--faint); line-height: 1.6; }
.settings-page textarea {
  width: 100%;
  resize: vertical;
  min-height: 110px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.6;
}
.settings-page textarea:focus,
.settings-page input:focus {
  outline: none;
  border-color: rgba(138, 184, 255, 0.5);
  box-shadow: 0 0 0 3px rgba(138, 184, 255, 0.12);
}
.settings-page input {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.settings-page input::placeholder, .settings-page textarea::placeholder { color: var(--faint); }
.settings-row-end { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.settings-status { font-size: 12px; color: var(--accent); }
.settings-primary {
  background: rgba(255, 255, 255, 0.92);
  color: #0b0e18;
  border: none;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}
.settings-primary:hover { background: #fff; }
.settings-primary:disabled { opacity: 0.4; cursor: default; }
.settings-danger {
  background: none;
  color: var(--danger);
  border: 1px solid rgba(252, 165, 165, 0.3);
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.settings-danger:hover { background: rgba(252, 165, 165, 0.1); }
.settings-divider { height: 1px; background: var(--glass-border); margin: 8px 0; }
.settings-email { font-size: 12.5px; color: var(--faint); }
.settings-empty { font-size: 12.5px; color: var(--faint); text-align: center; padding: 14px 0; }

/* Memory tab */
.memory-add { display: flex; gap: 8px; }
.memory-add input { flex: 1; }
.memory-list { display: flex; flex-direction: column; gap: 6px; }
.memory-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
}
.memory-text { flex: 1; font-size: 13px; line-height: 1.5; word-break: break-word; }
.memory-date { font-size: 11px; color: var(--faint); flex-shrink: 0; }
.memory-del {
  background: none;
  border: none;
  color: var(--faint);
  font-size: 11px;
  cursor: pointer;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.memory-del:hover { background: rgba(252, 165, 165, 0.12); color: var(--danger); }

/* MCP tab */
.mcp-add { display: flex; flex-direction: column; gap: 8px; }
.mcp-add .settings-primary { align-self: flex-end; }
.mcp-list { display: flex; flex-direction: column; gap: 6px; }
.mcp-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
}
.mcp-row.disabled { opacity: 0.5; }
.mcp-info { flex: 1; min-width: 0; }
.mcp-row-name { font-size: 13px; font-weight: 600; }
.mcp-row-url {
  font-size: 11.5px;
  color: var(--faint);
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mcp-test {
  background: none;
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11.5px;
  padding: 4px 10px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s, color 0.2s;
}
.mcp-test:hover { background: rgba(255, 255, 255, 0.07); color: var(--text); }
.mcp-toggle {
  width: 34px;
  height: 20px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  padding: 0;
  transition: background 0.2s, border-color 0.2s;
}
.mcp-toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--faint);
  transition: transform 0.2s, background 0.2s;
}
.mcp-toggle.on { background: rgba(138, 184, 255, 0.35); border-color: rgba(138, 184, 255, 0.5); }
.mcp-toggle.on .mcp-toggle-knob { transform: translateX(14px); background: #fff; }

/* Billing */
.billing-status {
  margin-bottom: 32px;
}
.billing-tier-card {
  background: var(--glass-strong);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 20px;
}
.tier-badge {
  display: inline-block;
  background: rgba(138, 184, 255, 0.2);
  border: 1px solid rgba(138, 184, 255, 0.5);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  color: #a5c8ff;
  margin-bottom: 12px;
}
.tier-expires {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}
.tier-limits {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.limit-row { }

.billing-plans h3, .billing-history h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 16px;
  color: var(--text);
}
.billing-plans {
  margin-bottom: 40px;
}
.plans-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}
.plan-card {
  background: var(--glass-strong);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 16px;
  transition: background 0.2s, border-color 0.2s;
}
.plan-card.active { background: rgba(138, 184, 255, 0.15); border-color: rgba(138, 184, 255, 0.5); }
.plan-card:hover:not(.active) { background: rgba(138, 184, 255, 0.08); }
.plan-name { font-weight: 600; font-size: 15px; margin-bottom: 8px; }
.plan-price { font-size: 18px; font-weight: 700; color: #a5c8ff; margin-bottom: 12px; }
.plan-features { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.plan-features div { margin-bottom: 4px; }
.plan-btn {
  width: 100%;
  padding: 8px;
  background: rgba(138, 184, 255, 0.2);
  border: 1px solid rgba(138, 184, 255, 0.5);
  border-radius: 6px;
  color: #a5c8ff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
.plan-btn:hover { background: rgba(138, 184, 255, 0.3); }

.billing-history { }
.payments-list { display: flex; flex-direction: column; gap: 8px; }
.payments-empty { font-size: 13px; color: var(--faint); padding: 20px; text-align: center; }
.payment-row {
  background: var(--glass-strong);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}
.payment-info { flex: 1; }
.payment-tier { font-weight: 500; }
.payment-date { font-size: 12px; color: var(--faint); }
.payment-amount { font-weight: 600; margin: 0 16px; }
.payment-status { font-size: 12px; color: var(--muted); }
.payment-pending { opacity: 0.6; }
.payment-paid { border-color: rgba(138, 200, 100, 0.3); }
.payment-failed { opacity: 0.5; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-card {
  background: var(--glass);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 400px;
  box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 8px; font-size: 18px; }
.modal-card p { margin: 0 0 20px; font-size: 13px; color: var(--muted); }
.checkout-method { margin-bottom: 20px; }
.checkout-method select {
  width: 100%;
  padding: 8px;
  background: var(--glass-strong);
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
}
.checkout-buttons { display: flex; gap: 8px; }
.checkout-buttons button {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  background: var(--glass-strong);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
.checkout-buttons button:hover { background: rgba(138, 184, 255, 0.2); }
.checkout-confirm { background: rgba(138, 184, 255, 0.2) !important; border-color: rgba(138, 184, 255, 0.5) !important; }

/* ---------- KaTeX (TeX math in assistant messages) ---------- */
.msg-content .katex { font-size: 1.05em; }
.msg-content .katex-display {
  margin: 0.6em 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 0;
}
.msg-content .katex-display > .katex { text-align: center; }
