:root {
  --bg-0: #070708;
  --bg-1: #101114;
  --chrome: rgba(14, 14, 16, 0.88);
  --panel: #121316;
  --panel-2: #18191d;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #f5f1ea;
  --muted: #9b958c;
  --red: #e10600;
  --red-deep: #b10500;
  --red-soft: rgba(225, 6, 0, 0.16);
  --ok: #3ecf8e;
  --warn: #ff8b7e;
  --font-display: "Oswald", "Arial Narrow", sans-serif;
  --font-body: "Manrope", "Segoe UI", sans-serif;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  color: var(--text);
  font-family: var(--font-body);
  background: var(--bg-0);
}

button, input, textarea {
  font: inherit;
}

#app {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(225, 6, 0, 0.07), transparent 28%),
    linear-gradient(135deg, #0c0c0e 0%, #101114 48%, #0a0a0c 100%);
  animation: app-in 420ms ease-out;
}

.ambient {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background:
    radial-gradient(700px 280px at 8% -10%, rgba(225, 6, 0, 0.22), transparent 60%),
    radial-gradient(520px 240px at 92% 0%, rgba(255, 255, 255, 0.04), transparent 55%),
    repeating-linear-gradient(
      -12deg,
      transparent 0 18px,
      rgba(255, 255, 255, 0.012) 18px 19px
    );
  opacity: 0.9;
  z-index: 0;
}

#chrome,
#workspace {
  position: relative;
  z-index: 1;
}

#chrome {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1rem;
  align-items: center;
  padding: 0.7rem 0.9rem;
  background: var(--chrome);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px) saturate(1.15);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: max-content;
}

.mark {
  width: 28px;
  height: 32px;
  display: block;
  flex-shrink: 0;
  object-fit: contain;
  filter: drop-shadow(0 0 10px rgba(225, 6, 0, 0.28));
  animation: mark-pulse 3.2s ease-in-out infinite;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
}

.product {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}

.nav-cluster {
  display: flex;
  gap: 0.28rem;
  padding: 0.2rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
}

.nav-cluster button,
#ai-close,
#ai-summarize,
#ai-form button {
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease, border-color 160ms ease;
}

.nav-cluster button {
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #d8d2c8;
}

.nav-cluster button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.nav-cluster button:disabled {
  opacity: 0.28;
  cursor: default;
}

#omni-form {
  position: relative;
  flex: 1;
  min-width: 0;
}

.omni-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  display: grid;
  pointer-events: none;
}

#omnibox {
  width: 100%;
  height: 2.35rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #141417, #0e0e11);
  color: var(--text);
  padding: 0 1rem 0 2.4rem;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

#omnibox::placeholder {
  color: #6f6a63;
}

#omnibox:focus {
  border-color: rgba(225, 6, 0, 0.55);
  box-shadow: 0 0 0 3px rgba(225, 6, 0, 0.12);
}

#btn-ai {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  height: 2.35rem;
  padding: 0 0.95rem;
  border-radius: 999px;
  border: 1px solid rgba(225, 6, 0, 0.4);
  background: linear-gradient(180deg, rgba(225, 6, 0, 0.18), rgba(225, 6, 0, 0.08));
  color: #ffe4e1;
  font-weight: 700;
  font-size: 0.86rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  white-space: nowrap;
  transition: background 160ms ease, transform 160ms ease, border-color 160ms ease;
}

#btn-ai:hover,
#btn-ai.active {
  background: linear-gradient(180deg, var(--red), var(--red-deep));
  border-color: var(--red);
  color: #fff;
  transform: translateY(-1px);
}

.ai-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 0 rgba(225, 6, 0, 0.45);
  animation: dot-pulse 1.8s ease-out infinite;
}

#workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  transition: grid-template-columns 220ms ease;
}

#workspace.ai-open {
  grid-template-columns: 1fr minmax(300px, 360px);
}

#viewport-wrap {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0.55rem 0.55rem 0;
}

.viewport-frame {
  flex: 1;
  min-height: 0;
  border-radius: 12px 12px 0 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-bottom: 0;
  background: #050505;
  box-shadow: var(--shadow);
}

#viewport {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  background:
    linear-gradient(180deg, #111 0%, #0a0a0a 100%);
  outline: none;
  object-fit: contain;
}

.chrome-foot {
  background: rgba(12, 12, 14, 0.96);
  border: 1px solid var(--line);
  border-top: 1px solid var(--line);
  border-radius: 0 0 12px 12px;
}

#status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.45rem 0.85rem 0.2rem;
  font-size: 0.78rem;
  color: var(--muted);
}

#page-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
  color: #cfc8bd;
}

#conn-state {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.68rem;
}

#conn-state i {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: currentColor;
}

#conn-state.online { color: var(--ok); }
#conn-state.offline { color: var(--warn); }

#captcha-hint {
  margin: 0;
  padding: 0.15rem 0.85rem 0.55rem;
  font-size: 0.72rem;
  color: #7d776e;
}

#ai-sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin: 0.55rem 0.55rem 0 0;
  background:
    linear-gradient(180deg, rgba(225, 6, 0, 0.06), transparent 18%),
    var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px 12px 0 0;
  box-shadow: var(--shadow);
  animation: sidebar-in 240ms ease;
}

#ai-sidebar[hidden] { display: none; }

.ai-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.9rem 0.95rem 0.75rem;
  border-bottom: 1px solid var(--line);
}

.ai-top strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.05rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.ai-sub {
  display: block;
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 500;
}

#ai-close {
  width: 1.85rem;
  height: 1.85rem;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
}

#ai-close:hover {
  color: #fff;
  border-color: var(--line-strong);
}

.ai-key-row {
  display: grid;
  gap: 0.35rem;
  padding: 0.75rem 0.95rem;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.18);
}

.ai-key-row label {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
}

#ai-api-key {
  width: 100%;
  height: 2.15rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0c0c0e;
  color: var(--text);
  padding: 0 0.75rem;
}

#ai-api-key:focus {
  outline: none;
  border-color: rgba(225, 6, 0, 0.55);
}

#ai-messages {
  flex: 1;
  overflow: auto;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.msg {
  padding: 0.75rem 0.85rem;
  border-radius: 12px;
  line-height: 1.5;
  font-size: 0.9rem;
  white-space: pre-wrap;
  animation: msg-in 180ms ease;
}

.msg.user {
  background: var(--red-soft);
  border: 1px solid rgba(225, 6, 0, 0.28);
  align-self: flex-end;
  max-width: 92%;
}

.msg.assistant {
  background: var(--panel-2);
  border: 1px solid var(--line);
  align-self: stretch;
  white-space: pre-wrap;
}

.msg.error {
  background: rgba(255, 80, 80, 0.1);
  border: 1px solid rgba(255, 80, 80, 0.25);
  color: #ffb4ae;
}

.ai-actions {
  padding: 0 0.95rem 0.55rem;
}

#ai-summarize {
  width: 100%;
  height: 2.2rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: #e8e2d8;
  font-weight: 600;
}

#ai-summarize:hover {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.06);
}

#ai-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  padding: 0.7rem 0.95rem 0.4rem;
  border-top: 1px solid var(--line);
}

#ai-input {
  resize: none;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0c0c0e;
  color: var(--text);
  padding: 0.65rem 0.75rem;
  min-height: 2.6rem;
}

#ai-input:focus {
  outline: none;
  border-color: rgba(225, 6, 0, 0.5);
}

#ai-form button {
  width: 2.6rem;
  border-radius: 10px;
  background: linear-gradient(180deg, var(--red), var(--red-deep));
  color: #fff;
  display: grid;
  place-items: center;
}

#ai-form button:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.ai-media {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  margin-top: 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #0b0b0b;
}

.ai-hint {
  margin: 0;
  padding: 0 0.95rem 0.85rem;
  color: #7d776e;
  font-size: 0.72rem;
  line-height: 1.4;
}

@keyframes app-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@keyframes sidebar-in {
  from { opacity: 0; transform: translateX(12px); }
  to { opacity: 1; transform: none; }
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@keyframes mark-pulse {
  0%, 100% { filter: drop-shadow(0 0 6px rgba(225, 6, 0, 0.18)); transform: translateY(0); }
  50% { filter: drop-shadow(0 0 14px rgba(0, 195, 240, 0.28)); transform: translateY(-1px); }
}

@keyframes dot-pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 228, 225, 0.45); }
  70% { box-shadow: 0 0 0 8px rgba(255, 228, 225, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 228, 225, 0); }
}

@media (max-width: 900px) {
  #chrome {
    grid-template-columns: 1fr;
    gap: 0.65rem;
  }

  #workspace.ai-open {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 44vh;
  }

  #ai-sidebar {
    margin: 0 0.55rem 0;
    border-radius: 12px 12px 0 0;
  }

  .product { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #app, #ai-sidebar, .msg, .mark, .ai-dot {
    animation: none !important;
  }
}
