* { box-sizing: border-box; }
html {
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #120a07;
  color: #f7e7c0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}
#stage, #game { touch-action: none; user-select: none; -webkit-user-select: none; }
#stage {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
body.playing #stage { pointer-events: auto; }
#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #120a07;
}
#rotate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  align-items: center;
  justify-content: center;
  background: #120a07;
  font-size: 18px;
  color: #d4a24a;
  pointer-events: none;
}
body.playing.need-rotate #rotate { display: none !important; }
body.playing.need-rotate #stage {
  inset: auto;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(90deg);
  transform-origin: center center;
}

#auth {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: auto;
  touch-action: auto;
  pointer-events: auto;
  background: radial-gradient(circle at 50% 20%, #5c1c1c, #120a07 70%);
}
#auth.hidden { display: none !important; }
.card {
  width: min(420px, 100%);
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(212,162,74,0.35);
  border-radius: 16px;
  padding: 22px 22px 18px;
  pointer-events: auto;
}
.kicker { color: #d4a24a; font-size: 12px; letter-spacing: 1px; }
h1 { margin: 8px 0 6px; font-size: 26px; color: #fff7e6; }
h2 { margin: 0 0 10px; font-size: 18px; color: #fff7e6; }
.hint, #modalText { color: rgba(243,230,200,0.7); font-size: 13px; line-height: 1.5; }
label { display: block; margin: 12px 0 6px; font-size: 13px; color: #d4a24a; }
input {
  width: 100%;
  height: 42px;
  border-radius: 10px;
  border: 1px solid rgba(212,162,74,0.35);
  background: rgba(255,247,230,0.08);
  color: #fff7e6;
  padding: 0 12px;
  font-size: 16px;
  outline: none;
  pointer-events: auto;
  user-select: text;
  -webkit-user-select: text;
}
.row { display: flex; gap: 10px; margin-top: 16px; }
button {
  flex: 1;
  height: 42px;
  border: 1px solid rgba(212,162,74,0.45);
  border-radius: 10px;
  background: rgba(255,247,230,0.08);
  color: #f7e7c0;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: rgba(212,162,74,0.35);
}
button.primary { background: #8e1f1a; color: #fff7e6; border-color: #d4a24a; }
.err { min-height: 18px; margin-top: 8px; color: #ff8b8b; font-size: 13px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 18%;
  transform: translateX(-50%);
  z-index: 50;
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(0,0,0,0.72);
  color: #fff7e6;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s;
}
#toast.show { display: block; opacity: 1; }

#modal {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.45);
  padding: 20px;
}
#loading {
  position: fixed;
  inset: 0;
  z-index: 42;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.35);
}
#modal.hidden, #loading.hidden,
#modal[hidden], #loading[hidden], #rotate[hidden] {
  display: none !important;
  pointer-events: none !important;
}
#loading span {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(212,162,74,0.25);
  border-top-color: #d4a24a;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
