:root{
  --bg: #12160f;
  --panel: #1a2117;
  --panel2: #212a1c;
  --border: #33402b;
  --text: #e8e6da;
  --muted: #9aa38c;
  --accent: #d9a441;
  --accent2: #7fb26a;
  --danger: #c0473a;
  --radius: 10px;
  font-family: "Georgia", "Iowan Old Style", serif;
}

*{ box-sizing: border-box; }
html,body{ height:100%; }
body{
  margin:0;
  background: radial-gradient(ellipse at top, #1b2416 0%, #0e120c 70%);
  color: var(--text);
  min-height:100vh;
}

.hidden{ display:none !important; }

.page{
  max-width: 1400px;
  margin: 0 auto;
  padding: 22px 20px 40px;
}

.brand{
  display:flex; align-items:baseline; gap:12px; margin-bottom: 18px;
}
.brand h1{
  font-size: 30px; letter-spacing: 1px; margin:0;
  color: var(--accent);
  text-shadow: 0 2px 10px rgba(217,164,65,0.25);
}
.brand span{ color: var(--muted); font-size: 14px; font-style: italic; }

/* ---------- auth screen ---------- */
.auth-wrap{
  max-width: 380px;
  margin: 8vh auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}
.auth-wrap h2{ margin-top:0; color: var(--accent); }
.auth-tabs{ display:flex; gap:8px; margin-bottom:16px; }
.auth-tabs button{
  flex:1; padding:8px; border-radius:8px; border:1px solid var(--border);
  background: var(--panel2); color: var(--muted); cursor:pointer; font-family:inherit;
}
.auth-tabs button.active{ background: var(--accent); color:#241a06; border-color: var(--accent); font-weight:bold; }
.field{ margin-bottom:14px; }
.field label{ display:block; font-size:13px; color: var(--muted); margin-bottom:5px; }
.field input{
  width:100%; padding:9px 10px; border-radius:8px; border:1px solid var(--border);
  background: #0f130c; color: var(--text); font-family: inherit; font-size:15px;
}
.btn{
  padding: 10px 16px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: #241a06; font-weight:bold; cursor:pointer;
  font-family: inherit; font-size: 14px;
}
.btn:hover{ filter: brightness(1.08); }
.btn:disabled{ opacity:0.5; cursor:default; }
.btn.secondary{ background: var(--panel2); color: var(--text); border-color: var(--border); }
.btn.danger{ background: var(--danger); border-color: var(--danger); color:#fff; }
.btn.small{ padding: 5px 10px; font-size: 12px; }
.error-msg{ color: var(--danger); font-size: 13px; min-height: 18px; margin-top:6px; }

/* ---------- game layout ---------- */
.workshop{
  display:flex; gap: 16px; align-items:flex-start;
}
.main-col{ flex: 1; min-width: 0; }
.side-col{
  flex: 0 0 300px;
  display:flex; flex-direction:column; gap: 14px;
}

.hud{
  display:flex; align-items:center; gap: 16px; flex-wrap:wrap;
  background: var(--panel); border:1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 12px;
}
.hud .creature-id{ min-width: 140px; }
.hud .creature-id .name{ font-size: 18px; color: var(--accent); }
.hud .creature-id .stage{ font-size: 12px; color: var(--muted); text-transform: capitalize; }
.bars{ display:flex; flex-direction:column; gap:4px; min-width: 160px; }
.bar-row{ display:flex; align-items:center; gap:6px; font-size:11px; color: var(--muted); }
.bar{ flex:1; height: 9px; background:#0f130c; border-radius:5px; overflow:hidden; border:1px solid var(--border); }
.bar > i{ display:block; height:100%; background: var(--accent2); }
.bar.hunger > i{ background: #d99a41; }
.hud .spacer{ flex:1; }
.hud .actions{ display:flex; gap:8px; flex-wrap:wrap; }

.canvas-frame{
  position:relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
}
.canvas-frame canvas{
  width:100%; display:block; border-radius:6px; image-rendering: pixelated;
  background:#0c0f09; cursor: crosshair;
}
.canvas-caption{
  display:flex; justify-content:space-between; align-items:center;
  font-size:12px; color: var(--muted); padding: 8px 4px 0;
}

.editor-tray{
  margin-top: 10px; background: var(--panel2); border:1px solid var(--border);
  border-radius: 8px; padding: 10px;
}
.editor-tray .row{ display:flex; align-items:center; gap:10px; flex-wrap:wrap; margin-bottom:8px; }
.editor-tray .row:last-child{ margin-bottom:0; }

.palette-group{ margin-bottom: 10px; }
.palette-group:last-child{ margin-bottom: 0; }
.palette-group-label{ font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 5px; }
.palette-row{ display:flex; flex-wrap:wrap; gap:6px; }
.terrain-btn{
  display:flex; align-items:center; gap:6px; padding: 5px 10px 5px 6px;
  border-radius:7px; border:1px solid var(--border); background: var(--panel);
  cursor:pointer; font-family:inherit; color: var(--text); font-size:12.5px;
}
.terrain-btn.active{ border-color: var(--accent); background: rgba(217,164,65,0.12); }
.terrain-btn:hover{ border-color: var(--accent2); }
.terrain-swatch{ width:16px; height:16px; border-radius:4px; display:inline-block; border:1px solid rgba(0,0,0,0.35); flex-shrink:0; }
.terrain-label{ white-space:nowrap; }

#colorPicker{ display:flex; align-items:center; gap:8px; margin-top:8px; }
#colorPicker label{ font-size:12px; color:var(--muted); }
#colorPickerInput{ width:44px; height:28px; padding:0; border:1px solid var(--border); border-radius:6px; background:none; cursor:pointer; }

.creature-switcher{ display:flex; gap:8px; flex-wrap:wrap; margin-bottom: 12px; }
.creature-slot{
  display:flex; flex-direction:column; align-items:center; gap:3px;
  padding: 8px 12px; border-radius:8px; border:1px solid var(--border); background: var(--panel2);
  cursor:pointer; min-width: 76px; font-size:11px; color: var(--muted);
}
.creature-slot.active{ border-color: var(--accent); background: rgba(217,164,65,0.14); color: var(--text); }
.creature-slot .slot-name{ font-size:12.5px; color: var(--text); font-weight:bold; }
.creature-slot.egg-pending .slot-name{ color: var(--accent); }
.creature-slot .slot-stage{ text-transform:capitalize; }
.creature-slot-empty{
  display:flex; align-items:center; justify-content:center;
  padding: 8px 14px; border-radius:8px; border:1px dashed var(--border); color: var(--muted);
  font-size:11px; min-width: 76px;
}

.inventory-tray{
  display:flex; gap:10px; margin-top:10px; flex-wrap:wrap;
}
.inv-item{
  display:flex; align-items:center; gap:6px; background: var(--panel2);
  border:1px solid var(--border); border-radius:8px; padding:6px 10px; cursor:pointer;
  font-size:13px;
}
.inv-item:hover{ border-color: var(--accent); }
.inv-item.usable{ border-color: rgba(169,139,214,0.5); }
.inv-item.usable:hover{ border-color: #a98bd6; }
.inv-item.empty{ opacity: 0.45; cursor: default; }
.inv-item.empty:hover{ border-color: var(--border); }
.inv-item .count{ color: var(--accent); font-weight:bold; }

.log-box{
  background: var(--panel2); border:1px solid var(--border); border-radius:8px;
  padding:8px 10px; font-size:12.5px; max-height:110px; overflow-y:auto; margin-top:10px;
  color: var(--muted);
}
.log-box div{ margin-bottom:3px; }

/* ---------- chat ---------- */
.panel-box{
  background: var(--panel); border:1px solid var(--border); border-radius: var(--radius);
  padding: 12px; display:flex; flex-direction:column;
}
.panel-box h3{ margin: 0 0 8px; font-size:14px; color: var(--accent); letter-spacing:0.5px; }

.chat-box{ height: 340px; }
.chat-messages{
  flex:1; overflow-y:auto; font-size:13px; margin-bottom:8px; display:flex; flex-direction:column; gap:4px;
}
.chat-messages .msg .who{ color: var(--accent2); font-weight:bold; margin-right:4px; }
.chat-messages .sys{ color: var(--muted); font-style: italic; }
.chat-input-row{ display:flex; gap:6px; }
.chat-input-row input{
  flex:1; padding:8px; border-radius:6px; border:1px solid var(--border);
  background:#0f130c; color:var(--text); font-family: inherit;
}

.online-box{ max-height: 260px; }
.online-list{ overflow-y:auto; display:flex; flex-direction:column; gap:6px; }
.online-row{
  display:flex; align-items:center; justify-content:space-between;
  background: var(--panel2); border:1px solid var(--border); border-radius:6px; padding:6px 8px;
  font-size:13px;
}
.online-row .dot{ width:7px; height:7px; border-radius:50%; background: var(--accent2); margin-right:6px; display:inline-block; }

.visit-banner{
  background: #2a2412; border:1px solid var(--accent); border-radius:8px;
  padding:8px 12px; margin-bottom:10px; font-size:13px; display:flex; justify-content:space-between; align-items:center;
}

.top-actions{ display:flex; gap:8px; align-items:center; margin-bottom:10px; }
.top-actions .whoami{ color: var(--muted); font-size:13px; margin-left:auto; }
.top-actions a.btn{ text-decoration:none; display:inline-flex; align-items:center; }

.modal-backdrop{
  position:fixed; inset:0; background:rgba(8,10,7,0.72);
  display:flex; align-items:center; justify-content:center; z-index:200; padding:20px;
}
.modal{
  background: var(--panel); border:1px solid var(--border); border-radius: var(--radius);
  padding:20px; max-width:520px; width:100%; max-height:80vh; overflow-y:auto;
}
.modal-head{ display:flex; align-items:center; justify-content:space-between; margin-bottom:14px; }
.modal-head h2{ margin:0; color: var(--accent); font-size:20px; }
.stat-grid{ display:grid; grid-template-columns: 1fr 1fr; gap:10px 16px; margin-bottom:16px; }
.stat-row{ display:flex; justify-content:space-between; font-size:13.5px; border-bottom:1px solid var(--border); padding-bottom:5px; }
.stat-row .k{ color: var(--muted); }
.stat-row .v{ color: var(--text); font-weight:bold; }
.stat-section-title{ font-size:11px; text-transform:uppercase; letter-spacing:0.5px; color:var(--muted); margin:14px 0 8px; }
.stat-bar-wrap{ margin-bottom:10px; }
.stat-bar-label{ display:flex; justify-content:space-between; font-size:12px; color:var(--muted); margin-bottom:3px; }
.stat-bar{ height:10px; background:#0f130c; border:1px solid var(--border); border-radius:5px; overflow:hidden; }
.stat-bar > i{ display:block; height:100%; }

@media (max-width: 980px){
  .workshop{ flex-direction:column; }
  .side-col{ flex-basis:auto; width:100%; }
}
