:root {
  --bg-deep: #0B1220;
  --bg-panel: #111A2B;
  --bg-card: #17283A;
  --border-color: #1E2C42;
  --text-main: #DCE6F2;
  --text-muted: #6B7C93;
  --text-bright: #FFFFFF;
  --teal-accent: #4FD1C5;
  --teal-dark: #0F2A2C;
  --gold-accent: #E8A33D;
  --red-accent: #E05252;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --font-heading: 'Oswald', sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  background-color: var(--bg-deep);
  color: var(--text-main);
  font-family: var(--font-sans);
  overflow: hidden;
}

/* HABITAT SHELL & LAYOUT */
.habitat-shell {
  display: flex;
  width: 100%;
  height: 100%;
  height: 100dvh;
  position: relative;
}

/* THREAD DRAWER (SIDEBAR) */
.thread-drawer {
  width: 300px;
  height: 100%;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.25s ease;
}

@media (max-width: 768px) {
  .thread-drawer {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: 4px 0 25px rgba(0,0,0,0.5);
  }

  .thread-drawer.open {
    transform: translateX(0);
  }
}

.drawer-backdrop {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(5, 8, 14, 0.7);
  z-index: 90;
}

.drawer-backdrop.open {
  display: block;
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border-color);
}

.drawer-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.drawer-title .mark {
  color: var(--gold-accent);
  font-size: 1.2rem;
}

.drawer-title h2 {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  color: var(--text-main);
}

.drawer-actions {
  padding: 1rem 1.2rem;
}

.thread-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.thread-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  background: transparent;
  color: var(--text-main);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s;
}

.thread-item:hover {
  background: #172436;
}

.thread-item.active {
  background: var(--teal-dark);
  border-color: var(--teal-accent);
  color: var(--teal-accent);
  font-weight: 500;
}

.thread-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  overflow: hidden;
}

.thread-title-text {
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.thread-del-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 4px;
  cursor: pointer;
  opacity: 0.6;
}

.thread-del-btn:hover {
  color: var(--red-accent);
  opacity: 1;
}

.drawer-footer {
  padding: 1rem 1.2rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.back-link {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-decoration: none;
  text-align: center;
}

.back-link:hover {
  color: var(--teal-accent);
}

/* MAIN HABITAT */
.habitat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  position: relative;
  overflow: hidden;
}

/* HEADER */
.habitat-header {
  height: 56px;
  padding: 0 1rem;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-anchor {
  color: var(--gold-accent);
  font-size: 1.2rem;
}

.brand-text h1 {
  font-family: var(--font-heading);
  font-size: 1rem;
  letter-spacing: 0.08em;

  color: var(--text-main);
  line-height: 1;
}

.status-badge {
  font-size: 0.65rem;
  color: var(--teal-accent);
  letter-spacing: 0.06em;
  font-weight: 600;
}

.status-badge .dot {
  font-size: 0.6rem;
}

/* FEED CONTAINER */
.feed-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.feed-content {
  width: 100%;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  padding-bottom: 1rem;
}

/* MESSAGES */
.message-bubble {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-width: 90%;
  animation: fadeIn 0.2s ease;
}

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

.message-bubble.admiral {
  align-self: flex-end;
}

.message-bubble.captain {
  align-self: flex-start;
  max-width: 100%;
}

.message-speaker {
  font-family: var(--font-heading);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.message-bubble.admiral .message-speaker {
  color: var(--teal-accent);
  align-self: flex-end;
}

.message-bubble.captain .message-speaker {
  color: var(--gold-accent);
}

.message-body {
  padding: 0.9rem 1.1rem;
  border-radius: 12px;
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-bubble.admiral .message-body {
  background: var(--teal-dark);
  border: 1px solid var(--teal-accent);
  color: var(--text-bright);
  border-top-right-radius: 2px;
}

.message-bubble.captain .message-body {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-top-left-radius: 2px;
}

/* TOOL EVENTS DISPLAY */
.tool-event-badge {
  background: #0d1a29;
  border: 1px solid #1e324a;
  border-radius: 6px;
  padding: 0.4rem 0.7rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--teal-accent);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
  cursor: pointer;
}

.tool-event-summary {
  font-weight: 500;
}

/* CODE BLOCKS */
pre {
  background: #060a12;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.8rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  margin: 0.6rem 0;
}

code {
  font-family: var(--font-mono);
  background: rgba(255,255,255,0.06);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}

/* COMPOSER STAGE (Fixed for Gboard) */
.composer-stage {
  padding: 0.8rem 1rem;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
  width: 100%;
  display: flex;
  justify-content: center;
}

.composer-form {
  width: 100%;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.attachment-preview {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-card);
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--teal-accent);
  width: fit-content;
}

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  background: var(--bg-deep);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 0.4rem 0.6rem;
}

.composer-box:focus-within {
  border-color: var(--teal-accent);
}

textarea#composerInput {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.4;
  resize: none;
  max-height: 140px;
  min-height: 24px;
  padding: 0.4rem 0.2rem;
  outline: none;
}

/* BUTTONS */
.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 8px;
}

.icon-btn:hover {
  color: var(--text-main);
  background: rgba(255,255,255,0.05);
}

.send-btn {
  background: var(--teal-accent);
  color: #05201D;
  border: none;
  min-width: 38px;
  min-height: 38px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: bold;
}

.send-btn:hover {
  background: #38bdf8;
}

.btn {
  padding: 0.6rem 1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.btn-primary { background: var(--teal-accent); color: #05201D; }
.btn-primary:hover { background: #38bdf8; }
.btn-danger { background: var(--red-accent); color: white; }
.btn-subtle { background: #172436; color: var(--text-main); border: 1px solid var(--border-color); }
.btn-full { width: 100%; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }

/* HEART DIALOG */
.heart-dialog {
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--bg-panel);
  color: var(--text-main);
  width: min(560px, 94vw);
  max-height: 80vh;
  margin: auto;
  padding: 0;
  box-shadow: 0 10px 30px rgba(0,0,0,0.7);
}

.heart-dialog::backdrop { background: rgba(5,8,14,0.8); }

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border-color);
}

.dialog-header h3 {
  font-family: var(--font-heading);
  font-size: 1rem;
  color: var(--gold-accent);
}

.dialog-body {
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: 65vh;
  overflow-y: auto;
}

.dialog-hint { font-size: 0.85rem; color: var(--text-muted); }

.heart-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.heart-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.7rem;
  font-size: 0.85rem;
}

.add-heart-box {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
  border-top: 1px solid var(--border-color);
  padding-top: 1rem;
}

.add-heart-box textarea {
  background: var(--bg-deep);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 6px;
  padding: 0.6rem;
  font-family: inherit;
}
