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

:root {
  --bg: #f3efe9;
  --surface: #ffffff;
  --border: #ddd6cc;
  --text: #2a2a35;
  --dim: #9a9a9a;
  --accent: #d63a50;
  --accent-glow: rgba(214, 58, 80, 0.15);
  --user-bubble: #ebe4f2;
  --radius: 12px;
}

html, body {
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 680px;
  margin: 0 auto;
  overflow: hidden;
}

header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  background: var(--surface);
}

.logo {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
  text-shadow: 0 0 12px var(--accent-glow);
  flex: 1;
}

.btn-dl {
  padding: 8px 16px;
  border-radius: 22px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s, color 0.2s;
}

.btn-chats {
  padding: 8px 14px;
  margin-right: 7px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.2s, color 0.2s;
}

.btn-chats:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-dl:hover {
  background: var(--accent);
  color: #fff;
}

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-history {
  position: absolute;
  z-index: 2;
  inset: 57px 0 69px;
  max-width: 680px;
  margin: 0 auto;
  overflow-y: auto;
  padding: 18px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 12px 24px rgba(42, 42, 53, 0.12);
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.history-close {
  border: 0;
  background: transparent;
  color: var(--dim);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.history-close:hover { color: var(--accent); }

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-message {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.history-message.ai {
  background: #eee9e2;
  color: #3a3a45;
}

.history-message.user {
  background: var(--user-bubble);
  color: var(--text);
}

.history-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  opacity: 0.6;
}

.history-empty {
  color: var(--dim);
  font-size: 13px;
}

.msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.55;
  animation: fadeIn 0.25s ease;
}

.msg.ai {
  align-self: flex-start;
  background: #eee9e2;
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: #3a3a45;
}

.msg.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
  color: #2a2a35;
}

.msg .label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  margin-bottom: 4px;
  opacity: 0.6;
}

.msg.typing {
  opacity: 0.5;
}

.input-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.input-bar input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.input-bar input:focus {
  border-color: var(--accent);
}

.btn-send {
  padding: 10px 20px;
  border-radius: 22px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-send:hover { opacity: 0.85; }
.btn-send:disabled { opacity: 0.4; cursor: default; }

.btn-roast {
  padding: 10px 16px;
  border-radius: 22px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s, color 0.2s;
}

.btn-roast:hover {
  background: var(--accent);
  color: #fff;
}
.btn-roast:disabled { opacity: 0.4; cursor: default; }

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

/* scrollbar */
.chat::-webkit-scrollbar { width: 5px; }
.chat::-webkit-scrollbar-track { background: transparent; }
.chat::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

@media (max-width: 480px) {
  html, body {
    height: 100dvh;
  }

  .app {
    height: 100dvh;
  }

  header {
    padding: 10px 12px;
  }

  .chat {
    padding: 12px 10px;
    gap: 8px;
  }

  .msg {
    max-width: 92%;
    font-size: 13px;
    padding: 8px 12px;
  }

  .input-bar {
    padding: 8px 10px;
    gap: 5px;
  }

  .input-bar input {
    min-width: 0;
    padding: 8px 12px;
    font-size: 16px;
  }

  .btn-send {
    padding: 8px 12px;
    font-size: 11px;
  }

  .btn-roast {
    padding: 8px 10px;
    font-size: 10px;
  }

  .btn-dl {
    padding: 6px 10px;
    font-size: 11px;
  }

  .btn-chats {
    padding: 6px 10px;
    margin-right: 4px;
    font-size: 11px;
  }

  .chat-history {
    inset: 48px 0 57px;
    padding: 14px 10px;
  }
}
