:root {
  --bg: #0b0e14;
  --ink: #e8f1ff;
  --dim: #8fa0bd;
  --me: #5cf2c5;
  --them: #ff7a9a;
  --card: rgba(13, 18, 30, 0.94);
  --line: rgba(232, 241, 255, 0.16);
  color-scheme: dark;
}
* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
/* fixed body stops iOS rubber-banding / address-bar jiggle during play */
body { position: fixed; inset: 0; touch-action: none; }

canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

#safe {
  position: fixed; visibility: hidden; pointer-events: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#hud {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 12px) 0 calc(env(safe-area-inset-left) + 12px);
  pointer-events: none;
  font: 12px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--dim);
  z-index: 5;
}
#hud button {
  pointer-events: auto; min-height: 32px; padding: 0 10px; font-size: 12px; border-radius: 8px;
  background: rgba(26, 34, 51, 0.7); color: var(--dim);
}
#net { padding-top: 8px; }
.hudbtns { display: flex; gap: 8px; }
#leave.confirm { background: var(--them); color: #1a0710; border-color: transparent; }
.botrow { display: grid; gap: 8px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { min-height: 40px; border: 0; border-radius: 0; background: transparent; color: var(--dim); padding: 0 8px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: #1f2a42; color: var(--ink); }
#net.ok { color: var(--me); }
#net.bad { color: var(--them); }

#banner {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none; text-align: center; z-index: 4; padding: 24px;
}
#bigtxt { font: 800 min(22vmin, 140px)/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; color: var(--ink); text-shadow: 0 0 30px rgba(92, 242, 197, 0.35); }
#bigtxt.small { font-size: min(8vmin, 44px); line-height: 1.2; }
#subtxt { margin-top: 12px; color: var(--dim); font-size: 16px; }

.panel {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(92vw, 360px); max-height: 96%; overflow: auto;
  padding: 24px 22px; text-align: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  z-index: 6;
}
.panel.hidden, .hidden { display: none; }
h1 { margin: 0; font: 800 54px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0.18em; padding-left: 0.18em; }
h2 { margin: 0 0 6px; font: 800 30px/1.1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0.06em; }
.tag { margin: 6px 0 20px; color: var(--dim); }
.label { margin: 0; color: var(--dim); font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase; }
.bigcode { font: 800 56px/1.15 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0.22em; padding-left: 0.22em; margin: 4px 0 8px; color: var(--me); }
.note { margin: 0 0 18px; color: var(--dim); font-size: 14px; }
.note b { color: var(--ink); font-weight: 600; }

.stack { display: grid; gap: 12px; }
.joinrow { display: grid; grid-template-columns: 1fr auto; gap: 10px; }

button {
  font: inherit; font-weight: 600; min-height: 48px; padding: 0 20px;
  color: var(--ink); background: #1a2233; border: 1px solid var(--line); border-radius: 12px;
  cursor: pointer; touch-action: manipulation;
}
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.5; }
button.primary { background: var(--me); color: #04130e; border-color: transparent; font-weight: 800; }
button.ghost { background: transparent; }

input {
  font: 700 22px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; /* >=16px stops iOS focus-zoom */
  letter-spacing: 0.3em; text-align: center; text-transform: uppercase;
  min-height: 48px; min-width: 0; padding: 0 8px;
  color: var(--ink); background: #0f1523; border: 1px solid var(--line); border-radius: 12px;
  -webkit-user-select: text; user-select: text;
}
input::placeholder { color: #44506a; letter-spacing: 0.2em; }
input:focus { outline: 2px solid var(--me); outline-offset: 1px; }

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%);
  max-width: 90vw; padding: 10px 16px; border-radius: 999px;
  background: rgba(232, 241, 255, 0.95); color: #0b0e14; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 10; text-align: center;
}
#toast.show { opacity: 1; }

/* short landscape screens (phones on their side) */
@media (max-height: 520px) {
  .panel { padding: 14px 18px; width: min(92vw, 480px); }
  h1 { font-size: 34px; }
  .tag { margin: 2px 0 10px; }
  .bigcode { font-size: 40px; }
  .note { margin-bottom: 10px; font-size: 13px; }
  .stack { gap: 8px; }
  button, input { min-height: 42px; }
  h2 { font-size: 24px; }
}
