/* Minecraft overworld — daytime forest biome.
   Greet page = deep forest green, chat = dirt/oak-wood brown,
   text = parchment, accents = grass green. */
:root {
  --bg: #3c6b35;        /* forest-green greet/landing background */
  --panel: #6b4a2f;     /* dirt/oak-wood brown chat background */
  --ink: #f4ead6;       /* parchment text */
  --muted: #cdbfa3;     /* faded parchment */
  --accent: #5cab3f;    /* grass-block green */
  --accent-ink: #1d2b14;/* dark leaf green for text on grass buttons */
  --bubble: #6b8e4f;    /* moss green message bubble */
  --border: #45301d;    /* dark-oak bark */
  --stone: #5c5c60;     /* stone grey — topbar, composer, emoji palette */
  --stone-light: #74747a;/* lit stone — emoji hover, topbar identicon */
  --stone-dark: #46464a;/* shaded stone — input field, stone borders */
}
@media (prefers-color-scheme: dark) {
  /* Overworld at night / under the canopy. */
  :root {
    --bg: #24401f;      /* dark pine green */
    --panel: #4a3322;   /* shaded dirt brown */
    --ink: #ece2cd;     /* parchment */
    --muted: #b6a988;   /* faded parchment */
    --accent: #4d9636;  /* deep grass green */
    --accent-ink: #15200e;
    --bubble: #4d6b3a;  /* dark moss green message bubble */
    --border: #2e1f12;  /* dark bark */
    --stone: #3a3a3e;     /* deepslate */
    --stone-light: #4e4e54;
    --stone-dark: #2a2a2e;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg) url('wood.png') repeat;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 18px;
}

#app { height: 100%; }

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 12px;
}

input {
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
input:focus { outline: none; border-color: var(--accent); }

.primary {
  background: var(--accent);
  color: var(--accent-ink);
  padding: 12px 20px;
  font-weight: 700;
}
.primary:active { transform: translateY(1px); }

/* ---- Landing & Join ---- */
.landing, .join {
  max-width: 560px;
  margin: 0 auto;
  padding: 48px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: center;
}
.landing h1, .join h1 { font-size: 2.4rem; margin: 0; }
.landing p, .join p { color: var(--muted); margin: 0; line-height: 1.5; }
.slug-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 6px 10px;
}
.slug-row .origin { color: var(--muted); white-space: nowrap; }
.slug-row input { border: none; flex: 1; padding: 8px 4px; }
.slug-row input:focus { outline: none; }
.name-input { width: 100%; text-align: center; }
.room-label { font-weight: 600; color: var(--ink) !important; word-break: break-all; }
.error { color: #ff6b5e; min-height: 1.4em; font-size: 0.95rem; } /* redstone red */

/* Avatar selector button on join screen */
.avatar-selector-btn {
  width: 80px;
  height: 80px;
  margin: 0 auto 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.avatar-selector-btn:hover {
  border-color: var(--accent);
  transform: scale(1.05);
}
.avatar-placeholder {
  width: 64px;
  height: 64px;
  background: var(--stone);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: bold;
  color: var(--muted);
}
.avatar-selector-btn img {
  border-radius: 8px;
}
.avatar-hint {
  position: absolute;
  bottom: -24px;
  font-size: 0.75rem;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.2s;
  white-space: nowrap;
}
.avatar-selector-btn:hover .avatar-hint {
  opacity: 1;
}

/* Avatar picker modal */
.avatar-picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.avatar-picker {
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  max-width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}
.avatar-picker h3 {
  width: 100%;
  text-align: center;
  margin: 0 0 12px 0;
  color: var(--ink);
}
.avatar-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px;
  background: var(--bubble);
  border: 2px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}
.avatar-option:hover {
  border-color: var(--accent);
  transform: scale(1.05);
}
.avatar-option img, .avatar-option .identicon {
  width: 64px;
  height: 64px;
}
.avatar-label {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

/* ---- Chat ---- */
.chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 760px;
  margin: 0 auto;
  background: var(--panel) url('dirt.png') repeat;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--stone);
  border-bottom: 1px solid var(--stone-dark);
}
.room-name { font-weight: 800; word-break: break-all; }
.me {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}
.me-avatar {
  cursor: pointer;
  transition: opacity 0.2s;
}
.me-avatar:hover {
  opacity: 0.8;
}

.history-wrap { position: relative; flex: 1; min-height: 0; }
.history {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}
.msg {
  border-radius: 14px;
  padding: 8px 12px;
  max-width: 85%;
  align-self: flex-start;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  color: var(--ink);
}
.msg.msg-mine {
  align-self: flex-end;
}
.msg-head {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 8px;
  vertical-align: middle;
}
.msg-user { font-weight: 700; color: var(--ink); opacity: 0.9; }
.msg-user::after { content: ":"; }
.msg-body { white-space: pre-wrap; color: var(--ink); }

/* Per-user pixel-icon, hashed from the username. */
.identicon {
  flex: none;
  border-radius: 4px;
  background: var(--bubble);
  /* crisp pixel edges rather than blurred scaling */
  shape-rendering: crispEdges;
}
.topbar .identicon { background: var(--stone-light); }

.jump {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--accent-ink);
  padding: 8px 16px;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}
.jump.hidden { display: none; }

.palette {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 12px;
  background: var(--stone);
  border-top: 1px solid var(--stone-dark);
  max-height: 124px;
  overflow-y: auto;
}
.emoji {
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  padding: 6px;
  border-radius: 10px;
}
.emoji:hover { background: var(--stone-light); }
.emoji:active { transform: scale(0.9); }

.composer {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: var(--stone);
  border-top: 1px solid var(--stone-dark);
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
.composer .msg-input {
  flex: 1;
  background: var(--stone-dark);
  border-color: var(--stone-dark);
}
.send {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  padding: 0 22px;
}
.send:active { transform: translateY(1px); }
