html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #05060a;
  overflow: hidden;
}

#wrap {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #05060a;
}

#screen {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #05060a;
}

#namebox {
  position: fixed;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  display: none;
  width: 240px;
  max-width: 78vw;
  padding: 8px 10px;
  background: #0a0d16;
  border: 2px solid #c8b06a;
  color: #e8ecf4;
  font-family: 'Galmuri9', 'Galmuri11', monospace;
  font-size: 18px;
  text-align: center;
  outline: none;
  letter-spacing: 2px;
  z-index: 20;
  touch-action: auto;
  -webkit-user-select: text;
  user-select: text;
}

#namebox::placeholder {
  color: #4a5268;
  letter-spacing: 1px;
}

#roompanel {
  position: fixed;
  left: 50%;
  top: 53%;
  transform: translate(-50%, -50%);
  display: none;
  flex-direction: column;
  gap: 7px;
  width: 264px;
  max-width: 84vw;
  z-index: 20;
}

#roomlink {
  width: 100%;
  box-sizing: border-box;
  padding: 7px 8px;
  background: #0a0d16;
  border: 2px solid #5a6a8a;
  color: #cfe0f0;
  font-family: 'Galmuri9', 'Galmuri11', monospace;
  font-size: 12px;
  text-align: center;
  outline: none;
  touch-action: auto;
  -webkit-user-select: all;
  user-select: all;
}

#roomcopy {
  padding: 9px;
  background: #2a3a26;
  border: 2px solid #6a8a5a;
  color: #d8f0c8;
  font-family: 'Galmuri9', 'Galmuri11', monospace;
  font-size: 13px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

#roomcopy:active { background: #3c5236; }

#sharebtn {
  position: fixed;
  display: none;
  box-sizing: border-box;
  padding: 0 2px;
  background: rgba(36, 26, 12, 0.92);
  border: 1.5px solid #cda44e;
  border-radius: 4px;
  color: #f0d878;
  font-family: 'Galmuri9', 'Galmuri11', monospace;
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
  text-align: center;
  z-index: 30;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

#sharebtn:active { background: rgba(58, 42, 18, 0.96); }

#authpanel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: none;
  flex-direction: column;
  gap: 8px;
  width: 286px;
  max-width: 88vw;
  padding: 14px;
  box-sizing: border-box;
  background: rgba(12, 10, 16, 0.96);
  border: 2px solid #c8b06a;
  border-radius: 6px;
  z-index: 25;
}

#authpanel input {
  box-sizing: border-box;
  width: 100%;
  padding: 9px 10px;
  background: #0a0d16;
  border: 2px solid #5a6a8a;
  border-radius: 3px;
  color: #e8ecf4;
  font-family: 'Galmuri9', 'Galmuri11', monospace;
  font-size: 15px;
  text-align: center;
  outline: none;
  letter-spacing: 1px;
  touch-action: auto;
  -webkit-user-select: text;
  user-select: text;
}

#authpanel input::placeholder { color: #4a5268; letter-spacing: 0; }
#authpanel input:focus { border-color: #c8b06a; }
#auth_code { text-transform: uppercase; }

.auth-msg {
  min-height: 13px;
  font-family: 'Galmuri9', 'Galmuri11', monospace;
  font-size: 11px;
  text-align: center;
  line-height: 1.35;
  color: #8a8268;
}
.auth-msg.auth-err { color: #e08a6a; }
.auth-msg.auth-info { color: #c8b06a; }

#authpanel button {
  padding: 10px 6px;
  border-radius: 3px;
  font-family: 'Galmuri9', 'Galmuri11', monospace;
  font-size: 13px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

#auth_row { display: flex; gap: 7px; }
#auth_row button { flex: 1; }
#auth_go { background: #2a3a26; border: 2px solid #6a8a5a; color: #d8f0c8; }
#auth_go:active { background: #3c5236; }
#auth_alt { background: #1a1d2a; border: 2px solid #5a6a8a; color: #c8d4e8; }
#auth_alt:active { background: #2a3040; }
#auth_back { width: 100%; background: #1a160e; border: 2px solid #5a5040; color: #b0a888; padding: 8px; font-size: 12px; }
#auth_back:active { background: #2a2418; }

body.touch {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#touchui {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  font-family: 'Galmuri9', sans-serif;
}

#touchui > * {
  pointer-events: auto;
}

#dpad {
  position: absolute;
  left: calc(8px + env(safe-area-inset-left));
  bottom: calc(12px + env(safe-area-inset-bottom));
  width: 112px;
  height: 112px;
  opacity: 0.55;
}

.dp {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 22, 36, 0.72);
  border: 1px solid #4a5474;
  color: #aab2c8;
  font-size: 13px;
}

.dp-u { left: 38px; top: 0; width: 36px; height: 38px; border-radius: 6px 6px 0 0; }
.dp-d { left: 38px; bottom: 0; width: 36px; height: 38px; border-radius: 0 0 6px 6px; }
.dp-l { left: 0; top: 38px; width: 38px; height: 36px; border-radius: 6px 0 0 6px; }
.dp-r { right: 0; top: 38px; width: 38px; height: 36px; border-radius: 0 6px 6px 0; }
.dp-c { left: 38px; top: 38px; width: 36px; height: 36px; background: rgba(18, 22, 36, 0.5); border: none; }

.tbtn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 22, 36, 0.72);
  border: 1px solid #4a5474;
  color: #aab2c8;
  opacity: 0.6;
}

.tbtn.on {
  background: rgba(64, 74, 108, 0.85);
  opacity: 0.95;
}

#btnz {
  position: absolute;
  right: calc(18px + env(safe-area-inset-right));
  bottom: calc(14px + env(safe-area-inset-bottom));
  width: 62px;
  height: 62px;
  border-radius: 50%;
  font-size: 22px;
  color: #e8c060;
  border-color: #6a5a34;
}

#btnx {
  position: absolute;
  right: calc(26px + env(safe-area-inset-right));
  bottom: calc(92px + env(safe-area-inset-bottom));
  width: 46px;
  height: 46px;
  border-radius: 50%;
  font-size: 16px;
}
