/* ============================================
   ED — TALK SHIT
   Street Brutalist / Fight Night aesthetic
   ============================================ */

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

:root {
  --bg: #080808;
  --surface: #111;
  --surface-2: #161616;
  --surface-3: #1c1c1c;
  --border: #222;
  --border-light: #333;
  --text: #eee;
  --text-dim: #666;
  --text-muted: #444;
  --ed: #e61919;
  --ed-bright: #ff2d2d;
  --ed-glow: rgba(230, 25, 25, 0.25);
  --ed-glow-soft: rgba(230, 25, 25, 0.08);
  --user-bg: #1a2a3a;
  --user-border: #243a50;
  --font-display: 'Bebas Neue', Impact, sans-serif;
  --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

/* ===== SCREENS ===== */
.screen {
  display: none;
  height: 100%;
  height: 100dvh;
  width: 100%;
  position: relative;
}
.screen.active { display: flex; }

/* ===== LOGIN ===== */
.login-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  gap: 48px;
  position: relative;
  overflow: hidden;
}

.login-bg-grain {
  position: absolute;
  inset: 0;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-size: 200px;
  pointer-events: none;
}

.logo {
  text-align: center;
  position: relative;
  z-index: 1;
}

/* Ed Avatar — menacing ring */
.ed-ring {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  margin: 0 auto 28px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ed-ring::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  background: conic-gradient(var(--ed), transparent 30%, var(--ed) 60%, transparent 80%, var(--ed));
  animation: ring-spin 4s linear infinite;
}

.ed-ring::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 40px var(--ed-glow), 0 0 80px var(--ed-glow-soft);
}

@keyframes ring-spin {
  to { transform: rotate(360deg); }
}

.ed-avatar {
  width: 94px;
  height: 94px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--ed);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  position: relative;
  z-index: 1;
}

.ed-letter {
  font-family: var(--font-display);
  font-size: 38px;
  color: var(--ed-bright);
  line-height: 1;
  letter-spacing: 3px;
}

.logo h1 {
  font-family: var(--font-display);
  font-size: 52px;
  font-weight: 400;
  line-height: 0.95;
  letter-spacing: 4px;
  color: var(--text);
}

.title-accent {
  color: var(--ed-bright);
  font-size: 58px;
  letter-spacing: 6px;
}

.tagline-bar {
  width: 40px;
  height: 3px;
  background: var(--ed);
  margin: 16px auto 12px;
  box-shadow: 0 0 12px var(--ed-glow);
}

.tagline {
  font-size: 14px;
  color: var(--text-dim);
  letter-spacing: 2px;
  text-transform: uppercase;
  font-weight: 500;
}

/* Login Form */
.login-form {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
  z-index: 1;
}

.input-wrap {
  position: relative;
}

.input-wrap::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 2px;
  background: var(--ed);
  transition: width 0.3s ease;
}

.input-wrap:focus-within::after {
  width: 100%;
}

.login-form input {
  width: 100%;
  padding: 14px 0;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 500;
  outline: none;
  letter-spacing: 0.5px;
  transition: border-color 0.2s;
}

.login-form input::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

#login-btn {
  padding: 16px;
  background: var(--ed);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 20px;
  letter-spacing: 3px;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
  margin-top: 4px;
}

#login-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 40%, rgba(255,255,255,0.1) 50%, transparent 60%);
  transform: translateX(-100%);
  transition: transform 0.5s;
}

#login-btn:hover::before {
  transform: translateX(100%);
}

#login-btn:active {
  transform: scale(0.98);
  background: var(--ed-bright);
}

.disclaimer {
  color: var(--text-muted);
  font-size: 11px;
  text-align: center;
  letter-spacing: 0.5px;
  line-height: 1.5;
}

/* ===== CHAT ===== */
#chat-screen {
  flex-direction: column;
  background: var(--bg);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ed-avatar-small {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--ed);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
}

.ed-avatar-small span {
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--ed-bright);
  letter-spacing: 2px;
  line-height: 1;
}

.pulse-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid var(--surface);
}

.header-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.header-name {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 18px;
  letter-spacing: 2px;
  line-height: 1;
  color: var(--text);
}

.header-status {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.3px;
}

.header-right {
  display: flex;
  gap: 2px;
}

.header-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.2s;
  border-radius: 8px;
}

.header-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}

.header-btn:active {
  color: var(--ed-bright);
}

/* ===== MESSAGES ===== */
.messages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.welcome-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  gap: 12px;
  flex: 1;
  opacity: 0.4;
}

.welcome-ed {
  font-family: var(--font-display);
  font-size: 28px;
  color: var(--ed);
  letter-spacing: 4px;
  opacity: 0.5;
}

.welcome-text {
  font-size: 13px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 3px;
}

/* Messages */
.message {
  display: flex;
  gap: 8px;
  max-width: 88%;
  animation: msgIn 0.25s ease-out;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message.ed {
  align-self: flex-start;
}

.message-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 9px;
  letter-spacing: 1px;
  margin-top: 2px;
}

.message.ed .message-avatar {
  background: var(--bg);
  border: 1.5px solid var(--ed);
  color: var(--ed-bright);
  font-family: var(--font-display);
  font-size: 10px;
}

.message.user .message-avatar {
  background: var(--surface-3);
  border: 1.5px solid var(--border-light);
  color: var(--text-dim);
  font-size: 10px;
}

.message-bubble {
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message.ed .message-bubble {
  background: var(--surface-2);
  border-left: 2px solid var(--ed);
  border-radius: 0 12px 12px 0;
  color: var(--text);
}

.message.user .message-bubble {
  background: var(--user-bg);
  border-right: 2px solid var(--user-border);
  border-radius: 12px 0 0 12px;
  color: #ccd;
}

/* Typing */
.typing-indicator {
  display: flex;
  gap: 5px;
  padding: 10px 14px;
  align-self: flex-start;
  margin-left: 34px;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ed);
  animation: typePulse 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typePulse {
  0%, 70%, 100% { opacity: 0.2; transform: scale(0.85); }
  35% { opacity: 1; transform: scale(1.1); }
}

/* ===== INPUT BAR ===== */
.input-container {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#message-input {
  flex: 1;
  padding: 10px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 22px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  resize: none;
  outline: none;
  max-height: 100px;
  line-height: 1.4;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}

#message-input:focus {
  border-color: var(--ed);
  box-shadow: 0 0 0 1px var(--ed-glow-soft);
}

#message-input::placeholder {
  color: var(--text-muted);
}

#send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--ed);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}

#send-btn:active {
  transform: scale(0.9);
  background: var(--ed-bright);
}

#send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ===== KB MODAL ===== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--surface);
  border-top: 2px solid var(--ed);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 75vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 400;
  letter-spacing: 3px;
  color: var(--ed-bright);
}

.modal-header button {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
}

.kb-list {
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.kb-empty {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 24px 0;
  letter-spacing: 0.3px;
}

.kb-fact {
  display: flex;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface-2);
  border-left: 2px solid var(--ed);
  font-size: 13px;
  line-height: 1.5;
}

.kb-category {
  color: var(--ed-bright);
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 1.5px;
  flex-shrink: 0;
  min-width: 65px;
  padding-top: 1px;
}

.kb-text {
  color: var(--text);
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ===== MOBILE ===== */
@media (max-width: 500px) {
  .logo h1 {
    font-size: 44px;
  }
  .title-accent {
    font-size: 50px;
  }
  .message {
    max-width: 92%;
  }
  .modal-content {
    max-height: 80vh;
  }
}

@media (max-width: 360px) {
  .logo h1 {
    font-size: 38px;
  }
  .title-accent {
    font-size: 42px;
  }
}
