:root {
  --bg: #0a0a0a;
  --bg-card: #0f0f0f;
  --bg-input: #111111;
  --border: #1a1a1a;
  --border-light: #252525;
  --text: #c4a77d;
  --text-dim: #6b5a42;
  --text-bright: #e0d0b8;
  --accent: #c4a77d;
  --accent-dim: #8a7355;
  --state-color: #c4a77d;
  --echo-bg: #0c0c0c;
  --glow: rgba(196, 167, 125, 0.15);

  /* Neon green accent */
  --green: #90ff90;
  --green-dim: #4a8a4a;
  --green-glow: rgba(144, 255, 144, 0.2);

  /* Pink for glyph */
  --pink: #ff6b9d;
  --pink-dim: #8a4a5d;
  --pink-glow: rgba(255, 107, 157, 0.2);

  /* State colors */
  --freeze: #6ec1e4;
  --fight: #ff6b6b;
  --edge: #ffa94d;
  --flow: #90ff90;
  --calm: #b197fc;
}

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

*::-webkit-scrollbar {
  width: 4px;
}

*::-webkit-scrollbar-track {
  background: var(--bg);
}

*::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 2px;
}

html, body {
  height: 100%;
  height: -webkit-fill-available;
  overflow: hidden;
}

body {
  font-family: 'Space Mono', monospace;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Subtle scanlines */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.05) 0px,
    rgba(0, 0, 0, 0.05) 1px,
    transparent 1px,
    transparent 3px
  );
  z-index: 1000;
}

#app {
  height: 100%;
  overflow: hidden;
}

.screen {
  display: none;
  height: 100%;
  overflow-y: auto;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* Loading */
#loading {
  align-items: center;
  justify-content: center;
}

.loading-text {
  font-size: 16px;
  color: var(--text-dim);
}

.loading-text::after {
  content: '_';
  animation: blink 0.7s step-end infinite;
}

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

/* Auth Messages */
#auth-required,
#not-subscribed {
  align-items: center;
  justify-content: center;
}

.auth-message {
  text-align: center;
  padding: 20px;
}

.auth-message h1 {
  font-size: 32px;
  letter-spacing: 8px;
  margin-bottom: 24px;
  color: var(--accent);
  text-shadow: 0 0 30px var(--glow);
}

.auth-message p {
  color: var(--text-dim);
  margin-bottom: 32px;
  max-width: 280px;
  font-size: 15px;
}

/* Dashboard */
#dashboard {
  padding: 16px;
  padding-bottom: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  flex-shrink: 0;
}

header h1 {
  font-size: 18px;
  letter-spacing: 6px;
  color: var(--accent);
  text-shadow: 0 0 15px var(--glow);
}

.user-name {
  font-size: 13px;
  color: var(--text-dim);
}

.user-name::before {
  content: '> ';
  color: var(--green);
}

/* State Card */
.state-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 16px;
  margin-bottom: 16px;
  text-align: center;
  flex-shrink: 0;
}

.state-label {
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.state-name {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 3px;
  text-shadow: 0 0 20px var(--glow);
}

.state-desc {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 6px;
}

/* Mode Tabs */
.mode-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  flex-shrink: 0;
}

.mode-tab {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 12px 8px;
  font-family: 'Space Mono', monospace;
  font-size: 13px;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-tab:not(:last-child) {
  border-right: none;
}

.mode-tab.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

.mode-tab[data-mode="diagnostic"].active {
  background: var(--green);
  border-color: var(--green);
}

.mode-tab[data-mode="glyph"].active {
  background: var(--pink);
  border-color: var(--pink);
}

.mode-content {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.mode-content.active {
  display: flex;
  flex-direction: column;
}

/* ===== SIGNAL MODE - CHAT INTERFACE ===== */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 300px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  padding-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-intro {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}

.intro-text {
  font-size: 14px;
  font-style: italic;
}

/* Chat bubbles */
.chat-msg {
  max-width: 85%;
  animation: msgSlide 0.3s ease-out;
}

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

.chat-msg.user {
  align-self: flex-end;
}

.chat-msg.field {
  align-self: flex-start;
}

.msg-bubble {
  padding: 12px 16px;
  border-radius: 4px;
  font-size: 15px;
  line-height: 1.5;
}

.chat-msg.user .msg-bubble {
  background: var(--accent);
  color: var(--bg);
  border-bottom-right-radius: 0;
}

.chat-msg.field .msg-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  color: var(--text);
  border-bottom-left-radius: 0;
}

.msg-time {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
  opacity: 0.6;
}

.chat-msg.user .msg-time {
  text-align: right;
}

.msg-state {
  font-size: 10px;
  color: var(--green);
  margin-top: 2px;
  letter-spacing: 1px;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  border-bottom-left-radius: 0;
  align-self: flex-start;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-dim);
  border-radius: 50%;
  animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* Chat input */
.chat-input-container {
  display: flex;
  gap: 8px;
  padding-top: 12px;
  padding-bottom: 8px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}

.chat-input-container textarea {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 12px 14px;
  color: var(--text);
  font-family: 'Space Mono', monospace;
  font-size: 15px;
  resize: none;
  border-radius: 4px;
  min-height: 44px;
  max-height: 120px;
}

.chat-input-container textarea::placeholder {
  color: var(--text-dim);
}

.chat-input-container textarea:focus {
  outline: none;
  border-color: var(--accent-dim);
}

.btn-send {
  width: 44px;
  height: 44px;
  background: var(--accent);
  border: none;
  color: var(--bg);
  font-size: 18px;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-send:hover {
  background: var(--text-bright);
  box-shadow: 0 0 15px var(--glow);
}

.btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ===== DIAGNOSTIC MODE ===== */
.diag-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  padding-bottom: 20px;
}

.diag-input-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.diag-prompt {
  font-size: 12px;
  color: var(--green);
  letter-spacing: 1px;
}

.diag-input-section textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 14px;
  color: var(--text);
  font-family: 'Space Mono', monospace;
  font-size: 15px;
  resize: none;
  border-radius: 4px;
}

.diag-input-section textarea:focus {
  outline: none;
  border-color: var(--green-dim);
  box-shadow: 0 0 10px var(--green-glow);
}

.diag-input-section textarea::placeholder {
  color: var(--text-dim);
}

/* Diagnostic Result */
.diagnostic-result.hidden {
  display: none;
}

/* State Header */
.state-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  background: var(--bg-card);
  border: 2px solid var(--green);
  border-radius: 4px;
  animation: scanIn 0.6s ease-out;
}

@keyframes scanIn {
  from {
    clip-path: inset(0 100% 0 0);
    opacity: 0;
  }
  to {
    clip-path: inset(0 0 0 0);
    opacity: 1;
  }
}

.state-glyph {
  font-size: 48px;
  color: var(--green);
  text-shadow: 0 0 20px var(--green-glow);
  animation: glyphPulse 2s ease-in-out infinite;
}

@keyframes glyphPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.state-info {
  flex: 1;
}

.state-name-lg {
  font-size: 22px;
  font-weight: bold;
  color: var(--accent);
  letter-spacing: 3px;
  margin-bottom: 4px;
}

.state-phase-text {
  font-size: 12px;
  color: var(--green);
  letter-spacing: 1px;
  opacity: 0.8;
}

/* Panels */
.science-panel,
.body-panel,
.intervention-panel,
.echo-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  animation: panelFade 0.4s ease-out;
  animation-fill-mode: both;
}

.science-panel { animation-delay: 0.1s; }
.body-panel { animation-delay: 0.2s; }
.intervention-panel { animation-delay: 0.3s; }
.echo-panel { animation-delay: 0.4s; }

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

.panel-header {
  background: var(--green);
  color: var(--bg);
  padding: 8px 14px;
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 2px;
}

.panel-content {
  padding: 14px;
}

/* Science Panel */
.sci-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.sci-label {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 1px;
  min-width: 70px;
}

.sci-value {
  font-size: 14px;
  color: var(--text);
}

.activation-bar {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.activation-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green) 0%, var(--accent) 100%);
  border-radius: 4px;
  transition: width 0.5s ease-out;
}

.sci-description {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* Body Zones */
.body-zones {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.body-zone {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 4px;
  font-size: 12px;
}

.zone-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}

.zone-indicator.active {
  background: var(--green);
  box-shadow: 0 0 8px var(--green-glow);
}

.zone-indicator.tense {
  background: var(--fight);
  box-shadow: 0 0 8px rgba(255, 107, 107, 0.3);
}

.zone-name {
  color: var(--text);
}

/* Intervention Panel */
.intervention-text {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
}

.intervention-text strong {
  color: var(--green);
}

/* Echo Panel */
.echo-response {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  font-style: italic;
}

/* ===== GLYPH MODE ===== */
.glyph-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.glyph-input-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.glyph-input-section textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 14px;
  color: var(--text);
  font-family: 'Space Mono', monospace;
  font-size: 15px;
  resize: none;
  border-radius: 4px;
}

.glyph-input-section textarea:focus {
  outline: none;
  border-color: var(--pink-dim);
  box-shadow: 0 0 10px var(--pink-glow);
}

.glyph-input-section textarea::placeholder {
  color: var(--text-dim);
}

.glyph-controls {
  display: flex;
  gap: 8px;
}

.glyph-controls select {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px;
  font-family: 'Space Mono', monospace;
  font-size: 14px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23c4a77d' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.glyph-controls select:hover {
  border-color: var(--pink-dim);
  box-shadow: 0 0 8px var(--pink-glow);
}

.glyph-controls select:focus {
  outline: none;
  border-color: var(--pink);
  box-shadow: 0 0 15px var(--pink-glow);
}

.glyph-controls select:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

/* Glyph Result */
.glyph-result.hidden {
  display: none;
}

.glyph-output {
  background: var(--bg-card);
  border: 2px solid var(--pink);
  padding: 24px;
  font-size: 18px;
  line-height: 2;
  text-align: center;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  border-radius: 4px;
  animation: glyphReveal 0.5s ease-out;
}

@keyframes glyphReveal {
  from {
    opacity: 0;
    transform: scale(0.95);
    filter: blur(4px);
  }
  to {
    opacity: 1;
    transform: scale(1);
    filter: blur(0);
  }
}

/* Buttons */
.btn {
  display: inline-block;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 12px 20px;
  font-family: 'Space Mono', monospace;
  font-size: 14px;
  letter-spacing: 1px;
  cursor: pointer;
  text-decoration: none;
  text-transform: lowercase;
  transition: all 0.2s;
  border-radius: 4px;
}

.btn:hover {
  background: var(--accent);
  color: var(--bg);
  box-shadow: 0 0 15px var(--glow);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-diag {
  color: var(--green);
  border-color: var(--green);
  width: 100%;
}

.btn-diag:hover {
  background: var(--green);
  color: var(--bg);
  box-shadow: 0 0 15px var(--green-glow);
}

.btn-glyph {
  color: var(--pink);
  border-color: var(--pink);
  flex: 1;
}

.btn-glyph:hover {
  background: var(--pink);
  color: var(--bg);
  box-shadow: 0 0 15px var(--pink-glow);
}

/* ===== STATS BAR ===== */
.stats-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 12px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  flex-shrink: 0;
  margin-top: auto;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-num {
  font-size: 18px;
  font-weight: bold;
  color: var(--accent);
}

.stat-lbl {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 1px;
  text-transform: lowercase;
}

.stat-divider {
  width: 1px;
  height: 28px;
  background: var(--border);
}

.stat-state {
  font-size: 12px;
  color: var(--green);
  letter-spacing: 2px;
  font-weight: bold;
}

/* Footer */
footer {
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
  margin: 0 -16px;
  margin-bottom: -16px;
}

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

/* ===== RESPONSIVE - MOBILE FIRST ===== */

/* Small phones */
@media (max-width: 360px) {
  #dashboard {
    padding: 12px;
  }

  header h1 {
    font-size: 16px;
    letter-spacing: 4px;
  }

  .mode-tab {
    font-size: 11px;
    padding: 10px 4px;
  }

  .state-glyph {
    font-size: 36px;
  }

  .state-name-lg {
    font-size: 18px;
  }

  .body-zones {
    grid-template-columns: 1fr;
  }

  .stats-bar {
    gap: 12px;
    padding: 10px 16px;
  }

  .stat-num {
    font-size: 16px;
  }

  .stat-lbl {
    font-size: 9px;
  }

  footer {
    margin: 0 -12px;
    margin-bottom: -12px;
  }
}

/* Tablets and up */
@media (min-width: 768px) {
  #dashboard {
    max-width: 600px;
    margin: 0 auto;
    padding: 24px;
  }

  .chat-messages {
    padding: 16px 0;
  }

  .chat-msg {
    max-width: 70%;
  }

  .state-header {
    padding: 24px;
  }

  .state-glyph {
    font-size: 56px;
  }

  .state-name-lg {
    font-size: 26px;
  }

  .body-zones {
    grid-template-columns: repeat(3, 1fr);
  }

  .stats-bar {
    max-width: 568px;
    margin-left: auto;
    margin-right: auto;
  }

  footer {
    margin: 0 -24px;
    margin-bottom: 0;
  }
}

/* Large screens */
@media (min-width: 1024px) {
  #dashboard {
    max-width: 700px;
  }

  .diagnostic-result {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }

  .state-header {
    grid-column: 1 / -1;
  }

  .echo-panel {
    grid-column: 1 / -1;
  }
}

/* Landscape phone adjustments */
@media (max-height: 500px) and (orientation: landscape) {
  .chat-container {
    min-height: 200px;
  }

  .state-header {
    padding: 12px 16px;
  }

  .state-glyph {
    font-size: 32px;
  }

  .panel-content {
    padding: 10px;
  }
}

/* Dark mode preference (already dark, but ensure contrast) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Touch devices - larger tap targets */
@media (hover: none) and (pointer: coarse) {
  .mode-tab {
    min-height: 48px;
  }

  .btn,
  .btn-send {
    min-height: 48px;
  }

  .glyph-controls select {
    min-height: 48px;
  }
}
