/* ==========================================================
   HAVEN — style.css
   Theme system via CSS variables + Flexbox/Grid layout
   ========================================================== */

:root {
  --font-display: Georgia, 'Times New Roman', serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --radius: 14px;
  --transition-theme: background-color 0.6s ease, color 0.6s ease,
                       border-color 0.6s ease, box-shadow 0.6s ease;
}

/* ---------- THEME: OBSIDIAN (default) ---------- */
:root,
[data-theme="obsidian"] {
  --bg: #14171c;
  --bg-elevated: #1c2028;
  --text: #e7e9ee;
  --text-muted: #8b93a3;
  --accent: #4c7ea8;
  --accent-soft: #34506b;
  --border: #2a2f3a;
  --danger: #b3564a;
  --bubble-user: #2a3340;
  --bubble-ai: #1c2028;
}

/* ---------- THEME: SERENE ---------- */
[data-theme="serene"] {
  --bg: #eef4f1;
  --bg-elevated: #ffffff;
  --text: #263a34;
  --text-muted: #698a7f;
  --accent: #6fa98f;
  --accent-soft: #bcded0;
  --border: #d6e6de;
  --danger: #c17a5c;
  --bubble-user: #cfe6db;
  --bubble-ai: #ffffff;
}

/* ---------- THEME: RAW ---------- */
[data-theme="raw"] {
  --bg: #17181a;
  --bg-elevated: #211618;
  --text: #f1e9e8;
  --text-muted: #a68887;
  --accent: #a4342a;
  --accent-soft: #5e211c;
  --border: #3a2224;
  --danger: #d1483a;
  --bubble-user: #3a1e1c;
  --bubble-ai: #211618;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  transition: var(--transition-theme);
}

.screen { min-height: 100vh; }

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---------- BUTTONS ---------- */
.btn {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.7rem 1.4rem;
  font-size: 0.95rem;
  transition: var(--transition-theme), transform 0.15s ease, opacity 0.2s ease;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: var(--bg);
}
.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: var(--bg); }

/* ==========================================================
   PREPARATION SCREEN
   ========================================================== */
#prep-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  text-align: center;
  padding: 2rem;
}

.orb {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--accent), var(--accent-soft) 70%);
  animation: breathe 3.2s ease-in-out infinite;
  box-shadow: 0 0 40px var(--accent-soft);
}
@keyframes breathe {
  0%, 100% { transform: scale(0.9); opacity: 0.85; }
  50% { transform: scale(1.15); opacity: 1; }
}

.prep-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 2.4rem;
  letter-spacing: 0.04em;
  margin: 0;
}
.prep-status {
  color: var(--text-muted);
  font-size: 0.95rem;
  min-height: 1.2em;
}

/* ==========================================================
   OVERLAYS (T&C + Policy)
   ========================================================== */
.overlay[hidden],
.screen[hidden] {
  display: none !important;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
  z-index: 50;
}

.tc-card, .policy-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.8rem;
  max-width: 640px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  transition: var(--transition-theme);
}

.tc-card h2 {
  font-family: var(--font-display);
  margin-top: 0;
}
.tc-intro { color: var(--text-muted); }

.tc-columns {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.2rem;
  margin: 1.2rem 0;
}
@media (min-width: 620px) {
  .tc-columns { grid-template-columns: 1fr 1fr; }
}
.tc-col h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 0.6rem;
}
.tc-col ul { padding-left: 1.1rem; margin: 0; }
.tc-col li { margin-bottom: 0.6rem; font-size: 0.92rem; line-height: 1.4; }

.tc-agree {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.92rem;
  margin-bottom: 1.2rem;
  cursor: pointer;
}

.policy-card { text-align: center; }
.policy-card p { line-height: 1.5; }

/* ==========================================================
   MAIN APP
   ========================================================== */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
}
.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
}

.theme-picker {
  display: flex;
  gap: 0.5rem;
}
.theme-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
  padding: 0;
}
.theme-swatch[data-theme="obsidian"] { background: linear-gradient(135deg, #14171c, #4c7ea8); }
.theme-swatch[data-theme="serene"]   { background: linear-gradient(135deg, #eef4f1, #6fa98f); }
.theme-swatch[data-theme="raw"]      { background: linear-gradient(135deg, #17181a, #a4342a); }
.theme-swatch.active { border-color: var(--accent); }

/* ---------- CHAT ---------- */
.chat-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 0 1rem;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding: 1.2rem 0;
}

.msg {
  max-width: 80%;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  line-height: 1.45;
  font-size: 0.96rem;
  transition: var(--transition-theme);
}
.msg-user {
  align-self: flex-end;
  background: var(--bubble-user);
  border-bottom-right-radius: 4px;
}
.msg-ai {
  align-self: flex-start;
  background: var(--bubble-ai);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

/* typing indicator: three breathing dots while a reply is "composed" */
.msg.typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0.85rem 1.1rem;
}
.msg.typing .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing-bounce 1.1s infinite ease-in-out;
}
.msg.typing .dot:nth-child(2) { animation-delay: 0.15s; }
.msg.typing .dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* blinking caret while a reply is being typed out character by character */
.msg-text:not(:empty)::after {
  content: "";
}

.chat-form {
  display: flex;
  gap: 0.6rem;
  padding: 0.8rem 0;
  border-top: 1px solid var(--border);
}
.chat-input {
  flex: 1;
  resize: none;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  font-family: inherit;
  font-size: 0.95rem;
  max-height: 140px;
  transition: var(--transition-theme);
}
.chat-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.session-note {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  padding-bottom: 0.6rem;
}

/* ==========================================================
   RESPONSIVE BREAKPOINTS
   ========================================================== */
@media (min-width: 768px) {
  .app-header { padding: 1.1rem 2rem; }
  .chat-wrap { padding: 0 1.5rem; }
}

@media (min-width: 1024px) {
  .chat-wrap { max-width: 860px; }
}

@media (prefers-reduced-motion: reduce) {
  .orb { animation: none; }
  * { transition-duration: 0.01ms !important; }
}
