:root {
  --bg: #03060c;
  --panel: rgba(6, 12, 22, .9);
  --panel-solid: #07101c;
  --line: rgba(111, 166, 207, .16);
  --line-hot: rgba(27, 207, 255, .45);
  --text: #f4f8fc;
  --muted: #8090a3;
  --cyan: #19d4ff;
  --blue: #2589ff;
  --green: #54edc0;
  --danger: #ff6384;
  --radius: 22px;
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  background:
    radial-gradient(circle at 58% 15%, rgba(0, 119, 190, .13), transparent 32%),
    radial-gradient(circle at 90% 90%, rgba(39, 77, 255, .08), transparent 30%),
    var(--bg);
  color: var(--text);
}
button, input, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  opacity: .8;
  pointer-events: none;
}
.cursor-orb {
  position: fixed;
  z-index: 1000;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(108, 236, 255, .9);
  background: rgba(26, 212, 255, .42);
  box-shadow: 0 0 18px rgba(25, 212, 255, .85);
  pointer-events: none;
  opacity: 0;
  transition: width .18s, height .18s, opacity .2s;
}
.cursor-orb.is-active { width: 24px; height: 24px; background: rgba(25, 212, 255, .12); }

.micro-label {
  margin: 0;
  color: var(--cyan);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .22em;
  text-transform: uppercase;
}

/* Access screen */
.connect-layer {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
}
.connect-card {
  position: relative;
  width: min(560px, 100%);
  padding: 50px;
  border: 1px solid var(--line);
  border-radius: 30px;
  background: linear-gradient(145deg, rgba(9, 19, 33, .94), rgba(3, 8, 16, .9));
  box-shadow: 0 35px 110px rgba(0, 0, 0, .55), inset 0 1px rgba(255, 255, 255, .03);
  overflow: hidden;
  animation: card-in .7s cubic-bezier(.16, 1, .3, 1);
}
.connect-card::before {
  content: "";
  position: absolute;
  width: 260px;
  height: 260px;
  right: -120px;
  top: -140px;
  border-radius: 50%;
  background: rgba(20, 201, 255, .12);
  filter: blur(20px);
}
.connect-signal {
  position: relative;
  display: grid;
  place-items: center;
  width: 78px;
  height: 78px;
  margin-bottom: 34px;
  border: 1px solid rgba(25, 212, 255, .24);
  border-radius: 24px;
  background: rgba(7, 25, 39, .8);
  box-shadow: 0 0 40px rgba(25, 212, 255, .11);
}
.connect-signal span { font-size: 22px; font-weight: 900; }
.connect-signal i {
  position: absolute;
  inset: -7px;
  border: 1px solid rgba(25, 212, 255, .12);
  border-radius: 28px;
  animation: pulse-ring 2.6s infinite;
}
.connect-signal i:nth-child(2) { inset: -15px; animation-delay: .8s; }
.connect-signal i:nth-child(3) { inset: -23px; animation-delay: 1.6s; }
.connect-card h1 {
  margin: 12px 0 18px;
  font-size: clamp(40px, 7vw, 62px);
  line-height: .96;
  letter-spacing: -.055em;
}
.connect-card h1 em { color: var(--cyan); font-style: normal; }
.connect-copy { max-width: 460px; color: var(--muted); font-size: 15px; line-height: 1.7; }
.connect-form { display: grid; gap: 11px; margin-top: 30px; }
.connect-form > label { color: #a8b6c8; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; }
.key-input { position: relative; }
.key-input input {
  width: 100%;
  height: 58px;
  padding: 0 54px 0 18px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(1, 7, 14, .8);
  color: white;
}
.key-input input:focus { border-color: var(--line-hot); }
.ghost-icon {
  position: absolute;
  right: 10px;
  top: 10px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.connect-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  margin-top: 5px;
  padding: 0 22px;
  border: 0;
  border-radius: 15px;
  background: linear-gradient(115deg, #11c8f5, #257cff);
  color: #00101a;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 14px 40px rgba(15, 157, 243, .25);
  transition: transform .2s, filter .2s;
}
.connect-button:hover { transform: translateY(-2px); filter: brightness(1.08); }
.connect-button:disabled { cursor: wait; opacity: .7; transform: none; }
.connect-error { color: #ff91a7; font-size: 13px; }
.trust-row { display: flex; flex-wrap: wrap; gap: 15px; margin-top: 22px; color: #607287; font-size: 11px; }
.trust-row span::before { content: "•"; margin-right: 7px; color: var(--green); }

/* Main application */
.workspace {
  display: grid;
  grid-template-columns: 334px minmax(0, 1fr);
  grid-template-rows: 76px minmax(0, 1fr);
  width: 100vw;
  height: 100dvh;
}
.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 334px 1fr auto;
  align-items: center;
  min-width: 0;
  border-bottom: 1px solid var(--line);
  background: rgba(3, 7, 13, .89);
  backdrop-filter: blur(22px);
  z-index: 30;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 100%;
  padding: 0 24px;
  color: white;
  text-decoration: none;
  border-right: 1px solid var(--line);
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(25, 212, 255, .5);
  border-radius: 11px;
  background: rgba(8, 30, 46, .8);
  color: var(--cyan);
  font-weight: 950;
}
.brand strong { display: block; font-size: 14px; letter-spacing: .12em; }
.brand small { display: block; margin-top: 2px; color: #547189; font-size: 8px; letter-spacing: .24em; }
.model-switcher { position: relative; justify-self: center; }
.model-button {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 220px;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(8, 17, 29, .82);
  cursor: pointer;
}
.model-button > span:nth-child(2) { display: grid; flex: 1; text-align: left; }
.model-button small { color: #688095; font-size: 9px; text-transform: uppercase; letter-spacing: .14em; }
.model-button strong { margin-top: 2px; font-size: 14px; }
.model-button > b { color: var(--cyan); transition: transform .2s; }
.model-button[aria-expanded="true"] > b { transform: rotate(180deg); }
.model-pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 14px var(--cyan); }
.model-popover {
  position: absolute;
  top: 56px;
  left: 50%;
  z-index: 60;
  width: 320px;
  padding: 8px;
  border: 1px solid rgba(68, 177, 238, .3);
  border-radius: 18px;
  background: rgba(5, 13, 24, .98);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .65);
  transform: translateX(-50%);
  animation: pop-in .18s ease-out;
}
.model-option {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.model-option:hover, .model-option.active { background: rgba(24, 179, 233, .1); }
.model-option .model-logo { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: #0a2337; color: var(--cyan); font-weight: 900; }
.model-option strong, .model-option small { display: block; }
.model-option small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.model-option > b { color: var(--cyan); }
.topbar-actions { display: flex; align-items: center; gap: 12px; padding-right: 18px; }
.quota-pill {
  display: flex;
  align-items: baseline;
  gap: 8px;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(8, 17, 29, .7);
}
.quota-pill span { color: #61768a; font-size: 8px; letter-spacing: .12em; }
.quota-pill strong { color: var(--cyan); font-family: ui-monospace, monospace; font-size: 13px; }
.disconnect, .mobile-menu, .delete-chat {
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: #9aabbc;
  cursor: pointer;
}
.disconnect:hover, .delete-chat:hover { border-color: rgba(255, 99, 132, .35); color: #ff8ba4; }
.mobile-menu { display: none; }

@media (min-width: 861px) {
  .topbar-actions { transform: translateY(8px); }
}

/* History */
.history-panel {
  grid-row: 2;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 26px 20px 18px;
  border-right: 1px solid var(--line);
  background: rgba(3, 9, 17, .75);
  backdrop-filter: blur(16px);
  z-index: 25;
}
.history-head { display: flex; align-items: center; justify-content: space-between; }
.history-head h2 { margin: 5px 0 0; font-size: 28px; letter-spacing: -.04em; }
.panel-close { display: none; border: 0; background: transparent; color: var(--muted); font-size: 28px; cursor: pointer; }
.new-chat {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 52px;
  margin-top: 24px;
  padding: 0 16px;
  border: 1px solid rgba(25, 212, 255, .32);
  border-radius: 14px;
  background: rgba(10, 54, 75, .18);
  font-weight: 800;
  cursor: pointer;
}
.new-chat span { color: var(--cyan); font-size: 22px; }
.search-box {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 42px;
  margin: 12px 0;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(1, 7, 14, .5);
}
.search-box span { color: #65829a; }
.search-box input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; color: white; font-size: 13px; }
.thread-list { min-height: 0; overflow: auto; scrollbar-width: thin; scrollbar-color: #17445d transparent; }
.thread-item {
  position: relative;
  display: grid;
  width: 100%;
  margin: 5px 0;
  padding: 13px 42px 13px 14px;
  border: 1px solid transparent;
  border-radius: 13px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.thread-item:hover { background: rgba(14, 36, 54, .45); }
.thread-item.active { border-color: rgba(25, 212, 255, .22); background: rgba(12, 48, 67, .48); }
.thread-item.active::before { content: ""; position: absolute; left: -1px; top: 14px; bottom: 14px; width: 2px; background: var(--cyan); box-shadow: 0 0 10px var(--cyan); }
.thread-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.thread-item small { margin-top: 5px; color: #667b8d; font-size: 10px; }
.thread-delete {
  position: absolute;
  right: 8px;
  top: 12px;
  width: 29px;
  height: 29px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #667b8d;
  opacity: 0;
  cursor: pointer;
}
.thread-item:hover .thread-delete, .thread-item.active .thread-delete { opacity: 1; }
.thread-delete:hover { background: rgba(255, 93, 126, .1); color: var(--danger); }
.retention-note { display: flex; gap: 10px; padding: 15px 8px 0; border-top: 1px solid var(--line); }
.retention-note i { width: 8px; height: 8px; margin-top: 4px; border-radius: 50%; background: var(--green); box-shadow: 0 0 12px var(--green); }
.retention-note p { margin: 0; }
.retention-note strong, .retention-note span { display: block; font-size: 11px; }
.retention-note span { margin-top: 4px; color: #536b7e; line-height: 1.45; }
.panel-scrim { display: none; }

/* Chat */
.chat-stage {
  grid-column: 2;
  grid-row: 2;
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 70px minmax(0, 1fr) auto;
  overflow: hidden;
}
.chat-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image: linear-gradient(rgba(65, 126, 164, .035) 1px, transparent 1px), linear-gradient(90deg, rgba(65, 126, 164, .035) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: linear-gradient(to bottom, transparent, black 15%, black 85%, transparent);
}
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(20px, 4vw, 56px);
  border-bottom: 1px solid rgba(111, 166, 207, .08);
}
.chat-head h1 { max-width: 52vw; margin: 3px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 18px; letter-spacing: -.02em; }
.delete-chat { height: 34px; font-size: 11px; }
.messages {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 30px max(20px, calc((100% - 920px) / 2)) 150px;
  scrollbar-width: thin;
  scrollbar-color: #15445d transparent;
}
.empty-chat {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 30px 0 80px;
  text-align: center;
  animation: rise .55s ease-out;
}
.core-visual { position: relative; display: grid; place-items: center; width: 108px; height: 108px; margin-bottom: 25px; }
.core-ring { position: absolute; inset: 8px; border: 1px solid rgba(25, 212, 255, .23); border-radius: 36%; animation: orbit 9s linear infinite; }
.core-ring.ring-two { inset: 20px; border-radius: 50%; animation-direction: reverse; animation-duration: 6s; }
.core-dot { position: absolute; width: 16px; height: 16px; border-radius: 50%; background: var(--cyan); filter: blur(1px); box-shadow: 0 0 28px var(--cyan); }
.core-visual b { position: relative; z-index: 1; color: #00121c; font-size: 10px; }
.empty-chat h2 { margin: 9px 0 12px; font-size: clamp(34px, 5vw, 56px); letter-spacing: -.055em; }
.empty-chat h2 em { color: var(--cyan); font-style: normal; }
.empty-chat > p:not(.micro-label) { max-width: 590px; margin: 0; color: var(--muted); line-height: 1.65; }
.starter-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: min(700px, 100%); margin-top: 28px; }
.starter-grid button {
  display: grid;
  min-height: 92px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(8, 18, 30, .62);
  text-align: left;
  cursor: pointer;
  transition: transform .2s, border-color .2s, background .2s;
}
.starter-grid button:hover { transform: translateY(-3px); border-color: var(--line-hot); background: rgba(10, 33, 48, .78); }
.starter-grid b { color: var(--cyan); font: 10px ui-monospace, monospace; }
.starter-grid span { align-self: end; font-size: 13px; font-weight: 750; }

.message {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 15px;
  max-width: 920px;
  margin: 0 auto 34px;
  animation: rise .3s ease-out;
}
.message-node { display: grid; place-items: center; width: 34px; height: 34px; margin-top: 2px; border: 1px solid var(--line); border-radius: 10px; color: #7e94a7; font-size: 10px; font-weight: 900; }
.message.assistant .message-node { border-color: rgba(25, 212, 255, .4); background: rgba(9, 55, 75, .34); color: var(--cyan); }
.message-body { min-width: 0; }
.message.user .message-body { padding: 17px 20px; border: 1px solid var(--line); border-radius: 6px 20px 20px 20px; background: rgba(10, 24, 39, .72); }
.message-meta { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; color: #62798c; font: 9px ui-monospace, monospace; letter-spacing: .08em; }
.message-meta strong { color: #95aabe; }
.message.assistant .message-meta strong { color: var(--cyan); }
.message-content { color: #dbe5ee; font-size: 15px; line-height: 1.75; overflow-wrap: anywhere; }
.message-content > :first-child { margin-top: 0; }
.message-content > :last-child { margin-bottom: 0; }
.message-content h1, .message-content h2, .message-content h3 { margin: 1.3em 0 .55em; color: white; line-height: 1.2; }
.message-content h1 { font-size: 24px; } .message-content h2 { font-size: 20px; } .message-content h3 { font-size: 17px; }
.message-content code { padding: 2px 5px; border-radius: 5px; background: rgba(32, 116, 155, .16); color: #75dcff; font-family: ui-monospace, Consolas, monospace; }
.message-content a { color: var(--cyan); }
.message-content blockquote { margin: 14px 0; padding: 10px 15px; border-left: 2px solid var(--cyan); background: rgba(9, 46, 64, .25); color: #a9bbca; }
.message-content li { margin: 5px 0; }
.code-block { margin: 16px 0; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: #020710; }
.code-head { display: flex; justify-content: space-between; align-items: center; height: 38px; padding: 0 12px; border-bottom: 1px solid var(--line); color: #65859c; font: 10px ui-monospace, monospace; }
.code-head button { border: 0; background: transparent; color: #82a1b8; font-size: 10px; cursor: pointer; }
.code-block pre { margin: 0; padding: 16px; overflow: auto; }
.code-block pre code { padding: 0; background: none; color: #bad5e6; }
.markdown-table-wrap { overflow-x: auto; }
.message-content table { width: 100%; border-collapse: collapse; margin: 14px 0; }
.message-content th, .message-content td { padding: 9px; border: 1px solid var(--line); text-align: left; }
.message-actions { display: flex; gap: 8px; margin-top: 10px; opacity: 0; transition: opacity .2s; }
.message:hover .message-actions { opacity: 1; }
.message-actions button { padding: 5px 8px; border: 0; border-radius: 7px; background: transparent; color: #607d92; font-size: 10px; cursor: pointer; }
.message-actions button:hover { background: rgba(25, 212, 255, .08); color: var(--cyan); }
.typing-caret { display: inline-block; width: 7px; height: 15px; margin-left: 4px; background: var(--cyan); animation: blink .8s steps(1) infinite; vertical-align: -2px; }

.artifact-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-top: 16px; }
.artifact-card { overflow: hidden; border: 1px solid var(--line); border-radius: 17px; background: rgba(7, 17, 29, .8); }
.artifact-image { position: relative; min-height: 180px; background: #02060b; }
.artifact-image img { display: block; width: 100%; max-height: 430px; object-fit: contain; }
.image-skeleton { display: grid; place-items: center; height: 240px; color: #516a7f; font-size: 12px; background: linear-gradient(100deg, #06101a, #0b1c2a, #06101a); background-size: 200% 100%; animation: shimmer 1.5s infinite; }
.artifact-info { display: flex; align-items: center; gap: 10px; padding: 12px; }
.artifact-icon { display: grid; place-items: center; flex: 0 0 auto; width: 38px; height: 38px; border-radius: 10px; background: rgba(19, 185, 237, .1); color: var(--cyan); font: 9px ui-monospace, monospace; }
.artifact-info p { min-width: 0; flex: 1; margin: 0; }
.artifact-info strong, .artifact-info small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.artifact-info strong { font-size: 12px; }
.artifact-info small { margin-top: 3px; color: #60798d; font-size: 9px; }
.artifact-actions { display: flex; gap: 6px; }
.artifact-actions button { padding: 7px 9px; border: 1px solid var(--line); border-radius: 9px; background: transparent; color: #8ba1b3; font-size: 10px; cursor: pointer; }
.artifact-actions button:hover { border-color: var(--line-hot); color: var(--cyan); }

/* Composer */
.composer-shell {
  position: absolute;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 15;
  width: min(920px, calc(100% - 40px));
  transform: translateX(-50%);
}
.composer {
  position: relative;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 46px;
  align-items: end;
  gap: 9px;
  padding: 9px;
  border: 1px solid rgba(87, 155, 198, .3);
  border-radius: 21px;
  background: rgba(6, 14, 25, .95);
  box-shadow: 0 20px 70px rgba(0, 0, 0, .5), 0 0 0 1px rgba(255,255,255,.015) inset;
  backdrop-filter: blur(22px);
  transition: border-color .2s, box-shadow .2s;
}
.composer:focus-within { border-color: rgba(25, 212, 255, .48); box-shadow: 0 20px 70px rgba(0, 0, 0, .5), 0 0 28px rgba(25, 212, 255, .07); }
.composer textarea { width: 100%; min-height: 46px; max-height: 180px; padding: 12px 4px 8px; border: 0; outline: 0; resize: none; background: transparent; color: white; line-height: 1.5; }
.composer textarea::placeholder { color: #587084; }
.attach-button, .send-button, .stop-button {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  cursor: pointer;
}
.attach-button { border: 1px solid var(--line); background: rgba(12, 28, 43, .75); color: #8ca3b6; font-size: 24px; }
.attach-button:hover { color: var(--cyan); border-color: var(--line-hot); }
.send-button { border: 0; background: linear-gradient(135deg, #16d1f9, #2585ff); color: #00121c; font-size: 24px; font-weight: 800; box-shadow: 0 8px 25px rgba(30, 162, 255, .25); }
.stop-button { border: 1px solid rgba(255, 99, 132, .35); background: rgba(255, 99, 132, .08); color: var(--danger); font-size: 13px; }
.drop-hint { margin: 8px 0 0; color: #40596c; font-size: 9px; text-align: center; letter-spacing: .05em; }
.composer-shell.is-dragging .composer { border-color: var(--cyan); box-shadow: 0 0 40px rgba(25, 212, 255, .18); }
.quote-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  margin: 0 12px 8px;
  padding: 10px 12px;
  border-left: 2px solid var(--cyan);
  border-radius: 9px;
  background: rgba(6, 25, 39, .94);
}
.quote-chip b, .quote-chip small { display: block; }
.quote-chip b { color: var(--cyan); font-size: 9px; text-transform: uppercase; }
.quote-chip small { max-width: 650px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #8198ab; }
.quote-chip button { border: 0; background: transparent; color: #688095; cursor: pointer; }
.attached-files { display: flex; gap: 8px; margin: 0 10px 8px; overflow-x: auto; }
.file-chip { display: flex; align-items: center; flex: 0 0 auto; gap: 8px; max-width: 280px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 11px; background: rgba(6, 17, 28, .96); font-size: 10px; }
.file-chip.processing { opacity: .65; }
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip button { border: 0; background: transparent; color: #72889a; cursor: pointer; }
.file-chip .file-edit { color: var(--cyan); }
.attach-menu {
  position: absolute;
  left: 8px;
  bottom: calc(100% + 8px);
  width: 268px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(5, 13, 23, .98);
  box-shadow: 0 22px 60px rgba(0, 0, 0, .55);
  animation: pop-in .18s ease-out;
}
.attach-menu button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px; border: 0; border-radius: 11px; background: transparent; text-align: left; cursor: pointer; }
.attach-menu button:hover { background: rgba(25, 212, 255, .08); color: var(--cyan); }
.attach-menu button > span { display: grid; }
.attach-menu b { font-size: 12px; }
.attach-menu small { margin-top: 3px; color: #657d91; font-size: 9px; }

/* Image editor */
.image-editor {
  width: min(1220px, calc(100vw - 28px));
  max-width: none;
  height: min(820px, calc(100dvh - 28px));
  padding: 0;
  border: 1px solid rgba(73, 177, 231, .3);
  border-radius: 24px;
  background: #050c16;
  color: white;
  box-shadow: 0 40px 130px rgba(0,0,0,.85);
}
.image-editor::backdrop { background: rgba(0, 3, 8, .84); backdrop-filter: blur(12px); }
.editor-shell { height: 100%; display: grid; grid-template-rows: 72px minmax(0, 1fr); }
.editor-shell > header { display: flex; align-items: center; justify-content: space-between; padding: 0 22px; border-bottom: 1px solid var(--line); }
.editor-shell h2 { margin: 4px 0 0; font-size: 20px; }
.editor-close { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 11px; background: transparent; color: #8399ac; font-size: 24px; cursor: pointer; }
.editor-workspace { min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 320px; }
.canvas-stage { position: relative; min-width: 0; min-height: 0; display: grid; place-items: center; overflow: hidden; background: #010409; background-image: linear-gradient(45deg,#07101a 25%,transparent 25%),linear-gradient(-45deg,#07101a 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#07101a 75%),linear-gradient(-45deg,transparent 75%,#07101a 75%); background-size: 24px 24px; background-position: 0 0,0 12px,12px -12px,-12px 0; touch-action: none; }
.canvas-stage canvas { position: absolute; max-width: calc(100% - 30px); max-height: calc(100% - 30px); width: auto; height: auto; }
#editor-mask { cursor: crosshair; }
.editor-loading { position: relative; z-index: 4; color: #70889b; }
.editor-tools { display: flex; flex-direction: column; gap: 18px; padding: 24px; border-left: 1px solid var(--line); background: rgba(7, 15, 26, .96); overflow-y: auto; }
.editor-tools > p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.editor-tools label { display: grid; gap: 10px; color: #9fb0bf; font-size: 11px; font-weight: 700; }
.editor-tools output { justify-self: end; margin-top: -20px; color: var(--cyan); font: 11px ui-monospace, monospace; }
.editor-tools input[type=range] { accent-color: var(--cyan); }
.tool-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tool-row button { height: 40px; border: 1px solid var(--line); border-radius: 10px; background: transparent; color: #879caf; cursor: pointer; }
.tool-row button.active, .tool-row button:hover { border-color: var(--line-hot); background: rgba(25, 212, 255, .08); color: var(--cyan); }
.edit-prompt-label { margin-top: auto; }
.edit-prompt-label textarea { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 12px; outline: none; resize: vertical; background: #030914; color: white; line-height: 1.5; }
.edit-prompt-label textarea:focus { border-color: var(--line-hot); }
.edit-submit { display: flex; align-items: center; justify-content: space-between; min-height: 52px; padding: 0 16px; border: 0; border-radius: 12px; background: linear-gradient(120deg, #18cdf4, #287fff); color: #00121c; font-weight: 900; cursor: pointer; }
.edit-submit:disabled { opacity: .6; cursor: wait; }

.selection-action { position: fixed; z-index: 80; padding: 8px 11px; border: 1px solid var(--line-hot); border-radius: 9px; background: #071827; color: var(--cyan); font-size: 10px; cursor: pointer; }
.toast-stack { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: grid; gap: 8px; width: min(350px, calc(100vw - 36px)); }
.toast { padding: 13px 15px; border: 1px solid var(--line); border-radius: 12px; background: rgba(7, 17, 29, .97); color: #c2d1dc; box-shadow: 0 15px 40px rgba(0,0,0,.45); font-size: 12px; animation: toast-in .25s ease-out; }
.toast.error { border-color: rgba(255, 99, 132, .35); color: #ff9db1; }

@keyframes card-in { from { opacity: 0; transform: translateY(20px) scale(.98); } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
@keyframes pop-in { from { opacity: 0; transform: translate(-50%, -5px) scale(.98); } }
@keyframes toast-in { from { opacity: 0; transform: translateX(10px); } }
@keyframes pulse-ring { 0%, 100% { opacity: .15; transform: scale(.92); } 50% { opacity: .7; transform: scale(1.04); } }
@keyframes orbit { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: 64px minmax(0, 1fr); }
  .topbar { grid-template-columns: auto auto minmax(0, 1fr) auto; padding: 0 10px; gap: 8px; }
  .mobile-menu { display: grid; place-items: center; width: 40px; padding: 0; }
  .brand { width: 40px; padding: 0; border: 0; }
  .brand > span:last-child { display: none; }
  .brand-mark { width: 36px; height: 36px; }
  .model-switcher { justify-self: stretch; min-width: 0; }
  .model-button { min-width: 0; width: 100%; height: 42px; }
  .model-button small { display: none; }
  .model-button strong { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .model-popover { position: fixed; top: 70px; left: 50%; width: calc(100vw - 24px); }
  .quota-pill { display: none; }
  .disconnect { width: 40px; padding: 0; font-size: 0; }
  .disconnect::before { content: "↪"; font-size: 18px; }
  .history-panel {
    position: fixed;
    inset: 64px auto 0 0;
    width: min(350px, 88vw);
    transform: translateX(-102%);
    transition: transform .28s cubic-bezier(.2,.8,.2,1);
    box-shadow: 28px 0 70px rgba(0,0,0,.55);
  }
  .history-panel.open { transform: none; }
  .panel-close { display: block; }
  .panel-scrim { position: fixed; inset: 64px 0 0; z-index: 20; display: block; border: 0; background: rgba(0,3,8,.62); }
  .chat-stage { grid-column: 1; grid-row: 2; grid-template-rows: 58px minmax(0,1fr) auto; }
  .chat-head { padding: 0 16px; }
  .chat-head .micro-label { display: none; }
  .chat-head h1 { max-width: 65vw; margin: 0; font-size: 14px; }
  .messages { padding: 22px 14px 145px; }
  .message { grid-template-columns: 28px minmax(0,1fr); gap: 10px; margin-bottom: 28px; }
  .message-node { width: 28px; height: 28px; border-radius: 8px; }
  .message.user .message-body { padding: 14px; border-radius: 5px 16px 16px 16px; }
  .message-content { font-size: 14px; line-height: 1.65; }
  .empty-chat { padding-bottom: 60px; }
  .empty-chat h2 { font-size: 38px; }
  .starter-grid { grid-template-columns: 1fr; width: min(420px,100%); }
  .starter-grid button { min-height: 62px; grid-template-columns: 30px 1fr; align-items: center; }
  .starter-grid span { align-self: center; }
  .composer-shell { bottom: max(8px, env(safe-area-inset-bottom)); width: calc(100% - 16px); }
  .drop-hint { display: none; }
  .composer { grid-template-columns: 42px minmax(0,1fr) 42px; border-radius: 18px; }
  .attach-button, .send-button, .stop-button { width: 42px; height: 42px; }
  .artifact-grid { grid-template-columns: 1fr; }
  .message-actions { opacity: 1; }
  .editor-workspace { grid-template-columns: 1fr; grid-template-rows: minmax(280px, 1fr) auto; }
  .editor-tools { max-height: 310px; padding: 16px; border-left: 0; border-top: 1px solid var(--line); }
  .edit-prompt-label { margin-top: 0; }
}

@media (max-width: 520px) {
  .connect-layer { padding: 10px; }
  .connect-card { padding: 34px 22px; border-radius: 24px; }
  .connect-card h1 { font-size: 42px; }
  .trust-row { display: grid; gap: 7px; }
  .model-button { padding: 0 9px; gap: 7px; }
  .model-button strong { max-width: 105px; font-size: 12px; }
  .model-pulse { width: 7px; height: 7px; }
  .empty-chat > p:not(.micro-label) { font-size: 13px; }
  .core-visual { width: 86px; height: 86px; margin-bottom: 18px; }
  .delete-chat { width: 34px; padding: 0; font-size: 0; }
  .delete-chat::after { content: "×"; color: var(--danger); font-size: 19px; }
  .image-editor { width: 100vw; height: 100dvh; border: 0; border-radius: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
  .cursor-orb { display: none; }
}
