/* ============================================================
 * Mini World · pixel HUD CSS
 * Matches the in-canvas reference mockup:
 *   - dark navy backdrop, subtle red/burgundy frame glow
 *   - Press Start 2P title with cyan glow
 *   - JetBrains Mono monospace for HUD chrome
 *   - chunky "pixel" meters in resource bars
 * ============================================================ */

:root {
  /* Core palette */
  --bg:           #08090f;
  --bg-deep:      #04050a;
  --panel:        rgba(10, 14, 26, 0.78);
  --panel-edge:   rgba(80, 110, 160, 0.22);
  --panel-inner:  rgba(20, 28, 50, 0.55);

  /* Frame burgundy/red glow */
  --frame-red:    #6b0d18;
  --frame-red-2:  #2a050a;

  /* Text */
  --text:         #b8c6e0;
  --text-bright:  #e7eefc;
  --text-dim:     #6b7a96;
  --text-faded:   rgba(184,198,224,0.55);

  /* Cyan accent (title + Thronglet) */
  --cyan:         #62e1ff;
  --cyan-soft:    #2c8db5;

  /* Resource accents */
  --c-energy:     #fbe44b;
  --c-food:       #5fd57c;
  --c-wood:       #5fd57c;
  --c-stone:      #c9d1e3;
  --c-happiness:  #ffb84d;

  /* Tribe accents */
  --c-orange:     #ff9851;
  --c-violet:     #b07cff;
  --c-teal:       #5be0d4;

  /* Legacy hooks (still used by sim event surfaces) */
  --c-plant:      #65d34d;
  --c-herbivore:  #f5d550;
  --c-predator:   #e15252;
  --c-human:      #ec9b5a;
  --c-skill:      #62e1ff;
  --c-trait:      #ffd34d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-deep);
  color: var(--text);
  font-family: 'JetBrains Mono', 'Menlo', monospace;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  width: 100vw;
  height: 100vh;
  position: relative;
  background: radial-gradient(ellipse at center, #0c1224 0%, #04050a 80%);
}

#canvas-container {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

#world-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ── Frame glow (always-on red/burgundy vignette) ──────────────── */
#world-frame-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  /* Inner shadow for the burgundy edge */
  box-shadow:
    inset 0 0 80px 8px rgba(107, 13, 24, 0.55),
    inset 0 0 200px 40px rgba(107, 13, 24, 0.22),
    inset 0 0 24px 2px rgba(255, 80, 100, 0.18);
  /* Faint corner darkening */
  background:
    radial-gradient(ellipse 140% 80% at 50% 0%, transparent 60%, rgba(0,0,0,0.45) 100%),
    radial-gradient(ellipse 140% 80% at 50% 100%, transparent 60%, rgba(0,0,0,0.45) 100%);
  mix-blend-mode: normal;
}

/* ── Centered title (fades after a few seconds) ────────────────── */
#world-title {
  position: absolute;
  top: 28px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  text-align: center;
  pointer-events: none;
  opacity: 1;
  transition: opacity 1.2s ease;
}
#world-title.faded {
  opacity: 0;
}
.world-title-main {
  font-family: 'Press Start 2P', monospace;
  font-size: 64px;
  letter-spacing: 6px;
  color: var(--cyan);
  text-shadow:
    0 0 6px rgba(98, 225, 255, 0.95),
    0 0 18px rgba(98, 225, 255, 0.65),
    0 0 36px rgba(46, 140, 200, 0.45),
    0 4px 0 rgba(8, 26, 38, 0.8);
}
.world-title-tag {
  margin-top: 18px;
  font-family: 'VT323', monospace;
  font-size: 28px;
  letter-spacing: 1px;
  color: rgba(220, 240, 255, 0.85);
  text-shadow: 0 0 8px rgba(98, 225, 255, 0.4);
}

/* ── HUD panels — shared chrome ────────────────────────────────── */
.hud-panel {
  position: absolute;
  z-index: 20;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 4px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.02),
    0 4px 18px rgba(0,0,0,0.55);
  font-family: 'JetBrains Mono', monospace;
}

/* ── TOP-LEFT · world simulation status ────────────────────────── */
#hud-tl {
  top: 80px;
  left: 28px;
  width: 220px;
  padding: 10px 12px 12px;
}
.hud-panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--panel-edge);
}
.hud-panel-title {
  font-size: 9px;
  letter-spacing: 1.4px;
  color: var(--text-bright);
  text-transform: uppercase;
  font-weight: 600;
}
.hud-version {
  color: var(--text-dim);
  font-weight: 500;
}
.hud-stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  letter-spacing: 0.5px;
  padding: 3px 0;
  text-transform: uppercase;
}
.hud-stat-icon {
  width: 12px;
  color: var(--cyan);
  text-align: center;
  font-size: 11px;
}
.hud-stat-label {
  color: var(--text-dim);
  flex: 1;
}
.hud-stat-value {
  color: var(--text-bright);
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* ── TOP-RIGHT · transport + event feed ────────────────────────── */
#hud-tr {
  top: 28px;
  right: 28px;
  width: 240px;
  padding: 10px 14px 10px 12px;
}
.hud-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--panel-edge);
}
.ctrl-btn {
  flex: 0 0 auto;
  width: 26px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-inner);
  border: 1px solid var(--panel-edge);
  border-radius: 3px;
  color: var(--text-bright);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  padding: 0;
}
.ctrl-btn:hover {
  background: rgba(46, 80, 130, 0.4);
  border-color: rgba(98, 225, 255, 0.4);
  color: var(--cyan);
}
.ctrl-btn.active {
  background: rgba(98, 225, 255, 0.18);
  border-color: rgba(98, 225, 255, 0.55);
  color: var(--cyan);
}
.ctrl-speed {
  margin-left: auto;
  padding-right: 2px;
  font-size: 11px;
  color: var(--text-bright);
  letter-spacing: 0.6px;
  font-weight: 600;
  min-width: 22px;
  text-align: right;
}

/* Event log — timestamped feed of recent events */
.event-log {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 10px;
  letter-spacing: 0.4px;
  max-height: 130px;
  overflow: hidden;
  text-transform: uppercase;
}
.event-row {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 6px;
  align-items: start;
  line-height: 1.35;
  animation: ev-in 0.5s ease;
}
.event-time {
  color: var(--cyan);
  font-weight: 600;
  letter-spacing: 0.3px;
}
.event-body {
  color: var(--text);
}
.event-body .ev-tribe {
  color: var(--text-bright);
  font-weight: 600;
  letter-spacing: 0.5px;
}
.event-body .ev-tribe.orange   { color: var(--c-orange); }
.event-body .ev-tribe.violet   { color: var(--c-violet); }
.event-body .ev-tribe.teal     { color: var(--c-teal); }
.event-body .ev-tribe.cyan     { color: var(--cyan); }
.event-body .ev-action {
  display: block;
  color: var(--text-faded);
  font-weight: 400;
  margin-top: 1px;
  letter-spacing: 0.4px;
}
.event-empty {
  color: var(--text-dim);
  font-style: italic;
  text-align: center;
  padding: 6px 0;
  letter-spacing: 0.5px;
}
@keyframes ev-in {
  from { opacity: 0; transform: translateX(8px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── BOTTOM-LEFT · minimap ─────────────────────────────────────── */
#minimap-host {
  bottom: 28px;
  left: 28px;
  padding: 6px;
  display: flex;
  flex-direction: column;
}
#minimap-canvas {
  display: block;
  border-radius: 2px;
  cursor: crosshair;
  background: #06070d;
}
.minimap-eye {
  position: absolute;
  top: 14px;
  right: 14px;
  font-size: 12px;
  color: var(--cyan);
  text-shadow: 0 0 6px rgba(98,225,255,0.7);
  pointer-events: none;
}

/* ── BOTTOM-CENTER · resource bars ─────────────────────────────── */
#hud-bottom {
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  padding: 12px 16px;
  /* Leave room for minimap (~200px) on the left and seed (~210px) on the right,
     plus a small breathing buffer on each side. */
  width: min(880px, calc(100vw - 480px));
  min-width: 0;
}
.resbar {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.resbar-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}
.resbar-icon {
  font-size: 12px;
  width: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.resbar-icon.energy    { color: var(--c-energy); }
.resbar-icon.food      { color: var(--c-food); }
.resbar-icon.wood      { color: var(--c-wood); }
.resbar-icon.stone     { color: var(--c-stone); }
.resbar-icon.happiness { color: var(--c-happiness); }

.resbar-label {
  color: var(--text-bright);
  font-weight: 600;
}
.resbar-meter-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Chunky "pixel" meter — 10 segments separated by transparent gutters */
.resbar-meter {
  position: relative;
  flex: 1;
  height: 14px;
  background: rgba(10, 14, 26, 0.85);
  border: 1px solid rgba(80, 110, 160, 0.35);
  border-radius: 2px;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.6);
}
.resbar-meter i {
  display: block;
  height: 100%;
  width: 0%;
  /* Segmented pixel look: stripes of color separated by tiny dark gutters.
     Implemented as repeating-linear-gradient over the fill width. */
  background:
    repeating-linear-gradient(
      to right,
      currentColor 0px,
      currentColor 10px,
      rgba(0,0,0,0.55) 10px,
      rgba(0,0,0,0.55) 12px
    );
  transition: width 0.4s cubic-bezier(.25,.8,.25,1);
}
#bar-energy    { color: var(--c-energy); }
#bar-food      { color: var(--c-food); }
#bar-wood      { color: var(--c-wood); }
#bar-stone     { color: var(--c-stone); }
#bar-happiness { color: var(--c-happiness); }

.resbar-value {
  font-size: 11px;
  color: var(--text-bright);
  font-weight: 600;
  min-width: 36px;
  text-align: right;
  letter-spacing: 0.5px;
}

/* ── BOTTOM-RIGHT · world seed ─────────────────────────────────── */
#hud-seed {
  bottom: 28px;
  right: 28px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.seed-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.seed-label {
  font-size: 9px;
  letter-spacing: 1.4px;
  color: var(--text-dim);
  text-transform: uppercase;
}
.seed-value {
  font-size: 13px;
  letter-spacing: 1.5px;
  color: var(--text-bright);
  font-weight: 600;
}
.seed-roll {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: var(--panel-inner);
  border: 1px solid var(--panel-edge);
  border-radius: 3px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.seed-roll:hover {
  background: rgba(98, 225, 255, 0.14);
  border-color: rgba(98, 225, 255, 0.55);
  color: var(--cyan);
}

/* ── Pause overlay ─────────────────────────────────────────────── */
#pause-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(4, 5, 10, 0.55);
  backdrop-filter: blur(2px);
  pointer-events: none;
}
#pause-overlay.visible { display: flex; }
.pause-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 36px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 4px;
  color: var(--text-bright);
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  letter-spacing: 2px;
}
.pause-hint {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}

/* ── Toasts ────────────────────────────────────────────────────── */
#toast-host {
  position: absolute;
  top: 200px;
  right: 28px;
  z-index: 25;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 240px;
  pointer-events: none;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 3px;
  padding: 8px 10px;
  font-size: 10px;
  color: var(--text);
  letter-spacing: 0.4px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  pointer-events: auto;
  animation: toast-in 0.35s ease;
}
.toast b { color: var(--text-bright); font-weight: 600; }
.toast em { color: var(--cyan); font-style: normal; }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Cinematic moment overlay (Thronglet stages) ───────────────── */
#moment-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.2s ease;
  background:
    radial-gradient(ellipse at center, transparent 40%, rgba(80, 0, 0, 0.55) 100%);
  z-index: 40;
}
#moment-vignette.active { opacity: 1; }

#moment-attribution {
  position: absolute;
  bottom: 110px;
  right: 28px;
  font-size: 9px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
  display: none;
  align-items: center;
  gap: 6px;
  z-index: 41;
}
#moment-attribution.visible { display: flex; }
.moment-attr-eye {
  color: var(--cyan);
  text-shadow: 0 0 6px rgba(98,225,255,0.7);
}

#moment-subtitle {
  position: absolute;
  bottom: 130px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 42;
  text-align: center;
  max-width: 720px;
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}
#moment-subtitle.visible { opacity: 1; }
.moment-sub-speaker {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--cyan);
  margin-bottom: 4px;
}
.moment-sub-text {
  font-family: 'VT323', monospace;
  font-size: 26px;
  color: #f6fbff;
  text-shadow: 0 2px 8px rgba(0,0,0,0.8);
  letter-spacing: 1px;
}
.moment-sub-text b {
  color: var(--cyan);
  font-weight: normal;
}

/* ── Misc removed/legacy hooks ─────────────────────────────────── */
/* Hide anything from the old chrome that might still get appended */
#brush-dial, #coords, #hud-fps, #thronglet-badge,
#welcome-modal, #help-modal, #toolbar, #sidebar,
#legend, .panel, .modal-host {
  display: none !important;
}

/* ── Responsive — keep panels readable on smaller windows ──────── */
@media (max-width: 1100px) {
  #hud-bottom { gap: 10px; padding: 10px 12px; }
  .resbar-label, .resbar-row { font-size: 9px; }
  .resbar-meter { height: 12px; }
  .world-title-main { font-size: 44px; letter-spacing: 4px; }
}
@media (max-width: 820px) {
  #hud-tl { width: 180px; }
  #hud-tr { width: 200px; }
  /* Tight viewport: drop minimap + seed below the bars on a separate row */
  #hud-bottom { width: calc(100vw - 56px); }
  #minimap-host { bottom: 168px; }
  #hud-seed { bottom: 168px; }
  .world-title-main { font-size: 30px; letter-spacing: 2px; }
}


/* ── Tweaks panel (in-design knobs) ─────────────────────────────── */
#tweaks-panel {
  position: fixed;
  left: 18px;
  top: 270px;
  z-index: 100;
  width: 240px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 6px;
  padding: 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.5px;
  color: var(--text);
  display: none;
  box-shadow: 0 8px 28px rgba(0,0,0,0.55), 0 0 0 1px rgba(98,225,255,0.06);
  backdrop-filter: blur(8px);
}
#tweaks-panel.open { display: block; }

#tweaks-panel .tw-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-bottom: 1px solid var(--panel-edge);
}
#tweaks-panel .tw-title {
  font-size: 9px;
  letter-spacing: 1.6px;
  color: var(--cyan);
  text-shadow: 0 0 6px rgba(98,225,255,0.55);
}
#tweaks-panel .tw-close {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  opacity: 0.6;
}
#tweaks-panel .tw-close:hover { opacity: 1; color: var(--cyan); }

#tweaks-panel .tw-section {
  padding: 10px 12px;
  border-bottom: 1px solid var(--panel-edge);
}
#tweaks-panel .tw-section:last-child { border-bottom: none; }
#tweaks-panel .tw-label {
  font-size: 8px;
  letter-spacing: 1.4px;
  color: rgba(180, 200, 230, 0.6);
  margin-bottom: 8px;
}
#tweaks-panel .tw-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
#tweaks-panel .tw-chip,
#tweaks-panel .tw-btn {
  background: rgba(20, 28, 46, 0.7);
  border: 1px solid rgba(80, 110, 160, 0.35);
  color: var(--text);
  font-family: inherit;
  font-size: 9px;
  letter-spacing: 1px;
  padding: 5px 8px;
  border-radius: 3px;
  cursor: pointer;
  transition: background 120ms, border-color 120ms, color 120ms;
}
#tweaks-panel .tw-chip:hover,
#tweaks-panel .tw-btn:hover {
  background: rgba(46, 80, 130, 0.4);
  border-color: rgba(98, 225, 255, 0.4);
  color: var(--cyan);
}
#tweaks-panel .tw-chip.on {
  background: rgba(98, 225, 255, 0.18);
  border-color: rgba(98, 225, 255, 0.55);
  color: var(--cyan);
  text-shadow: 0 0 4px rgba(98,225,255,0.5);
}
#tweaks-panel .tw-btn { width: 100%; padding: 7px 8px; }
