/* NULLWOOD — Visual System */

:root {
  --bg: #0A0A0A;
  --text: #F0EDE8;
  --amber: #C8A96E;
  --dim: #8B7355;
  --ghost: #6B6058;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  background: #0A0A0A;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
  padding: 0;
}

h1, h2, h3 {
  font-family: Georgia, 'Times New Roman', serif;
  font-weight: 400;
  color: var(--amber);
}

a {
  color: var(--amber);
  text-decoration: none;
}

a:hover {
  color: var(--text);
}

/* ---- Layout ---- */

.page {
  max-width: 600px;
  margin: 0 auto;
  padding: 80px 24px;
}

/* Chat-active layout: pin input at bottom */
body.chat-active {
  overflow: hidden;
  height: 100vh;
}
body.chat-active .page {
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 12px 16px 0;
  max-width: 100%;
  box-sizing: border-box;
}
body.chat-active #chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* ---- Field Manual ---- */

.field-manual p {
  margin-bottom: 1.8em;
  font-size: 1rem;
  line-height: 1.7;
  color: var(--text);
}

.field-manual .separator {
  color: var(--dim);
  margin: 2.4em 0;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.15em;
}

/* ---- Draw Button ---- */

.draw-btn {
  display: block;
  margin: 60px auto 0;
  background: none;
  border: 1px solid var(--dim);
  color: var(--amber);
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.1rem;
  font-weight: 500;
  letter-spacing: 0.25em;
  padding: 14px 48px;
  cursor: pointer;
  transition: border-color 0.3s, color 0.3s;
}

.draw-btn:hover {
  border-color: var(--amber);
  color: var(--text);
}

/* ---- Card Display ---- */

.card-display {
  border: 1px solid var(--dim);
  padding: 40px 32px;
  margin: 40px 0;
}

.card-display .card-name {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.4rem;
  color: var(--amber);
  margin-bottom: 8px;
}

.card-display .card-axis {
  font-size: 0.85rem;
  color: var(--dim);
  font-weight: 600;
  letter-spacing: 0.1em;
  margin-bottom: 24px;
}

.card-display .card-field {
  margin-bottom: 16px;
}

.card-display .card-field-label {
  font-size: 0.75rem;
  color: var(--dim);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 4px;
}

.card-display .card-field-value {
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.6;
}

/* ---- Dialogue ---- */

.dialogue-container {
  margin: 40px 0;
}
body.chat-active .dialogue-container {
  flex: 1;
  overflow-y: auto;
  margin: 0;
  min-height: 0;
}

.message {
  margin-bottom: 28px;
  padding-bottom: 28px;
  border-bottom: 1px solid #1a1a1a;
}

.message:last-child {
  border-bottom: none;
}

.message-role {
  font-size: 0.7rem;
  color: var(--dim);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-bottom: 8px;
}

.message-text {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text);
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.message-text.agent {
  color: var(--amber);
}

.dialogue-input {
  display: flex;
  gap: 12px;
  margin-top: 0;
  border-top: 1px solid var(--ghost);
  padding: 16px 0;
  flex-shrink: 0;
}

.dialogue-input textarea {
  flex: 1;
  background: none;
  border: 1px solid var(--dim);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  padding: 12px;
  resize: none;
  min-height: 60px;
  line-height: 1.5;
}

.dialogue-input textarea:focus {
  outline: none;
  border-color: var(--amber);
}

.dialogue-input button {
  background: none;
  border: 1px solid var(--dim);
  color: var(--amber);
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.15em;
  padding: 12px 24px;
  cursor: pointer;
  align-self: flex-end;
  transition: border-color 0.3s, color 0.3s;
}

.dialogue-input button:hover {
  border-color: var(--amber);
  color: var(--text);
}

/* ---- Stage Indicator ---- */

.stage-indicator {
  position: fixed;
  bottom: 16px;
  right: 20px;
  font-size: 0.7rem;
  color: var(--dim);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ---- Loading ---- */

.loading {
  color: var(--dim);
  font-size: 0.85rem;
  font-weight: 500;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* ---- Thinking Indicator ---- */

.thinking-indicator {
  display: none;
  color: var(--dim);
  font-size: 0.8rem;
  padding: 12px 0;
  font-style: italic;
}

.thinking-indicator.active {
  display: block;
}

.thinking-indicator .dots {
  display: inline-block;
}

.thinking-indicator .dots span {
  animation: dotPulse 1.4s infinite both;
  opacity: 0.3;
}

.thinking-indicator .dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-indicator .dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.3; }
  40% { opacity: 1; }
}

/* ---- Thinking Content (collapsible) ---- */

.thinking-block {
  margin-bottom: 4px;
  border-left: 2px solid var(--ghost);
  padding-left: 12px;
}
.thinking-block:has(.thinking-content:not(.expanded)) {
  margin-bottom: 2px;
  border-left-color: transparent;
}

.thinking-toggle {
  cursor: pointer;
  font-size: 0.7rem;
  color: var(--ghost);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  user-select: none;
  margin-bottom: 6px;
}

.thinking-toggle:hover {
  color: var(--dim);
}

.thinking-content {
  display: none;
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--ghost);
  white-space: pre-wrap;
  word-break: break-word;
}

.thinking-content.expanded {
  display: block;
}

body.chat-active #card-header {
  flex-shrink: 0;
}
body.chat-active .dialogue-input {
  flex-shrink: 0;
}

/* ============================================================
   MOBILE RESPONSIVE — screens under 768px
   ============================================================ */
@media (max-width: 768px) {
  /* Sidebar: full-width overlay instead of partial */
  #chat-sidebar {
    width: 100% !important;
    padding-top: 12px;
  }
  /* Don't shift page on mobile — sidebar overlays */
  .page.shifted {
    margin-left: 0 !important;
  }

  /* Sidebar toggle: bigger tap target */
  #sidebar-toggle {
    font-size: 1.5rem;
    padding: 8px;
    top: 8px;
    left: 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex !important;
    align-items: center;
    justify-content: center;
  }

  /* Top-right controls: stack vertically, bigger targets */
  #token-counter {
    top: 8px;
    right: 48px;
    font-size: 0.6rem;
    max-width: calc(100vw - 120px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #tts-toggle {
    top: 8px;
    right: 8px;
    font-size: 1.2rem;
    min-width: 44px;
    min-height: 44px;
    display: flex !important;
    align-items: center;
    justify-content: center;
  }

  /* Stage indicator: bottom-left on mobile to avoid input overlap */
  .stage-indicator {
    bottom: auto;
    top: 8px;
    right: auto;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.6rem;
  }

  /* Page layout: tighter padding */
  .page {
    padding: 60px 12px 12px;
  }
  body.chat-active .page {
    padding: 48px 8px 0;
    max-width: 100%;
  }

  /* Chat area fills screen */
  body.chat-active #chat-area {
    flex: 1;
    min-height: 0;
  }

  /* Messages: less margin, tighter */
  .message {
    margin-bottom: 16px;
    padding-bottom: 16px;
  }
  .message-text {
    font-size: 0.9rem;
    line-height: 1.6;
  }

  /* Input area: stack vertically on very small screens */
  .dialogue-input {
    gap: 8px;
    padding: 8px 0;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    flex-wrap: wrap;
  }
  .dialogue-input textarea {
    min-height: 44px;
    padding: 10px;
    font-size: 0.9rem;
    flex: 1 1 100%;
    order: 1;
  }
  .dialogue-input button#send-btn {
    padding: 10px 16px;
    font-size: 0.8rem;
    min-height: 44px;
    flex: 1 1 auto;
    order: 3;
  }
  /* Settings gear: move to row with send button */
  .dialogue-input button#settings-gear {
    order: 2;
    min-width: 44px;
    min-height: 44px;
    font-size: 1.2rem !important;
    opacity: 0.6 !important;
  }

  /* Settings panel: full-width bottom sheet */
  #settings-panel {
    width: calc(100vw - 16px) !important;
    max-width: none !important;
    left: 8px !important;
    right: 8px !important;
    bottom: 8px !important;
    max-height: 80vh !important;
    border-radius: 12px 12px 8px 8px;
  }
  #settings-panel select,
  #settings-panel textarea,
  #settings-panel input {
    font-size: 16px !important; /* Prevents iOS zoom on focus */
  }
  #settings-panel input[type="range"] {
    height: 32px;
  }

  /* Playback bar: full width at bottom */
  #playback-bar {
    bottom: 60px;
    left: 8px;
    right: 8px;
    transform: none;
    border-radius: 12px;
    padding: 8px 16px;
  }
  #playback-bar button {
    min-width: 44px;
    min-height: 44px;
    font-size: 1.2rem;
  }

  /* Message controls: always visible on mobile (no hover) */
  .msg-play, .msg-play-all, .msg-delete {
    opacity: 0.4 !important;
    font-size: 0.8rem;
    min-width: 32px;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Login box: a bit wider padding */
  .login-box {
    width: 92%;
    padding: 0 12px;
  }
  .login-box input, .login-box button {
    padding: 14px 12px;
    font-size: 16px !important;
  }

  /* Card display: less padding */
  .card-display {
    padding: 24px 16px;
    margin: 24px 0;
  }

  /* Draw button: full width on mobile */
  .draw-btn {
    width: 100%;
    margin: 40px auto 0;
    padding: 16px 24px;
  }

  /* Chat items: bigger tap targets */
  .chat-item {
    padding: 14px 16px;
    min-height: 44px;
  }
  .chat-item .delete-chat {
    opacity: 0.4;
    font-size: 0.8rem;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* New chat button: bigger */
  .new-chat-btn {
    padding: 14px;
    font-size: 0.85rem;
  }

  /* Thinking blocks: full width */
  .thinking-content.expanded {
    max-height: 40vh !important;
  }

  /* Card header: less margin */
  #card-header {
    margin-bottom: 16px !important;
  }

  /* Welcome state */
  .welcome-state {
    padding-top: 80px;
  }

  /* Sidebar close area — add a close button for mobile */
  .sidebar-header {
    padding: 8px 16px 16px;
  }
}

/* Extra small screens (iPhone SE etc) */
@media (max-width: 375px) {
  body.chat-active .page {
    padding: 44px 4px 0;
  }
  .message-text {
    font-size: 0.85rem;
  }
  .dialogue-input textarea {
    font-size: 16px;
    min-height: 40px;
  }
  #token-counter {
    display: none !important;
  }
}

/* iOS safe areas */
@supports (padding: env(safe-area-inset-bottom)) {
  body.chat-active .dialogue-input {
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
  body.chat-active .page {
    padding-top: calc(48px + env(safe-area-inset-top));
  }
  .stage-indicator {
    top: calc(8px + env(safe-area-inset-top));
  }
}

/* ---- Integrated Landing / Login ---- */
.login-landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 0 24px;
  max-width: 480px;
}
.landing-title {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 2.8rem;
  font-weight: 400;
  color: var(--amber);
  letter-spacing: 0.35em;
  margin-bottom: 32px;
}
.landing-directive {
  font-size: 0.9rem;
  color: var(--dim);
  line-height: 1.8;
  font-style: italic;
  max-width: 440px;
  margin-bottom: 48px;
}
.landing-attrib {
  display: block;
  margin-top: 8px;
  font-style: normal;
  font-size: 0.8rem;
  color: var(--ghost);
  letter-spacing: 0.08em;
  font-weight: 500;
}
.landing-nav {
  margin-top: 40px;
  font-size: 0.8rem;
}
.landing-nav a {
  color: var(--ghost);
  text-decoration: none;
  letter-spacing: 0.08em;
  transition: color 0.2s;
}
.landing-nav a:hover { color: var(--amber); }
.landing-nav .nav-sep {
  color: #333;
  margin: 0 12px;
}

/* ---- Site Navigation Bar ---- */
#site-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 40px;
  background: rgba(10, 10, 10, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #1a1a1a;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 90;
  font-size: 0.75rem;
}
#site-nav .nav-link {
  color: var(--ghost);
  text-decoration: none;
  letter-spacing: 0.08em;
  transition: color 0.2s;
  padding: 4px 8px;
}
#site-nav .nav-link:hover { color: var(--amber); }
#site-nav .nav-links {
  display: flex;
  gap: 4px;
}

/* ---- Welcome State Navigation ---- */
.welcome-nav {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  margin-top: 16px;
}
.welcome-nav-btn {
  display: block;
  background: none;
  border: 1px solid var(--dim);
  color: var(--amber);
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 0.85rem;
  letter-spacing: 0.15em;
  padding: 10px 40px;
  width: 240px;
  text-align: center;
  text-decoration: none;
  transition: border-color 0.3s, color 0.3s;
}
.welcome-nav-btn:hover {
  border-color: var(--amber);
  color: var(--text);
}

/* ---- Adjust body padding for nav bar ---- */
body.chat-active .page {
  padding-top: 48px;
}

/* ---- Mobile nav adjustments ---- */
@media (max-width: 768px) {
  .landing-title { font-size: 2rem; letter-spacing: 0.2em; }
  .landing-directive { font-size: 0.8rem; margin-bottom: 32px; }
  .landing-nav { margin-top: 24px; }
  .landing-nav a { font-size: 0.7rem; }
  .landing-nav .nav-sep { margin: 0 8px; }
  #site-nav { padding: 0 8px; font-size: 0.7rem; }
  #site-nav .nav-link { padding: 4px 4px; }
  .welcome-nav-btn { width: 200px; font-size: 0.75rem; padding: 8px 24px; }
}

/* Nav bar left group */
#site-nav .nav-left {
  display: flex;
  align-items: center;
  gap: 4px;
}
#site-nav .nav-left span:hover { opacity: 1 !important; }
