:root {
  --ink: #0e1a1c;
  --panel: #14252a;
  --jade: #5fbfa0;
  --gold: #e8b84b;
  --paper: #f1eee4;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--ink);
  color: var(--paper);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.screen {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Login */

#login-screen {
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 320px;
  background: var(--panel);
  border-radius: 12px;
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.login-card h1 {
  margin: 0 0 0.5rem;
  color: var(--gold);
  font-size: 1.4rem;
  text-align: center;
}

.login-card input {
  background: var(--ink);
  border: 1px solid #24393e;
  color: var(--paper);
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  font-size: 1rem;
}

.login-card button {
  background: var(--jade);
  border: none;
  color: var(--ink);
  font-weight: 600;
  padding: 0.7rem;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
}

.error {
  color: #e88b4b;
  font-size: 0.85rem;
  text-align: center;
  margin: 0;
}

/* Chat */

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid #1c2f34;
}

.display-name {
  color: var(--gold);
  font-weight: 600;
}

.header-actions {
  display: flex;
  gap: 0.4rem;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--paper);
  font-size: 1.1rem;
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
  cursor: pointer;
}

.icon-btn[aria-pressed="true"] {
  background: var(--jade);
  color: var(--ink);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.bubble {
  max-width: 78%;
  padding: 0.6rem 0.9rem;
  border-radius: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.bubble.user {
  align-self: flex-end;
  background: var(--gold);
  color: var(--ink);
  border-bottom-right-radius: 4px;
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--panel);
  color: var(--paper);
  border-bottom-left-radius: 4px;
}

.typing-dots {
  align-self: flex-start;
  background: var(--panel);
  padding: 0.7rem 1rem;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 0.3rem;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--jade);
  animation: blink 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem;
  background: var(--panel);
  border-top: 1px solid #1c2f34;
  padding-bottom: max(0.6rem, env(safe-area-inset-bottom));
}

.chat-input-bar input {
  flex: 1;
  background: var(--ink);
  border: 1px solid #24393e;
  color: var(--paper);
  padding: 0.65rem 0.9rem;
  border-radius: 20px;
  font-size: 1rem;
}

.send-btn {
  background: var(--jade);
  border: none;
  color: var(--ink);
  font-weight: 600;
  padding: 0.6rem 1rem;
  border-radius: 20px;
  cursor: pointer;
}

.mic-btn {
  font-size: 1.3rem;
}

.mic-btn.listening {
  background: var(--gold);
  color: var(--ink);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Memory drawer */

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100dvh;
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  padding: 1rem;
  gap: 1rem;
  z-index: 10;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-header h2 {
  margin: 0;
  color: var(--gold);
}

.memory-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.memory-category {
  color: var(--jade);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.6rem;
}

.memory-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  background: var(--ink);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font-size: 0.9rem;
}

.memory-item button {
  background: transparent;
  border: none;
  color: #e88b4b;
  cursor: pointer;
  flex-shrink: 0;
}

.danger-btn {
  background: transparent;
  border: 1px solid #e88b4b;
  color: #e88b4b;
  padding: 0.6rem;
  border-radius: 8px;
  cursor: pointer;
}

@media (min-width: 640px) {
  .screen {
    max-width: 720px;
    margin: 0 auto;
  }
}
