:root {
  color-scheme: dark;
  --bg: #06100e;
  --panel: #0b1815;
  --panel-2: #10221d;
  --line: rgba(132, 244, 208, .16);
  --text: #f5fbf8;
  --muted: #86a59b;
  --mint: #63e7c3;
  --mint-2: #2bbd99;
  --yt: #ff4f57;
  --tw: #a66cff;
  --shadow: 0 18px 60px rgba(0, 0, 0, .32);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 20% -10%, #11372d 0, transparent 36%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(1540px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 12px;
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(280px, 1fr) auto;
  gap: 18px;
  align-items: center;
  margin-bottom: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 190px;
}
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-weight: 900;
  color: var(--mint);
  background: linear-gradient(145deg, #143c32, #0b201b);
  border: 1px solid rgba(99,231,195,.4);
  box-shadow: inset 0 0 22px rgba(99,231,195,.08);
}
.brand h1 { font-size: 19px; margin: 0; letter-spacing: -.02em; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.resident-pill, .button {
  border: 1px solid var(--line);
  background: rgba(12, 28, 24, .86);
  color: var(--text);
  border-radius: 10px;
  min-height: 40px;
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.resident-pill { font-size: 13px; color: var(--muted); }
.resident-pill strong { color: var(--text); }
.resident-pill.muted { background: rgba(10, 23, 20, .55); }
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 10px rgba(99,231,195,.85);
}
.button {
  font-weight: 800;
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}
.button:hover {
  transform: translateY(-1px);
  border-color: rgba(99,231,195,.46);
}
.button.primary {
  background: var(--mint);
  color: #062018;
  border-color: transparent;
}
.button.secondary { background: #0f211d; }
.button.small { min-height: 34px; padding: 0 11px; font-size: 12px; }

.search-shell {
  position: relative;
  width: min(520px, 100%);
  justify-self: center;
  z-index: 20;
}
.search-box {
  height: 42px;
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 4px;
  padding: 4px 5px 4px 10px;
  background: rgba(11, 26, 22, .92);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.16);
}
.search-box:focus-within {
  border-color: rgba(99,231,195,.55);
  box-shadow: 0 0 0 3px rgba(99,231,195,.08);
}
.search-icon {
  color: var(--mint);
  font-size: 21px;
  line-height: 1;
  transform: rotate(-12deg);
}
.search-box input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
}
.search-box input::placeholder { color: #69877e; }
.search-go {
  border: 0;
  border-radius: 8px;
  height: 32px;
  padding: 0 13px;
  color: #082019;
  background: var(--mint);
  font-weight: 900;
}
.search-results {
  position: absolute;
  top: calc(100% + 7px);
  left: 0;
  right: 0;
  background: rgba(8, 21, 18, .98);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  box-shadow: var(--shadow);
  max-height: 330px;
  overflow: auto;
}
.search-result {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  border-radius: 8px;
  padding: 9px 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}
.search-result:hover,
.search-result.active { background: rgba(99,231,195,.09); }
.search-result strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search-result small { color: var(--muted); font-size: 11px; }
.search-empty {
  color: var(--muted);
  font-size: 12px;
  padding: 12px;
  text-align: center;
}

.world-wrap {
  position: relative;
  height: clamp(650px, 78vh, 920px);
  overflow: hidden;
  border-radius: 20px;
  border: 1px solid rgba(103, 231, 194, .24);
  background: #173a2d;
  box-shadow: var(--shadow);
  user-select: none;
}
#world {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}
#world.dragging { cursor: grabbing; }

.world-hint,
.world-status,
.world-controls {
  position: absolute;
  z-index: 5;
  background: rgba(5, 18, 14, .84);
  border: 1px solid rgba(255,255,255,.08);
  backdrop-filter: blur(8px);
}
.world-hint {
  left: 14px;
  bottom: 14px;
  border-radius: 10px;
  padding: 8px 10px;
  color: #c6d9d2;
  font-size: 12px;
}
.world-status {
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  border-radius: 999px;
  padding: 7px 11px;
  color: #b9d1c8;
  font-size: 12px;
  transition: opacity .25s ease;
}
.world-status.hidden {
  opacity: 0;
  pointer-events: none;
}
.world-controls {
  right: 14px;
  bottom: 14px;
  border-radius: 10px;
  display: flex;
  overflow: hidden;
}
.world-controls button {
  width: 48px;
  height: 40px;
  border: 0;
  border-right: 1px solid rgba(255,255,255,.08);
  background: transparent;
  color: var(--text);
  font-weight: 900;
}
.world-controls button:nth-child(2) { width: 58px; font-size: 12px; }
.world-controls button:last-child { border-right: 0; }
.world-controls button:hover { background: rgba(99,231,195,.1); }

.footer {
  min-height: 38px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
  color: #66867c;
  font-size: 12px;
  padding: 0 4px;
}
.legend {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.legend b {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  margin-left: 6px;
}
.yt-dot { background: var(--yt); }
.tw-dot { background: var(--tw); }
.both-dot {
  background: linear-gradient(90deg, var(--yt) 0 50%, var(--tw) 50%);
}

dialog { color: var(--text); }
dialog::backdrop {
  background: rgba(0, 7, 6, .56);
  backdrop-filter: blur(4px);
}
.dialog-card,
.join-dialog {
  border: 1px solid rgba(99,231,195,.18);
  background: #0b1815;
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.dialog-card {
  width: min(470px, calc(100% - 28px));
  padding: 24px;
  display: none;
  grid-template-columns: 86px 1fr;
  gap: 18px;
  align-items: center;
}
.dialog-card[open] { display: grid; }
.join-dialog {
  width: min(520px, calc(100% - 28px));
  padding: 30px;
}
.dialog-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: 0;
  background: transparent;
  color: #9fb9b0;
  font-size: 26px;
}
.profile-avatar {
  width: 82px;
  height: 82px;
  border-radius: 16px;
  background: linear-gradient(145deg, #1b493b, #10261f);
  border: 1px solid rgba(99,231,195,.25);
  overflow: hidden;
  display: grid;
  place-items: center;
  font-weight: 900;
  color: var(--mint);
}
.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.profile-copy h2,
.join-dialog h2 {
  margin: 2px 0 8px;
  font-size: 25px;
}
.profile-copy p,
.join-dialog p {
  color: var(--muted);
  line-height: 1.5;
}
.eyebrow {
  color: var(--mint);
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: 10px;
  font-weight: 900;
}
.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 9px 0;
}
.badge {
  border-radius: 999px;
  font-size: 11px;
  font-weight: 900;
  padding: 5px 8px;
  border: 1px solid rgba(255,255,255,.1);
  background: rgba(255,255,255,.05);
}
.badge.youtube { color: #ff8d92; }
.badge.twitch { color: #c29dff; }
.badge.creator { color: #ffd66f; }
.badge.verified { color: #7ff0ca; }
.join-icon {
  font-size: 30px;
  color: var(--mint);
  margin-bottom: 8px;
}
.login-stack {
  display: grid;
  gap: 10px;
  margin: 22px 0 15px;
}
.platform-button {
  width: 100%;
  border-radius: 13px;
  border: 1px solid rgba(255,255,255,.09);
  background: #11231f;
  color: var(--text);
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 11px;
  align-items: center;
  text-align: left;
  padding: 13px;
}
.platform-button:hover {
  border-color: rgba(255,255,255,.2);
  transform: translateY(-1px);
}
.platform-button .platform-logo {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-weight: 900;
}
.platform-button span:last-child {
  display: grid;
  gap: 2px;
}
.platform-button small { color: #8da79f; }
.platform-button.youtube .platform-logo {
  background: rgba(255,79,87,.15);
  color: var(--yt);
}
.platform-button.twitch .platform-logo {
  background: rgba(166,108,255,.14);
  color: var(--tw);
}
.fine-print {
  font-size: 11px;
  color: #708c83 !important;
}
.character-preview {
  height: 160px;
  border-radius: 14px;
  margin-top: 18px;
  border: 1px solid rgba(99,231,195,.12);
  background:
    radial-gradient(circle at center, rgba(99,231,195,.12), transparent 55%),
    #0d201b;
  position: relative;
}
.character-preview::before {
  content: "🧍";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 58px;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  z-index: 100;
  border: 1px solid rgba(99,231,195,.22);
  background: rgba(7, 22, 18, .96);
  color: #eafff8;
  border-radius: 11px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  transition: .2s ease;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1120px) {
  .topbar { grid-template-columns: auto 1fr; }
  .search-shell {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
  }
  .top-actions {
    grid-column: 2;
    grid-row: 1;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: calc(100% - 14px);
    padding-top: 8px;
  }
  .topbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
  }
  .brand { flex: 1 1 auto; }
  .top-actions {
    width: 100%;
    justify-content: flex-start;
  }
  .search-shell { order: 3; }
  .resident-pill.muted { display: none; }
  .world-wrap {
    height: 74vh;
    min-height: 560px;
    border-radius: 15px;
  }
  .world-hint { max-width: calc(100% - 150px); }
  .dialog-card[open] {
    grid-template-columns: 1fr;
    text-align: center;
  }
  .profile-avatar { margin: auto; }
  .badge-row { justify-content: center; }
  .footer {
    flex-wrap: wrap;
    padding-top: 8px;
  }
}
