/* =========================================================
   MAIN — PAGE STRUCTURE & CONTENT (VARIABLE-BASED THEME)
   ========================================================= */

/* ---------------------------------------------------------
   Global Reset + Typography
--------------------------------------------------------- */
html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, sans-serif;
  font-size: var(--base-font);
  line-height: var(--line-height);
  height: 100%;
  overflow: auto;
}

body {
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

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

/* While dragging the splitter: no text selection, consistent cursor */
body.is-resizing {
  user-select: none;
  -webkit-user-select: none;
  cursor: ns-resize;
}

/* ---------------------------------------------------------
   Hide Prompts / Hide Responses
   "Prompts" = the interviewer's questions, "Responses" = your answers.
--------------------------------------------------------- */
body.hide-prompts .ai-msg {
  display: none;
}

body.hide-responses .user-msg {
  display: none;
}

/* ---------------------------------------------------------
   Voice: listening indicator (Manual mode's mic button)
--------------------------------------------------------- */
#voice-btn.listening {
  background: var(--btn-danger-bg);
  color: var(--btn-danger-text);
}

/* ---------------------------------------------------------
   Settings modal
   (Self-contained: main.css doesn't have visibility into
   modals.css, so this modal styles itself rather than
   assuming shared rules for #identity-modal apply here too.)
--------------------------------------------------------- */
#settings-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 4000;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
}

#settings-modal.open {
  display: flex;
}

#settings-modal-inner {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--bg);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  padding-top: max(var(--space-lg), env(safe-area-inset-top, 0px));
  padding-bottom: max(var(--space-lg), env(safe-area-inset-bottom, 0px));
}

#settings-close-btn {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text);
  padding: var(--space-xs);
}

#settings-modal h3 {
  margin-top: 0;
}

#settings-modal h4 {
  margin: var(--space-md) 0 var(--space-sm);
  font-size: var(--font-scale-md);
  color: var(--text);
  opacity: 0.8;
}

#settings-display-section .identity-row {
  gap: var(--gap-sm);
}

#settings-display-section #hide-prompts-btn,
#settings-display-section #hide-responses-btn {
  min-height: 44px;
}

.settings-checkbox-row {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  margin: var(--space-md) 0;
  font-size: var(--font-scale-sm);
}

.settings-checkbox-row input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
  flex-shrink: 0;
}

#voice-input-mode-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
}

#voice-input-mode-group label {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  font-size: var(--font-scale-sm);
}

#voice-input-mode-group input[type="radio"] {
  width: 1.15rem;
  height: 1.15rem;
  flex-shrink: 0;
}

/* ---------------------------------------------------------
   Splash Gating — UI hidden until JS unhides
--------------------------------------------------------- */
#top-bar,
main {
  display: none;
}

/* ---------------------------------------------------------
   Top Bar
   (Converted to neutral variables: bar-bg, bar-border, bar-text)
--------------------------------------------------------- */
#top-bar {
  position: fixed;
  top: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  background: var(--bar-bg);
  border-bottom: 1px solid var(--bar-border);
  opacity: 1;
  color: var(--bar-text);
  z-index: 2000;
}

#top-left,
#top-right {
  display: flex;
  align-items: center;
  gap: var(--gap-md);
}

#identity-btn {
    padding-bottom: 15px;
}

#sidebar-toggle {
  background: none;
  border: none;
  font-size: 1.8rem;
  padding: var(--space-xxs) var(--space-xs);
  color: inherit;
  z-index: 2000;
}

#app-title {
  margin-right: var(--space-md);
  font-weight: 500;
  font-size: 1.25rem;
  letter-spacing: 0.5px;
  font-family: "Segoe UI", "Inter", sans-serif;
}

#new-story-btn {
  margin-top: 20px;
  margin-bottom: 15px;
}

/* ---------------------------------------------------------
   Buttons (Global)
   (Already neutral — no theme selectors needed)
--------------------------------------------------------- */
button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius-md);
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-scale-md);
  transition: filter 0.15s ease;
}

button:hover {
  filter: brightness(1.08);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: none;
}

.btn-primary {
  background: var(--btn-bg);
  color: var(--btn-text);
}

.btn-primary:hover {
  background: var(--btn-bg-hover);
}

.btn-muted {
  background: var(--btn-muted-bg);
  color: var(--btn-muted-text);
}

.btn-muted:hover {
  background: var(--btn-muted-hover);
}

.btn-danger {
  background: var(--btn-danger-bg);
  color: var(--btn-danger-text);
}

.btn-danger:hover {
  background: var(--btn-danger-hover);
}

.btn-success {
  background: var(--btn-success-bg);
  color: var(--btn-success-text);
}

.btn-success:hover {
  background: var(--btn-success-hover);
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--bar-text);
}

.icon-btn:hover {
  opacity: 0.7;
}

/* ---------------------------------------------------------
   Main Area
--------------------------------------------------------- */
main {
  display: flex;
  flex: 1;
  min-height: 0;
  width: 90%;
  margin: 0 auto;
}

main > section {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ---------------------------------------------------------
   Conversation Column
--------------------------------------------------------- */
.conversation {
  display: flex;
  flex-direction: column;
  flex: 1;
  flex-shrink: 0;
  min-height: 0;
  max-width: 900px;
  margin: 0 auto;
  max-height: 100%;
  width: 100%;
}

/* ---------------------------------------------------------
   Story Header
--------------------------------------------------------- */
#story-header h2 {
  margin: 0 0 var(--space-md) 0;
  font-size: var(--font-scale-lg);
  font-weight: 500;
  margin-top: 100px;
  color: var(--text);
}

/* ---------------------------------------------------------
   Messages
   Takes whatever height the splitter and input area leave over.
--------------------------------------------------------- */
#messages {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  padding-right: var(--space-sm);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ---------------------------------------------------------
   Splitter
   A 14px-tall grab area (28px on touch screens) with a thin
   line and a small grip drawn inside it.
--------------------------------------------------------- */
#splitter {
  position: relative;
  flex: 0 0 14px;
  height: 14px;
  margin: 0;
  cursor: ns-resize;
  touch-action: none;      /* lets a finger drag it instead of scrolling the page */
  user-select: none;
  -webkit-user-select: none;
}

#splitter::before {        /* the line */
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  transform: translateY(-50%);
  background: var(--bar-border);
  border-radius: 2px;
}

#splitter::after {         /* the grip */
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 4px;
  transform: translate(-50%, -50%);
  background: var(--bar-text);
  opacity: 0.35;
  border-radius: 2px;
}

#splitter:hover::after,
#splitter:focus-visible::after,
body.is-resizing #splitter::after {
  background: var(--btn-bg);
  opacity: 1;
}

#splitter:focus-visible {
  outline: none;
}

@media (pointer: coarse) {
  #splitter {
    flex-basis: 28px;
    height: 28px;
  }
}

/* ---------------------------------------------------------
   Message Bubbles
   (Converted to neutral variables: bubble-user-bg, bubble-ai-bg)
--------------------------------------------------------- */
.user-msg,
.ai-msg,
.thinking-msg {
  width: 100%;
  margin: var(--space-sm) 0;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.user-msg {
  background: var(--bubble-user-bg);
}

.ai-msg {
  background: var(--bubble-ai-bg);
}

.thinking-msg {
  background: transparent;
  opacity: 0.7;
  font-style: italic;
  max-width: 75%;
  margin-left: auto;
  margin-right: auto;
  color: var(--text);
}

/* ---------------------------------------------------------
   Message Bar
   (Converted to neutral variables: bar-bg, bar-border)
--------------------------------------------------------- */
.message-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--gap-sm);
  height: 2rem;
  padding: var(--space-xs) var(--space-sm);
  background: var(--bar-bg);
  border-bottom: 1px solid var(--bar-border);
}

.msg-label {
  margin-right: auto;
  opacity: 0.7;
  font-size: var(--font-scale-sm);
  font-weight: 500;
  color: var(--text);
}

.tts-btn, .edit-btn {
  background: none;
}

/* ---------------------------------------------------------
   Message Text
--------------------------------------------------------- */
.message-text {
  padding: var(--space-sm) var(--space-md);
  white-space: pre-wrap;
  color: var(--text);
  min-width: 0;
}

/* ---------------------------------------------------------
   Input Area
   Height comes from --input-h (set by the splitter), with limits.
   Layout: textarea on top, then [mic][Send], then the two
   secondary buttons.
--------------------------------------------------------- */
#input-area {
  flex: 0 1 var(--input-h, 240px);
  min-height: 170px;
  max-height: 70%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
  padding-bottom: max(var(--space-sm), env(safe-area-inset-bottom, 0px));
  background: var(--bg);
}

#input-form {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  display: grid;
  grid-template-columns: 1fr max-content;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: var(--gap-sm);
}

#user-input {
  grid-column: 1 / -1;
  grid-row: 1;
  min-height: 0;
  resize: none;              /* the splitter controls the size now */
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-md);
  background: var(--bubble-user-bg);
  color: var(--text);
  font: inherit;
  line-height: 1.4;
}

#user-input::placeholder {
  color: var(--text);
  opacity: 0.5;
}

#user-input:focus {
  outline: none;
  border-color: var(--btn-bg);
}

#input-form .btn-primary {
  grid-column: 1;
  grid-row: 2;
  min-height: 44px;
  width: 100%;
  font-weight: 500;
}

#voice-btn {
  grid-column: 2;
  grid-row: 2;
  width: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 1.25rem;
  background: var(--btn-muted-bg);
  border-radius: var(--radius-md);
}

/* ---------------------------------------------------------
   Redirect Buttons
--------------------------------------------------------- */
#bottom-buttons {
  display: flex;
  gap: var(--gap-sm);
  flex: none;
}

#bottom-buttons button {
  flex: 1 1 0;
  min-height: 40px;
  font-size: var(--font-scale-sm);
}

/* ---------------------------------------------------------
   Memoir overlay layout
   (Prefixed with #memoir-overlay so these win over any older
   memoir rules in modals.css.)
--------------------------------------------------------- */
#memoir-overlay #memoir-container {
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
}

#memoir-overlay #memoir-title {
  flex: none;
  margin: 0;
}

#memoir-overlay #memoir-editor {
  flex: 1 1 auto;
  min-height: 45vh;
  width: 100%;
  resize: none;
  padding: var(--space-md);
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-md);
  background: var(--bubble-user-bg);
  color: var(--text);
  font: inherit;
  line-height: 1.5;
}

#memoir-overlay #memoir-editor:focus {
  outline: none;
  border-color: var(--btn-bg);
}

#memoir-overlay #memoir-editor:disabled {
  opacity: 0.7;
}

/* Revise: instruction box + Revise + Undo */
#memoir-overlay #memoir-revise-row {
  display: flex;
  gap: var(--gap-sm);
  flex: none;
}

#memoir-overlay #memoir-revise-input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  padding: 0 var(--space-md);
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-md);
  background: var(--bubble-user-bg);
  color: var(--text);
  font: inherit;
}

#memoir-overlay #memoir-revise-input::placeholder {
  color: var(--text);
  opacity: 0.5;
}

#memoir-overlay #memoir-revise-input:focus {
  outline: none;
  border-color: var(--btn-bg);
}

#memoir-overlay #memoir-revise-row button {
  flex: none;
  min-height: 44px;
}

/* Options (notes toggle + regenerate) and actions (save / download / export / close) */
#memoir-overlay #memoir-buttons {
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
  flex: none;
}

#memoir-overlay #memoir-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap-sm);
}

#memoir-overlay #memoir-options label {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  font-size: var(--font-scale-sm);
  color: var(--text);
}

#memoir-overlay #memoir-options input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
}

#memoir-overlay #memoir-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-sm);
}

#memoir-overlay #memoir-actions button {
  flex: 1 1 auto;
  min-height: 44px;
}

/* ---------------------------------------------------------
   Splash Screen
   (Already neutral variables)
--------------------------------------------------------- */
#splash-screen {
  position: fixed;
  inset: 0;
  background: var(--splash-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl) var(--space-lg);
  text-align: center;
  z-index: 5000;
}

#splash-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap-md);
}

#splash-loading {
  margin-top: 12px;
  opacity: 0.8;
}

#splash-silhouette {
  width: 200px;
  opacity: var(--silhouette-opacity);
  filter: grayscale(100%);
  margin-bottom: var(--space-lg);
}

#splash-title {
  font-size: var(--font-scale-xl);
  color: var(--splash-title);
  margin: 0;
}

#splash-subtitle {
  font-size: var(--font-scale-md);
  color: var(--splash-subtitle);
  margin-top: var(--space-sm);
  margin-bottom: var(--space-xl);
}

#splash-buttons {
  display: flex;
  flex-direction: column;
  gap: var(--gap-md);
  width: 240px;
}

#splash-footer {
  margin-top: var(--space-xl);
  font-size: var(--font-scale-sm);
  opacity: 0.6;
}

@keyframes splashFadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

.splash-hide {
  animation: splashFadeOut 6s ease forwards;
}
/* ---------------------------------------------------------
   Media Query
   Replace text title with icon on phones
--------------------------------------------------------- */
@media (max-width: 399px) {
  #app-title {
    /*  Display the icon instead of text */
    background-image: url('/assets/icons/favicon-32.png');
    background-size: contain;
    background-repeat: no-repeat;
    width: 24px; /* Adjust width as needed */
    height: 24px; /* Adjust height as needed */
    display: inline-block; /* Make it behave like an image */
    padding-right: 24px;
    color: transparent;
  }
}
