* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #15171c;
  color: #e6e6e6;
  font: 15px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

body { display: flex; flex-direction: column; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: #0d0e11;
  border-bottom: 1px solid #262a33;
}
.logo { font-weight: 700; letter-spacing: 1px; }
.logo small { color: #f0c040; margin-left: 4px; }
.server { font-size: 13px; color: #8a93a3; }

main { flex: 1; display: flex; justify-content: center; align-items: flex-start; padding: 16px; min-height: 0; }
.screen { width: 100%; }
.hidden { display: none !important; }

button {
  font: inherit;
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid #3a404c;
  background: #242832;
  color: #e6e6e6;
  cursor: pointer;
}
button:hover:not(:disabled) { background: #2e3440; }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: #d9a520; border-color: #d9a520; color: #111; font-weight: 700; }
button.primary:hover { background: #f0bb30; }
button.big { font-size: 18px; padding: 12px; width: 100%; }

input {
  font: inherit;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #3a404c;
  background: #101216;
  color: #e6e6e6;
  width: 120px;
  letter-spacing: 2px;
  text-align: center;
}

kbd {
  display: inline-block;
  min-width: 22px;
  padding: 0 5px;
  margin: 0 1px;
  border: 1px solid #454b58;
  border-bottom-width: 2px;
  border-radius: 4px;
  font: 12px/18px monospace;
  text-align: center;
  background: #1c1f26;
}

/* Lobby */
#lobby { max-width: 520px; display: flex; flex-direction: column; gap: 14px; }
#lobby h1 { margin: 12px 0 0; font-size: 34px; text-align: center; color: #f0c040; letter-spacing: 6px; }
.tagline { margin: 0; text-align: center; color: #8a93a3; font-size: 14px; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode { cursor: pointer; }
.mode input { display: none; }
.mode span {
  display: block;
  height: 100%;
  padding: 12px;
  border: 2px solid #2d323c;
  border-radius: 8px;
  background: #1b1e25;
}
.mode b { display: block; font-size: 17px; }
.mode small { color: #8a93a3; }
.mode input:checked + span { border-color: #d9a520; background: #262217; }
.room-row { display: flex; gap: 8px; justify-content: center; }
.msg { min-height: 1.5em; margin: 0; text-align: center; color: #9bd18b; }
.msg.err { color: #ff8a7a; }
.help { font-size: 13px; color: #8a93a3; border-top: 1px solid #262a33; padding-top: 8px; }
.help p { margin: 4px 0; }
.stats { font-size: 12px; color: #6c7482; text-align: center; margin: 0; }

/* Waiting */
#waiting { max-width: 420px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; padding-top: 40px; }
.spinner {
  width: 44px; height: 44px;
  border: 4px solid #2d323c;
  border-top-color: #d9a520;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.room-box { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.room-code { font: 700 44px/1 monospace; letter-spacing: 8px; color: #f0c040; }

/* Game */
#play { display: flex; gap: 16px; justify-content: center; align-items: flex-start; }
.stage { position: relative; flex: 0 1 auto; }
#cv {
  display: block;
  width: min(calc(100vw - 300px), calc((100vh - 90px) * 512 / 448), 1024px);
  aspect-ratio: 512 / 448;
  image-rendering: pixelated;
  background: #636363;
  border-radius: 4px;
}
.side { width: 240px; flex: none; display: flex; flex-direction: column; gap: 10px; }
.card { background: #1b1e25; border: 1px solid #2a2f39; border-radius: 8px; padding: 10px 12px; }
.card-title { font-size: 12px; color: #8a93a3; margin-bottom: 4px; }
.mode-label { font-weight: 700; font-size: 17px; }
.role-label { font-size: 13px; color: #8a93a3; }
.path { font-weight: 700; }
.path.host, .path.srflx { color: #7bdc6a; }
.path.relay { color: #f0b040; }
.detail { font: 11px/1.4 monospace; color: #8a93a3; word-break: break-all; margin: 2px 0 4px; }
.kv { display: flex; justify-content: space-between; font-size: 13px; }
.kv b { font-weight: 600; }
.talkers { display: flex; gap: 8px; margin: 4px 0; }
.talker {
  padding: 2px 10px;
  border-radius: 12px;
  background: #2a2f39;
  font-size: 13px;
  transition: background 0.1s, box-shadow 0.1s;
}
.talker.on { background: #3c8a34; box-shadow: 0 0 0 2px #7bdc6a55; }
#mic { width: 100%; }

/* Touch controls */
.touch { display: none; }
@media (pointer: coarse) {
  #play { flex-direction: column; align-items: center; }
  #cv { width: min(100vw - 16px, (100vh - 250px) * 512 / 448); }
  .side { width: 100%; flex-direction: row; flex-wrap: wrap; }
  .side .card { flex: 1 1 140px; }
  .touch {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 6px 0;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
  }
  .dpad { position: relative; width: 150px; height: 150px; }
  .dpad button, .fire { position: absolute; width: 52px; height: 52px; padding: 0; font-size: 20px; touch-action: none; }
  .dpad .up { left: 49px; top: 0; }
  .dpad .down { left: 49px; bottom: 0; }
  .dpad .left { left: 0; top: 49px; }
  .dpad .right { right: 0; top: 49px; }
  .fire { position: static; width: 90px; height: 90px; border-radius: 50%; background: #b8321c; border-color: #b8321c; font-size: 18px; }
}
