:root {
  --ink: #101018;
  --panel: #d8d0b8;
  --panel-dark: #6b654f;
  --line: #2a2830;
  --grass: #40a040;
  --water: #4080c8;
  --red: #c84040;
  --blue: #4040c8;
  --yellow: #c8c840;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #191923;
  color: var(--ink);
  font-family: "Courier New", ui-monospace, monospace;
  image-rendering: pixelated;
}

button,
input {
  font: inherit;
}

#app {
  display: grid;
  grid-template-columns: 164px minmax(320px, 1fr) 216px;
  grid-template-rows: 72px minmax(0, 1fr);
  gap: 8px;
  width: 100vw;
  height: 100vh;
  padding: 8px;
  background:
    linear-gradient(45deg, rgba(255,255,255,.035) 25%, transparent 25%) 0 0 / 8px 8px,
    #232332;
}

.pixel-panel {
  background: var(--panel);
  border: 4px solid var(--line);
  box-shadow: inset -4px -4px 0 var(--panel-dark), inset 4px 4px 0 #fff6d8;
}

#topbar {
  grid-column: 1 / 4;
  display: grid;
  grid-template-columns: 160px repeat(5, minmax(90px, 1fr)) 260px;
  gap: 8px;
  align-items: center;
  padding: 8px 14px;
}

.brand {
  color: #f8f0d0;
  background: #305870;
  border: 3px solid #101018;
  padding: 8px;
  text-align: center;
  font-weight: 700;
}

.stat span {
  display: block;
  color: #504838;
  font-size: 11px;
  line-height: 1;
}

.stat strong {
  display: block;
  font-size: 16px;
  white-space: nowrap;
}

#players {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.player-chip {
  min-width: 0;
  padding: 5px;
  border: 2px solid #222;
  background: #eee1bd;
  font-size: 11px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-chip.empty { opacity: .45; }

#toolbar,
#sidebar {
  padding: 10px;
  overflow: hidden auto;
}

#toolbar {
  display: grid;
  align-content: start;
  gap: 7px;
}

.tool-btn {
  width: 100%;
  min-height: 48px;
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  gap: 7px;
  padding: 5px;
  border: 3px solid #222;
  background: #eee1bd;
  cursor: pointer;
}

.tool-btn.active {
  background: #fff0a0;
  box-shadow: inset 0 0 0 3px #c84040;
}

.tool-icon {
  width: 30px;
  height: 30px;
  border: 2px solid #222;
  position: relative;
}

.tool-label {
  display: grid;
  min-width: 0;
  font-size: 12px;
  line-height: 1.1;
  text-align: left;
}

.tool-label b { overflow: hidden; text-overflow: ellipsis; }
.tool-label span { color: #5d563f; font-size: 11px; }

#stage {
  position: relative;
  overflow: hidden;
  border: 4px solid #101018;
  background: #000;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  cursor: crosshair;
}

#sidebar {
  display: grid;
  align-content: start;
  gap: 12px;
}

#minimap {
  width: 100%;
  height: auto;
  border: 3px solid #202028;
  background: #111;
}

.rci {
  display: grid;
  gap: 8px;
}

.rci div {
  display: grid;
  grid-template-columns: 20px 1fr 42px;
  align-items: center;
  gap: 5px;
  font-weight: 700;
}

meter {
  width: 100%;
  height: 18px;
}

.tax {
  display: grid;
  grid-template-columns: 38px 1fr 42px;
  align-items: center;
  gap: 7px;
}

.speed {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.speed button,
#readyBtn {
  border: 3px solid #222;
  background: #f2deb0;
  padding: 7px;
  cursor: pointer;
}

.speed button.active,
#readyBtn.ready {
  background: #a0e090;
}

.problems {
  display: grid;
  gap: 5px;
  padding: 8px;
  border: 3px solid #222;
  background: #eee1bd;
}

#messages {
  display: grid;
  gap: 6px;
  font-size: 11px;
  line-height: 1.25;
}

.msg {
  padding: 7px;
  border-left: 5px solid #4070b0;
  background: #fff0c0;
}

#toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  width: min(520px, calc(100% - 28px));
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 12px;
  align-items: center;
  padding: 12px;
  pointer-events: none;
}

#toast.hidden { display: none; }

.wright-face {
  width: 48px;
  height: 48px;
  border: 3px solid #202028;
  background:
    linear-gradient(#38a060 0 24%, transparent 24%),
    linear-gradient(90deg, transparent 0 28%, #101018 28% 36%, transparent 36% 64%, #101018 64% 72%, transparent 72%),
    linear-gradient(#ffd898 0 62%, #284070 62%);
}

#toastText {
  margin: 0;
  font-weight: 700;
}

#lobby {
  position: absolute;
  inset: 24px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 14px;
  background: #d8d0b8;
}

#lobby.hidden { display: none; }

#lobby h1 {
  margin: 0;
  font-size: 44px;
  color: #305870;
  text-shadow: 3px 3px #f8f0d0;
}

#slots {
  display: grid;
  grid-template-columns: repeat(4, minmax(90px, 1fr));
  width: min(560px, 92%);
  gap: 8px;
}

.slot {
  padding: 12px 8px;
  border: 3px solid #222;
  background: #eee1bd;
  text-align: center;
}

.slot.empty { opacity: .45; }

@media (max-width: 880px) {
  #app {
    grid-template-columns: 116px minmax(0, 1fr);
    grid-template-rows: 84px minmax(0, 1fr) 170px;
  }
  #topbar {
    grid-column: 1 / 3;
    grid-template-columns: repeat(4, 1fr);
  }
  .brand,
  .room,
  #players {
    display: none;
  }
  #sidebar {
    grid-column: 1 / 3;
    grid-row: 3;
    grid-template-columns: 150px 1fr 1fr;
    overflow: hidden;
  }
  #slots { grid-template-columns: repeat(2, 1fr); }
}
