*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0b0c0f;
  --surface: #131518;
  --surface-2: #1a1d22;
  --surface-3: #22262c;
  --border: #2a2e36;
  --text: #e8e4de;
  --text-dim: #8a8680;
  --text-muted: #5c5955;
  --accent: #e8a84c;
  --accent-dim: #c4862e;
  --accent-glow: rgba(232, 168, 76, 0.12);
  --accent-glow-strong: rgba(232, 168, 76, 0.25);
  --red: #d45a5a;
  --green: #6abf7b;
  --radius: 12px;
  --radius-sm: 8px;
  --font-body: "Manrope", sans-serif;
  --font-display: "Instrument Serif", serif;
  --font-mono: "DM Mono", monospace;
}

html {
  font-size: 16px;
}
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  opacity: 0;
}
body.ready {
  opacity: 1;
}

/* ─── Noise overlay ─── */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
}

/* ─── Screens ─── */
.screen {
  display: none;
  width: 100%;
  height: 100dvh;
}
.screen.active {
  display: flex;
}

#landing {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.landing-glow {
  position: absolute;
  width: 600px;
  height: 600px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    var(--accent-glow-strong) 0%,
    transparent 70%
  );
  top: 50%;
  left: 50%;
  transform: translate(-50%, -55%);
  animation: breathe 6s ease-in-out infinite;
  pointer-events: none;
}
@keyframes breathe {
  0%,
  100% {
    opacity: 0.5;
    transform: translate(-50%, -55%) scale(1);
  }
  50% {
    opacity: 0.8;
    transform: translate(-50%, -55%) scale(1.12);
  }
}

.landing-tag {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-glow);
  border: 1px solid rgba(232, 168, 76, 0.2);
  padding: 6px 16px;
  border-radius: 100px;
  margin-bottom: 28px;
  position: relative;
}

.landing-title {
  font-family: var(--font-display);
  font-size: clamp(3rem, 8vw, 5.5rem);
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--text);
  position: relative;
  margin-bottom: 16px;
}
.landing-title em {
  font-style: italic;
  color: var(--accent);
}

.landing-sub {
  font-size: 1.05rem;
  color: var(--text-dim);
  max-width: 520px;
  line-height: 1.65;
  margin-bottom: 44px;
  position: relative;
  font-weight: 300;
}

.landing-specs {
  display: flex;
  gap: 32px;
  margin-bottom: 48px;
  position: relative;
}
.spec {
  text-align: center;
}
.spec-value {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
}
.spec-label {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-top: 4px;
}

.btn-load-group {
  display: inline-flex;
  align-items: stretch;
  border-radius: 100px;
  position: relative;
  box-shadow: 0 0 40px var(--accent-glow-strong);
  transition: all 0.25s;
}
.btn-load-group:hover {
  transform: translateY(-2px);
  box-shadow:
    0 0 60px var(--accent-glow-strong),
    0 8px 30px rgba(0, 0, 0, 0.4);
}
.btn-load-group:active {
  transform: translateY(0);
}
.btn-load {
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--bg);
  background: var(--accent);
  border: none;
  padding: 16px 12px 16px 36px;
  border-radius: 100px 0 0 100px;
  cursor: pointer;
}
.btn-load-arrow {
  color: var(--bg);
  background: var(--accent);
  border: none;
  border-left: 1px solid rgba(0, 0, 0, 0.15);
  padding: 16px 20px 16px 12px;
  border-radius: 0 100px 100px 0;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.model-select {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  pointer-events: none;
}
.model-select option {
  background: var(--surface-2);
  color: var(--text);
}

.landing-footer {
  position: absolute;
  bottom: 28px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
}
.landing-footer a {
  color: var(--text-dim);
  text-decoration: none;
}
.landing-footer a:hover {
  color: var(--accent);
}

#loading {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 36px;
}

.loader-ring {
  width: 72px;
  height: 72px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loader-text {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-dim);
  letter-spacing: 0.05em;
  text-align: center;
}
.loader-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 8px;
  text-align: center;
  line-height: 1.5;
}

#chat {
  flex-direction: column;
  height: 100dvh;
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.chat-avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--bg);
  font-weight: 600;
}
.chat-header-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
}
.chat-header-status {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--green);
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  gap: 5px;
}
.chat-header-status::before {
  content: "";
  width: 6px;
  height: 6px;
  background: var(--green);
  border-radius: 50%;
}
.chat-header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Reasoning toggle */
.toggle-reasoning {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}
.toggle-reasoning input {
  display: none;
}
.toggle-slider {
  width: 32px;
  height: 18px;
  background: var(--border);
  border-radius: 100px;
  position: relative;
  transition: background 0.2s;
}
.toggle-slider::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-muted);
  top: 2px;
  left: 2px;
  transition: all 0.2s;
}
.toggle-reasoning input:checked + .toggle-slider {
  background: var(--accent-glow);
}
.toggle-reasoning input:checked + .toggle-slider::after {
  background: var(--accent);
  left: 16px;
}
.toggle-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  transition: color 0.2s;
}
.toggle-reasoning input:checked ~ .toggle-label {
  color: var(--accent);
}

.btn-reset {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 100px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-reset:hover {
  color: var(--red);
  border-color: var(--red);
}

/* Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar {
  width: 5px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}

.msg {
  max-width: 72%;
  padding: 14px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.65;
  animation: msgIn 0.3s ease;
  word-wrap: break-word;
  white-space: pre-wrap;
}
@keyframes msgIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.msg.user {
  align-self: flex-end;
  background: var(--surface-3);
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--surface);
  border-bottom-left-radius: 4px;
}
.msg.assistant.generating {
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
}

.msg-image {
  max-width: 220px;
  max-height: 180px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  display: block;
  object-fit: cover;
  border: 1px solid var(--border);
}

.msg-role {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.msg.assistant .msg-role {
  color: var(--accent-dim);
}

.thinking-dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 4px;
  animation: dot 1.2s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) {
  animation-delay: 0.2s;
}
.thinking-dots span:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes dot {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: scale(0.8);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Generation stats */
.msg-stats {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

/* Thinking block (collapsible) */
.msg-thinking-label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-dim);
  margin-bottom: 4px;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 4px;
}
.msg-thinking-label:hover {
  color: var(--accent);
}
.msg-thinking-chevron {
  font-size: 0.55rem;
  transition: transform 0.2s;
}
.msg-thinking {
  font-size: 0.8rem;
  color: var(--text-muted);
  border-left: 2px solid var(--border);
  padding-left: 10px;
  margin-bottom: 8px;
  max-height: none;
  overflow-y: auto;
}
.msg-thinking.collapsing {
  overflow: hidden;
  transition:
    max-height 0.3s ease,
    opacity 0.2s ease,
    margin-bottom 0.2s ease;
}
.msg-thinking.collapsed {
  max-height: 0 !important;
  opacity: 0;
  margin-bottom: 0;
  overflow: hidden;
}

/* Input area */
.chat-input-area {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.image-preview-bar {
  display: none;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.image-preview-bar.visible {
  display: flex;
}
.image-preview-thumb {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--border);
}
.image-preview-name {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-dim);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-remove-image {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
  transition: color 0.2s;
}
.btn-remove-image:hover {
  color: var(--red);
}

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.btn-attach,
.btn-send {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-attach {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 1.2rem;
}
.btn-attach:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}
.btn-attach:disabled,
.btn-send:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.input-wrap {
  flex: 1;
  position: relative;
}
.input-wrap textarea {
  width: 100%;
  min-height: 42px;
  max-height: 140px;
  padding: 10px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.88rem;
  line-height: 1.5;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
}
.input-wrap textarea::placeholder {
  color: var(--text-muted);
}
.input-wrap textarea:focus {
  border-color: var(--accent);
}

.btn-send {
  background: var(--accent);
  border: none;
  color: var(--bg);
  font-size: 1.1rem;
}
.btn-send .icon-stop {
  display: none;
}
.btn-send.stopping {
  background: var(--red);
}
.btn-send.stopping .icon-send {
  display: none;
}
.btn-send.stopping .icon-stop {
  display: block;
}
.btn-send:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px var(--accent-glow-strong);
}
.btn-send.stopping:not(:disabled):hover {
  box-shadow: 0 4px 20px rgba(212, 90, 90, 0.3);
}

.chat-footer-note {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 10px;
  letter-spacing: 0.04em;
}

/* ─── Error banner ─── */
.error-banner {
  display: none;
  padding: 12px 18px;
  background: rgba(212, 90, 90, 0.1);
  border: 1px solid rgba(212, 90, 90, 0.3);
  border-radius: var(--radius-sm);
  color: var(--red);
  font-size: 0.82rem;
  margin: 12px 24px 0;
}
.error-banner.visible {
  display: block;
}

/* ─── Welcome msg ─── */
.welcome-msg {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.welcome-msg h3 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--text-dim);
  margin-bottom: 8px;
  font-weight: 400;
}
.welcome-msg p {
  font-size: 0.85rem;
  line-height: 1.6;
}
