:root {
  --ink: #2d2018;
  --ink-soft: #674d3a;
  --cream: #f8e6b4;
  --paper: #fff5cf;
  --wood: #9c613f;
  --wood-dark: #5b3427;
  --gold: #e4a84d;
  --green: #5d8f82;
  --green-dark: #315d57;
  --red: #bb574d;
  --shadow: rgba(36, 24, 18, .42);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 30% 10%, rgba(244, 189, 101, .18), transparent 35%),
    #201914;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  image-rendering: pixelated;
}

button, input { font: inherit; }
button { cursor: pointer; }

.lobby {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
}

.pixel-panel {
  border: 4px solid var(--wood-dark);
  box-shadow: 0 0 0 4px #c88b50, 0 12px 0 4px var(--shadow);
  background: var(--paper);
}

.lobby-card {
  width: min(520px, 100%);
  padding: 28px;
  position: relative;
}

.lobby-scene {
  height: 146px;
  margin: -8px -8px 24px;
  position: relative;
  overflow: hidden;
  border: 4px solid var(--wood-dark);
  background:
    linear-gradient(90deg, transparent 31px, rgba(109, 74, 45, .18) 32px, transparent 33px),
    linear-gradient(transparent 31px, rgba(109, 74, 45, .18) 32px, transparent 33px),
    #d7b576;
  background-size: 32px 32px;
}

.lobby-scene::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 24px;
  background: #79503a;
  border-bottom: 6px solid #4e3026;
}

.mini-desk {
  position: absolute;
  width: 88px;
  height: 34px;
  top: 55px;
  background: #a76743;
  border: 4px solid #553226;
  box-shadow: inset 0 6px #d09057;
}
.mini-desk::before {
  content: "";
  position: absolute;
  width: 34px;
  height: 25px;
  left: 23px;
  top: -25px;
  background: #526b69;
  border: 4px solid #302a27;
}
.desk-one { left: 30px; }
.desk-two { left: calc(50% - 44px); }
.desk-three { right: 30px; }

.mini-person {
  position: absolute;
  width: 22px;
  height: 28px;
  top: 100px;
  border: 4px solid #33231d;
  background: #d16d61;
}
.mini-person::before {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  left: 0;
  top: -14px;
  border: 4px solid #33231d;
  background: #f1bd88;
}
.person-one { left: 64px; }
.person-two { left: calc(50% - 11px); background: #5d8f82; }
.person-three { right: 64px; background: #e0a23f; }

.eyebrow {
  display: block;
  margin-bottom: 6px;
  color: var(--green-dark);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .16em;
}

h1 {
  margin: 0 0 12px;
  font-family: Georgia, serif;
  font-size: clamp(34px, 8vw, 54px);
  line-height: .96;
  color: var(--wood-dark);
}

.lobby-copy {
  margin: 0 0 24px;
  color: var(--ink-soft);
  line-height: 1.55;
}

#join-form { display: grid; gap: 9px; }
#join-form label { margin-top: 6px; font-size: 12px; font-weight: 900; }

#join-form input {
  width: 100%;
  min-height: 48px;
  padding: 10px 13px;
  color: var(--ink);
  background: #fffaf0;
  border: 3px solid #76513a;
  border-radius: 0;
  outline: none;
  box-shadow: inset 0 -4px rgba(92, 58, 35, .1);
}
#join-form input:focus { border-color: var(--green-dark); box-shadow: 0 0 0 3px #a8c6aa; }

.pixel-button {
  min-height: 44px;
  padding: 10px 14px;
  color: var(--ink);
  background: #f3c76f;
  border: 3px solid #5c3829;
  border-radius: 0;
  box-shadow: inset 0 -5px rgba(104, 60, 35, .2), 0 4px 0 #4a2d23;
  font-size: 12px;
  font-weight: 900;
}
.pixel-button:hover { filter: brightness(1.05); transform: translateY(-1px); }
.pixel-button:active { transform: translateY(3px); box-shadow: inset 0 -2px rgba(104, 60, 35, .2), 0 1px 0 #4a2d23; }
.pixel-button.primary { margin-top: 12px; color: #fff8d9; background: var(--green); }
.pixel-button[aria-pressed="true"] { color: #fff; background: var(--red); }
.pixel-button:disabled { cursor: wait; opacity: .6; }

.form-error { min-height: 20px; margin: 12px 0 0; color: #9c342e; font-size: 12px; }

.workspace {
  width: min(1500px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 14px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
}
.workspace[aria-hidden="true"] { display: none; }

.topbar, .controlbar {
  min-height: 66px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: 0 0 0 3px #c88b50, 0 6px 0 2px var(--shadow);
}
.topbar strong { font-size: 18px; }

.connection-block, .participants-block { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.connection-dot { width: 12px; height: 12px; background: #d99d42; border: 2px solid var(--wood-dark); }
.connection-dot.online { background: #61a46f; }
.connection-dot.offline { background: #bb574d; }
.participants-block strong { min-width: 28px; padding: 4px 7px; text-align: center; background: var(--cream); border: 2px solid var(--wood-dark); }

.stage-shell {
  width: 100%;
  position: relative;
  align-self: center;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  outline: 4px solid #140f0c;
  box-shadow: 0 0 0 8px #6f432f, 0 14px 0 8px rgba(0, 0, 0, .35);
  background: #a98558;
}
.stage-shell:focus-visible { outline-color: #f5ce70; }
#game-canvas { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.media-layer { position: absolute; inset: 0; pointer-events: none; }

.station-media {
  position: absolute;
  width: 18.3%;
  min-width: 120px;
  transform: translate(-50%, -100%);
  padding: 4px;
  color: #fff7d6;
  background: #2b2521;
  border: 3px solid #140f0c;
  box-shadow: 0 4px 0 rgba(0,0,0,.4);
  transition: opacity .2s;
}
.station-media.is-empty { opacity: .78; }
.station-title {
  height: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
  font-size: clamp(7px, .7vw, 10px);
  white-space: nowrap;
  overflow: hidden;
}
.station-feeds { display: grid; grid-template-columns: 1fr 1.25fr; gap: 3px; }
.feed {
  min-width: 0;
  aspect-ratio: 16 / 10;
  position: relative;
  overflow: hidden;
  background: #181d1d;
  border: 2px solid #6b5a48;
}
.feed video { width: 100%; height: 100%; display: block; object-fit: cover; background: #111; }
.feed.screen video { object-fit: contain; }
.feed-label {
  position: absolute;
  left: 2px;
  bottom: 2px;
  padding: 2px 3px;
  color: #f9ecc9;
  background: rgba(20, 15, 12, .82);
  font-size: clamp(5px, .45vw, 7px);
}
.feed-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #927e67;
  font-size: clamp(6px, .55vw, 9px);
  text-align: center;
}
.feed.live .feed-placeholder { display: none; }

.wasd-hint {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: grid;
  grid-template-columns: repeat(3, 28px);
  gap: 3px;
  opacity: .82;
  pointer-events: none;
}
.wasd-hint kbd { height: 28px; display: grid; place-items: center; color: #fff4ce; background: #38281f; border: 2px solid #160f0c; box-shadow: inset 0 -3px #211712; font-size: 11px; }

.controlbar { flex-wrap: wrap; }
.identity { display: flex; align-items: center; gap: 10px; min-width: 150px; }
.identity small, .identity strong { display: block; }
.identity small { color: var(--ink-soft); font-size: 9px; }
.self-color { width: 28px; height: 28px; border: 3px solid var(--wood-dark); background: var(--green); }
.media-controls { display: flex; gap: 10px; }
.media-controls .pixel-button { display: inline-flex; align-items: center; gap: 8px; }
.control-icon { width: 16px; height: 12px; display: inline-block; position: relative; border: 2px solid currentColor; }
.camera-icon::after { content: ""; position: absolute; right: -7px; top: 1px; border: 4px solid transparent; border-left: 5px solid currentColor; }
.screen-icon::after { content: ""; position: absolute; width: 8px; left: 2px; bottom: -6px; border-bottom: 2px solid currentColor; }
.invite { background: #d8b986; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  max-width: min(92vw, 560px);
  padding: 11px 16px;
  color: #fff9df;
  background: #30231c;
  border: 3px solid #c88b50;
  box-shadow: 0 5px 0 rgba(0,0,0,.38);
  transform: translate(-50%, 150%);
  transition: transform .18s ease;
  font-size: 12px;
}
.toast.show { transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .workspace { padding: 8px; gap: 8px; min-width: 720px; transform-origin: top left; }
  body.game-active { overflow-x: auto; }
  .topbar, .controlbar { padding: 8px 10px; }
  .controlbar { justify-content: center; }
  .identity { display: none; }
  .station-media { min-width: 110px; }
}

@media (max-height: 720px) and (min-width: 800px) {
  .workspace { padding: 8px; gap: 8px; }
  .topbar, .controlbar { min-height: 54px; }
  .pixel-button { min-height: 38px; padding-block: 7px; }
}
