:root {
  --bg: #0e0e10;
  --surface: #18181c;
  --surface2: #222228;
  --border: #2e2e38;
  --accent: #f97316;
  --accent-dim: rgba(249, 115, 22, 0.10);
  --accent-border: rgba(249, 115, 22, 0.28);
  --text: #e8e8ef;
  --text-muted: #6b6b80;
  --font-mono: 'DM Mono', monospace;
  --font-serif: 'Instrument Serif', serif;
  --error: #f87171;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

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

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

/* Header */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  z-index: 20;
}

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

.logo-dot {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 500;
  color: #fff;
  font-style: italic;
  font-family: var(--font-serif);
  box-shadow: 0 2px 8px rgba(249, 115, 22, 0.2);
}

.brand-name {
  font-family: var(--font-serif);
  font-size: 18px;
  font-style: italic;
  letter-spacing: -0.02em;
}

/* Language Selector */
#language-selector {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  position: relative;
  user-select: none;
}

#language-selector:hover {
  background: var(--accent-dim);
}

#language-menu {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  min-width: 120px;
  display: none;
  z-index: 100;
}

#language-menu.open {
  display: block;
}

.language-option {
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.language-option:hover {
  background: var(--surface2);
}

.language-option.active {
  background: var(--accent-dim);
  color: var(--accent);
}

/* Header Right Container */
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Messages */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

#messages::-webkit-scrollbar {
  width: 4px;
}

#messages::-webkit-scrollbar-track {
  background: transparent;
}

#messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* Welcome Screen */
#welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 12px;
  text-align: center;
  padding: 40px 20px;
  animation: fadeUp 0.6s ease both;
}

#welcome h1 {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 32px;
  letter-spacing: -0.03em;
  line-height: 1.1;
  background: linear-gradient(90deg, var(--accent), var(--success));
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

#welcome p {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
  max-width: 260px;
}

.welcome-suggestions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 320px;
  margin-top: 16px;
}

.suggestion {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  cursor: pointer;
  text-align: left;
  font-size: 12px;
  color: var(--text-muted);
  transition: all 0.2s;
  line-height: 1.4;
  position: relative;
  overflow: hidden;
}

.suggestion::before {
  content: "✦";
  position: absolute;
  left: 12px;
  color: var(--accent);
}

.suggestion:hover, .suggestion:active {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-dim);
  transform: translateY(-1px);
}

/* Message Cards */
.msg-card {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--border);
  overflow: hidden;
  animation: fadeUp 0.28s ease both;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.3);
}

.msg-card.user {
  border-color: #2a2a36;
}

.msg-card.user .msg-card-header {
  background: #1b1b24;
}

.msg-card.user .msg-card-body {
  background: #17171f;
}

.msg-card.ai {
  border-color: var(--accent-border);
}

.msg-card.ai .msg-card-header {
  background: #111115;
}

.msg-card.ai .msg-card-body {
  background: #0d0d12;
}

.msg-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
}

.card-role {
  display: flex;
  align-items: center;
  gap: 8px;
}

.role-dot {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-family: var(--font-serif);
  font-style: italic;
}

.msg-card.ai .role-dot {
  background: var(--accent);
  color: #fff;
}

.msg-card.user .role-dot {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.role-label {
  font-size: 10px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  font-weight: 500;
}

.msg-card.ai .role-label {
  color: var(--accent);
}

.msg-card.user .role-label {
  color: var(--text-muted);
}

.card-timestamp {
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.4;
}

.msg-card-body {
  padding: 14px 16px;
  line-height: 1.75;
  font-size: 13.5px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  min-height: 42px;
}

/* Translation hover effect */
.msg-card-body [data-translation] {
  display: none;
  font-style: italic;
  font-size: 0.85em;
  color: var(--text-muted);
  opacity: 0.8;
  margin-top: 0.3em;
}

.msg-card-body span:hover [data-translation] {
  display: block;
}

.msg-card-footer {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 7px 12px;
  border-top: 1px solid var(--border);
  background: #0a0a0e;
}

.footer-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 10px;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  padding: 4px 8px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s;
}

.footer-btn:hover {
  color: var(--text);
  background: var(--surface2);
}

.footer-btn svg {
  width: 11px;
  height: 11px;
  fill: currentColor;
  flex-shrink: 0;
}

/* Footer */
#footer {
  flex-shrink: 0;
  background: #0a0a0d;
  border-top: 1px solid var(--border);
  padding: 0;
}

/* Input Row */
#input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px 14px;
}

#input-box {
  flex: 1;
  position: relative;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 18px;
  padding: 10px 46px 10px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#input-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.08);
}

#prompt {
  width: 100%;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.5;
  resize: none;
  max-height: 110px;
  min-height: 22px;
  padding: 0;
  caret-color: var(--accent);
  display: block;
}

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

#send-btn {
  position: absolute;
  right: 7px;
  bottom: 7px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  opacity: 0.35;
}

#send-btn.active {
  opacity: 1;
}

#send-btn:active {
  transform: scale(0.9);
}

#send-btn.loading {
  opacity: 1;
  background: var(--surface2);
  cursor: not-allowed;
}

/* Animations */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Toast */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 11px;
  padding: 6px 14px;
  border-radius: 20px;
  z-index: 999;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

/* Error Message Styling */
.msg-card.error {
  border-color: var(--error);
}

.msg-card.error .msg-card-header {
  background: rgba(239, 68, 68, 0.1);
}

.msg-card.error .msg-card-body {
  background: rgba(239, 68, 68, 0.05);
  color: var(--error);
  font-weight: 500;
}

/* Error code styling */
.msg-card-body [data-error-code] {
  display: block;
  font-size: 0.8em;
  color: var(--error);
  margin-top: 0.5em;
  font-family: var(--font-mono);
  opacity: 0.9;
}
