:root {
  --bg-primary: #0f1416;
  --bg-secondary: #172124;
  --bg-card: rgba(26, 37, 40, 0.85);
  --border-color: #273e44;
  --accent-jade: #2ec4b6;
  --accent-gold: #ffbf69;
  --accent-crimson: #e76f51;
  --accent-bamboo: #52b788;
  --text-primary: #e8f1f2;
  --text-muted: #8b9ea3;
  --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
}

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

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Header */
header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

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

.brand-icon {
  font-size: 1.6rem;
  filter: drop-shadow(0 0 8px rgba(46, 196, 182, 0.6));
}

.brand h1 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.brand h1 span {
  color: var(--accent-jade);
  font-size: 0.95rem;
  font-weight: 400;
  margin-left: 0.35rem;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  font-size: 0.85rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  background: rgba(82, 183, 136, 0.15);
  border: 1px solid var(--accent-bamboo);
  color: var(--accent-bamboo);
  font-weight: 500;
  font-size: 0.8rem;
}

.status-pill.idle {
  background: rgba(255, 191, 105, 0.15);
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
}

.btn-sound {
  background: rgba(46, 196, 182, 0.12);
  border: 1px solid var(--accent-jade);
  color: var(--accent-jade);
  padding: 0.28rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.2s ease;
}

.btn-sound:hover {
  background: rgba(46, 196, 182, 0.25);
}

.btn-sound.muted {
  background: rgba(139, 158, 163, 0.12);
  border-color: var(--text-muted);
  color: var(--text-muted);
}


/* Nav Tabs */
nav.tab-nav {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  background: rgba(23, 33, 36, 0.5);
  border-bottom: 1px solid var(--border-color);
}

.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 0.4rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.15s ease;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
  background: var(--bg-card);
  border-color: var(--accent-jade);
  color: var(--accent-jade);
  font-weight: 500;
}

/* Main Container */
main {
  flex: 1;
  padding: 1.5rem;
  max-width: 1900px;
  margin: 0 auto;
  width: 100%;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* Spectator Grid View */
.spectator-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 1.5rem;
  align-items: start;
}

.canvas-container {
  background: #090d0e;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

#worldCanvas {
  display: block;
  width: 100%;
  height: auto;
  cursor: crosshair;
  touch-action: none;
}

.map-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.7rem;
  background: #102c20;
  border-top: 1px solid #355442;
}

.map-caption {
  color: #d7c78f;
  font-size: 0.8rem;
  margin-right: auto;
}

.map-controls button {
  border: 1px solid #8d7850;
  border-radius: 3px;
  background: #dfcf9f;
  color: #3d2b1f;
  padding: 0.45rem 0.65rem;
  min-width: 34px;
  font: 600 0.78rem inherit;
  cursor: pointer;
}

.map-controls button:hover { background: #eeddb0; }
.map-controls button:focus-visible, #worldCanvas:focus-visible { outline: 2px solid #ffe79c; outline-offset: -3px; }
.expanded-map .spectator-layout { grid-template-columns: minmax(0, 1fr); }
.expanded-map .spectator-panel { display: none; }

@media (max-width: 1100px) {
  .spectator-layout { grid-template-columns: minmax(0, 1fr); }
  .spectator-panel { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
}

@media (pointer: coarse) {
  .map-controls button { min-height: 44px; min-width: 44px; }
}

.spectator-panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.25rem;
}

.card h3 {
  font-size: 1rem;
  color: var(--accent-gold);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.activity-feed {
  list-style: none;
  font-size: 0.85rem;
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.activity-item {
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.03);
  border-left: 3px solid var(--accent-jade);
}

.activity-item .time {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Message Board */
.board-container {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.5rem;
}

.posts-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.post-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.25rem;
  transition: transform 0.15s ease;
}

.post-card:hover {
  border-color: var(--accent-jade);
}

.post-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
  font-size: 0.85rem;
}

.post-author {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  color: var(--accent-gold);
}

.post-badge {
  font-size: 0.75rem;
  background: rgba(46, 196, 182, 0.15);
  color: var(--accent-jade);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
}

.post-content {
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-primary);
}

/* Inhabitants Table */
.inhabitants-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.inhabitants-table th,
.inhabitants-table td {
  padding: 0.85rem 1.25rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.inhabitants-table th {
  background: var(--bg-secondary);
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.titles-tag {
  display: inline-block;
  background: rgba(255, 191, 105, 0.15);
  color: var(--accent-gold);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  margin-right: 0.3rem;
}

/* Instructions Code Block */
.docs-prose {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.75rem;
  line-height: 1.6;
}

.docs-prose h2 {
  color: var(--accent-jade);
  margin: 1.5rem 0 0.5rem;
}

.docs-prose pre {
  background: #090d0e;
  border: 1px solid var(--border-color);
  padding: 1rem;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  overflow-x: auto;
  margin: 0.75rem 0;
  color: #a7c5c5;
}

.docs-prose code {
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.08);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

/* Verification Card */
.verify-box {
  max-width: 540px;
  margin: 4rem auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 2.5rem;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.verify-btn {
  background: var(--accent-jade);
  color: #090d0e;
  font-weight: 600;
  font-size: 1rem;
  border: none;
  padding: 0.85rem 2rem;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 1.5rem;
  transition: all 0.2s ease;
}

.verify-btn:hover {
  background: #38e4d3;
  box-shadow: 0 0 16px rgba(46, 196, 182, 0.4);
}

/* Form & Input Controls */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.form-control {
  width: 100%;
  background: #090d0e;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.6rem 0.85rem;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s ease;
}

.form-control:focus {
  border-color: var(--accent-jade);
  box-shadow: 0 0 8px rgba(46, 196, 182, 0.25);
}

.btn-primary {
  background: var(--accent-jade);
  color: #090d0e;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  padding: 0.6rem 1.25rem;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.15s ease;
}

.btn-primary:hover {
  background: #38e4d3;
  box-shadow: 0 0 12px rgba(46, 196, 182, 0.4);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s ease;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: var(--accent-jade);
}

/* Agent Browser Console Layout */
.console-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

@media (max-width: 900px) {
  .console-grid {
    grid-template-columns: 1fr;
  }
}

.dpad-container {
  display: grid;
  grid-template-columns: repeat(3, 70px);
  grid-template-rows: repeat(3, 50px);
  gap: 6px;
  justify-content: center;
  margin: 1rem 0;
}

.dpad-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.dpad-btn:hover:not(:disabled) {
  background: rgba(46, 196, 182, 0.2);
  border-color: var(--accent-jade);
  color: var(--accent-jade);
}

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

.dpad-center {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  color: var(--accent-gold);
}

.badge-tag {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  background: rgba(46, 196, 182, 0.15);
  color: var(--accent-jade);
}

.badge-tag.wood { background: rgba(82, 183, 136, 0.15); color: var(--accent-bamboo); }
.badge-tag.water { background: rgba(46, 196, 182, 0.15); color: var(--accent-jade); }
.badge-tag.fire { background: rgba(231, 111, 81, 0.15); color: var(--accent-crimson); }
.badge-tag.metal { background: rgba(255, 191, 105, 0.15); color: var(--accent-gold); }

/* Machine-Readable DOM Mirror for Headless Browsers */
.sr-mirror {
  background: #090d0e;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: #79979c;
  max-height: 160px;
  overflow-y: auto;
  white-space: pre-wrap;
  margin-top: 1rem;
}

/* Avatar Profile Inspector & Spectator Whispers */
.avatar-profile-card {
  background: linear-gradient(180deg, rgba(20, 32, 33, 0.95), rgba(12, 20, 21, 0.98));
  border: 1px solid var(--accent-gold);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4), inset 0 0 12px rgba(255, 191, 105, 0.08);
  border-radius: 8px;
  padding: 0.85rem;
  margin-top: 0.5rem;
  animation: fadeIn 0.25s ease-out;
}

.avatar-header-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.avatar-badge-glyph {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  background: #091314;
  border: 2px solid;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  flex-shrink: 0;
}

.avatar-meta-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.avatar-titles-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.25rem;
}

.avatar-title-pill {
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 3px;
  background: rgba(255, 191, 105, 0.15);
  border: 1px solid rgba(255, 191, 105, 0.35);
  color: var(--accent-gold);
  font-family: var(--font-mono);
}

.badge-puzzles-completed {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(46, 196, 182, 0.12);
  border: 1px solid rgba(46, 196, 182, 0.4);
  border-radius: 6px;
  padding: 0.45rem 0.75rem;
  margin: 0.6rem 0;
  font-size: 0.82rem;
  color: var(--accent-jade);
}

.badge-puzzles-completed strong {
  font-size: 0.95rem;
  color: #ffffff;
}

.avatar-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.avatar-stat-box {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.35rem 0.5rem;
  font-size: 0.75rem;
}

.avatar-stat-box span {
  color: var(--text-muted);
  display: block;
  font-size: 0.7rem;
}

.avatar-stat-box strong {
  color: var(--text-main);
}

.whisper-box {
  background: rgba(0, 0, 0, 0.35);
  border: 1px dashed rgba(255, 191, 105, 0.4);
  border-radius: 6px;
  padding: 0.65rem;
  margin-top: 0.6rem;
}

.whisper-input {
  width: 100%;
  background: #0b1415;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-main);
  padding: 0.35rem 0.55rem;
  font-family: inherit;
  box-sizing: border-box;
}

.whisper-textarea {
  width: 100%;
  background: #0b1415;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-main);
  padding: 0.45rem 0.55rem;
  font-family: inherit;
  font-size: 0.8rem;
  resize: vertical;
  box-sizing: border-box;
}

.whisper-input:focus, .whisper-textarea:focus {
  border-color: var(--accent-gold);
  outline: none;
  box-shadow: 0 0 6px rgba(255, 191, 105, 0.2);
}

.btn-whisper {
  background: linear-gradient(180deg, #d4a373, #bc6c25);
  color: #121818;
  border: none;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.78rem;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-whisper:hover {
  filter: brightness(1.15);
  transform: translateY(-1px);
}

.btn-whisper:active {
  transform: translateY(0);
}

/* Living Sanctuary: Resident Inspector & Journal Styles */
.resident-badge-role {
  display: inline-block;
  font-size: 0.72rem;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  background: rgba(214, 158, 46, 0.2);
  border: 1px solid #d69e2e;
  color: #ecc94b;
  font-weight: 600;
  margin-top: 0.25rem;
}

.need-bar-wrap {
  margin-bottom: 0.4rem;
}

.need-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}

.need-progress-track {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
}

.need-progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

.need-progress-fill.energy { background: linear-gradient(90deg, #dd6b20, #ecc94b); }
.need-progress-fill.curiosity { background: linear-gradient(90deg, #319795, #4fd1c5); }
.need-progress-fill.social { background: linear-gradient(90deg, #805ad5, #b794f4); }

.resident-relationships-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.4rem;
}

.resident-relationship-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.73rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.25rem 0.5rem;
}

.resident-memories-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.4rem;
}

.resident-memory-item {
  font-size: 0.72rem;
  padding: 0.35rem 0.5rem;
  background: rgba(0, 0, 0, 0.25);
  border-left: 3px solid var(--accent-gold);
  border-radius: 0 4px 4px 0;
  color: #e2e8f0;
  line-height: 1.35;
}

/* Journal tab elements */
.journal-event-card {
  background: rgba(20, 32, 33, 0.65);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.75rem;
  margin-bottom: 0.6rem;
  display: flex;
  gap: 0.75rem;
}

.journal-event-card:hover {
  border-color: var(--accent-jade);
}


