@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600;700&display=swap');

:root {
  --bg: #14120e;
  --panel: #1d1a14;
  --line: #3a3428;
  --amber: #e8a33d;
  --amber-dim: #8a6428;
  --red: #d9482e;
  --text: #d8cfbe;
  --muted: #7d745f;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Mono', monospace;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#app {
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

h1, h2 { font-weight: 700; letter-spacing: 0.06em; }
button {
  font-family: inherit;
  font-weight: 600;
  background: var(--panel);
  color: var(--amber);
  border: 1px solid var(--amber-dim);
  padding: 14px 18px;
  font-size: 16px;
  cursor: pointer;
  letter-spacing: 0.04em;
}
button:active { background: var(--amber-dim); color: var(--bg); }
button:disabled { opacity: 0.4; }
input {
  font-family: inherit;
  font-size: 16px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 12px;
  width: 100%;
  letter-spacing: 0.08em;
  -webkit-user-select: text;
  user-select: text;
}

.lobby {
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.logo { font-size: 26px; color: var(--amber); }
.logo small { display: block; font-size: 11px; color: var(--muted); font-weight: 400; margin-top: 4px; letter-spacing: 0.12em; }
.srv-status { font-size: 11px; color: var(--muted); }
.srv-status b { color: var(--text); font-weight: 400; }

.panel { border: 1px solid var(--line); background: var(--panel); padding: 14px; }
.panel h2 { font-size: 12px; color: var(--muted); margin-bottom: 10px; letter-spacing: 0.1em; }

.btn-row { display: flex; gap: 10px; }
.btn-row button { flex: 1; }

.code-display {
  font-size: 34px;
  text-align: center;
  color: var(--amber);
  letter-spacing: 0.3em;
  padding: 16px 0;
  border: 1px dashed var(--amber-dim);
  margin-bottom: 10px;
}

.player-line { display: flex; justify-content: space-between; padding: 8px 0; font-size: 14px; }
.player-line .st-ready { color: var(--amber); }
.player-line .st-wait { color: var(--muted); }

.lb-row { display: flex; justify-content: space-between; font-size: 12px; padding: 4px 0; color: var(--muted); }
.lb-row.me { color: var(--amber); }
.lb-row span:first-child { flex: 1; }
.lb-row .mmr { min-width: 52px; text-align: right; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--red); color: var(--red);
  padding: 10px 18px; font-size: 13px; z-index: 50;
}

.game { position: relative; flex: 1; min-height: 0; overflow: hidden; }
canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hud-top {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top));
  pointer-events: none; font-size: 13px; gap: 8px;
}
.hud-res { display: flex; gap: 12px; background: rgba(20,18,14,0.85); border: 1px solid var(--line); padding: 6px 10px; }
.hud-res b { color: var(--amber); font-weight: 600; }
.hud-shield { background: rgba(20,18,14,0.85); border: 1px solid var(--line); padding: 6px 10px; }
.hud-shield.warn { color: var(--red); border-color: var(--red); }
.hud-ping { color: var(--muted); font-size: 11px; align-self: center; }

.ralog {
  position: absolute; right: 8px; bottom: calc(72px + env(safe-area-inset-bottom));
  width: min(300px, 62vw); max-height: 26vh; overflow: hidden;
  background: rgba(20,18,14,0.88); border: 1px solid var(--line);
  font-size: 11px; line-height: 1.5; padding: 8px 10px;
  pointer-events: none; color: var(--muted);
  display: flex; flex-direction: column; justify-content: flex-end;
}
.ralog div:last-child { color: var(--text); }

.action-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; gap: 6px; padding: 8px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: rgba(20,18,14,0.9); border-top: 1px solid var(--line);
  overflow-x: auto; touch-action: pan-x;
}
.action-bar button {
  flex: 0 0 auto; padding: 12px 14px; font-size: 13px; min-width: 84px;
  white-space: nowrap;
}
.action-bar button.armed { background: var(--amber-dim); color: var(--bg); }
.action-bar button.sel { border-color: var(--amber); background: #2a251b; }
.action-bar .gap { flex: 1; }

.radial {
  position: absolute; z-index: 30;
  width: 220px; height: 220px; margin: -110px 0 0 -110px;
  pointer-events: none;
}
.radial button {
  position: absolute; width: 64px; height: 64px; border-radius: 50%;
  font-size: 10px; padding: 4px; line-height: 1.2; pointer-events: auto;
  display: flex; align-items: center; justify-content: center; text-align: center;
}
.radial button:active { background: var(--amber); }

.build-menu {
  position: absolute; z-index: 30; left: 50%; bottom: 110px;
  transform: translateX(-50%);
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  background: rgba(20,18,14,0.94); border: 1px solid var(--amber-dim);
  padding: 12px; width: min(340px, 92vw);
}
.build-menu button { font-size: 11px; padding: 10px 6px; min-width: 0; }
.build-menu button small { display: block; color: var(--muted); font-size: 10px; font-weight: 400; }
.build-menu .close { grid-column: 1 / -1; border-color: var(--line); color: var(--muted); }

.over {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 24px; text-align: center;
}
.over .verdict { font-size: 30px; letter-spacing: 0.1em; }
.over .verdict.win { color: var(--amber); }
.over .verdict.lose { color: var(--red); }
.over .detail { color: var(--muted); font-size: 13px; white-space: pre-line; }
.medal { border: 1px solid var(--amber-dim); color: var(--amber); padding: 6px 14px; font-size: 12px; }

.overlay-msg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(20,18,14,0.7); z-index: 40; font-size: 18px; color: var(--amber);
  letter-spacing: 0.15em; pointer-events: none;
}

@media (max-width: 380px) {
  .action-bar button { min-width: 70px; padding: 10px 10px; font-size: 12px; }
}
