:root {
  --bg: #000000;
  --text: #e0e0e0;
  --accent: #8b0000;
  --scarlet: #c41e3a;
  --user: #2f4f4f;
  --tomb: #1a0000;
  --stone: #808080;
}

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

body {
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  background: linear-gradient(to bottom, #0a0a0a, #000000);
  border: 1px solid var(--accent);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(139, 0, 0, 0.3);
  position: relative;
  max-height: 100dvh;
}

h1 {
  text-align: center;
  color: var(--stone);
  margin: 12px 0 8px;
  font-family: 'Old English Text MT', 'Times New Roman', serif;
  font-weight: normal;
  z-index: 10;
  font-size: 2rem;
}

/* Chat messages — extra bottom padding for keyboard/safe area */
.chat-messages {
  flex: 1;
  padding: 16px 16px 120px 16px; /* big bottom padding for keyboard overlap */
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #000000;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding-bottom: calc(80px + env(safe-area-inset-bottom)); /* extra iOS space */
}

.chat-messages::-webkit-scrollbar {
  display: none;
}

/* User messages on RIGHT */
.user-message {
  align-self: flex-end;
  background: var(--user);
  color: #e0e0e0;
  text-align: right;
}

/* AI messages on LEFT */
.ai-message {
  align-self: flex-start;
  background: rgba(139, 0, 0, 0.35);
  border: 1px solid var(--accent);
  color: #ffdada;
  box-shadow: 0 0 12px rgba(139, 0, 0, 0.5);
  text-align: left;
}

/* Fixed input bar — always at bottom, extra space for iOS keyboard */
.input-area {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  padding: 12px;
  background: var(--tomb);
  border-top: 1px solid var(--accent);
  z-index: 1000; /* high z-index to stay on top */
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 10px rgba(0,0,0,0.5); /* subtle shadow for separation */
}

/* Adjust input area on larger screens */
@media (min-width: 801px) {
  .input-area {
    left: 50%;
    transform: translateX(-50%);
    width: 800px;
  }
}

#user-input {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--accent);
  border-radius: 8px 0 0 8px;
  background: #0d0d0d;
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

#send-btn {
  padding: 0 20px;
  background: var(--scarlet);
  color: white;
  border: none;
  border-radius: 0 8px 8px 0;
  cursor: pointer;
  font-family: Arial, Helvetica, sans-serif;
}

#send-btn:hover {
  background: #a1122a;
}

/* Mobile & tablet fixes — extra keyboard handling */
@media (max-width: 1024px) {
  .container {
    border-radius: 0;
    height: 100dvh;
    max-height: 100dvh;
  }
  h1 {
    font-size: 1.8rem;
    margin: 8px 0;
  }
  .chat-messages {
    padding: 12px 12px 140px 12px; /* even more bottom space for iOS keyboard */
  }
  .message {
    max-width: 90%;
  }
  .input-area {
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 600px) {
  h1 {
    font-size: 1.6rem;
  }
  .input-area {
    padding: 8px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
  #user-input {
    padding: 10px;
  }
}

/* Force input visible when keyboard is open (iOS/Android) */
@media (orientation: portrait) and (max-height: 800px) {
  .input-area {
    position: fixed !important;
    bottom: env(safe-area-inset-bottom) !important;
  }
  .chat-messages {
    padding-bottom: 160px !important; /* aggressive bottom space for keyboard */
  }
}
/* Extra aggressive bottom space on iPhone-like devices */
@media (max-width: 500px) and (max-height: 900px) {
  .chat-messages {
    padding-bottom: 200px !important; /* forces more space for keyboard */
  }
  .input-area {
    padding-bottom: calc(20px + env(safe-area-inset-bottom)) !important;
  }
}