:root {
  --bg: #1b0f2e;
  --ink: #fff;
  --accent: #ffcf3a;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    "Noto Sans CJK SC", "Source Han Sans SC", "WenQuanYi Micro Hei", sans-serif;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  position: fixed;
  inset: 0;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  font-family: var(--font);
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  display: block;
  touch-action: none;
  image-rendering: auto;
}

#rotate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(20, 8, 40, 0.94);
  color: var(--ink);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
}

#rotate p {
  margin: 0;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 1px;
}

#rotate button {
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: transparent;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 999px;
  padding: 8px 20px;
}

#rotate .phone {
  width: 54px;
  height: 92px;
  border: 5px solid var(--accent);
  border-radius: 12px;
  animation: turn 1.8s ease-in-out infinite;
}

@keyframes turn {
  0%, 20% { transform: rotate(0deg); }
  60%, 100% { transform: rotate(-90deg); }
}

@media (orientation: portrait) {
  body:not(.portrait-ok) #rotate { display: flex; }
}

/* nickname box and share card: real HTML above the canvas so phone keyboards and long-press save work */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 5vh 16px;
  box-sizing: border-box;
  background: rgba(12, 4, 26, 0.8);
  color: var(--ink);
}

.overlay[hidden] { display: none; }

.overlay .card {
  width: min(420px, 100%);
  box-sizing: border-box;
  padding: 18px 20px;
  border: 3px solid var(--accent);
  border-radius: 18px;
  background: #2a1240;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.overlay h2 { margin: 0 0 6px; font-size: 22px; font-weight: 900; }
.overlay p { margin: 0 0 12px; font-size: 15px; opacity: 0.88; }

#nick-input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  font: inherit;
  font-size: 18px;
  color: #24103d;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 10px;
  -webkit-user-select: text;
  user-select: text;
}

.overlay .row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
}

.overlay .row button, .overlay .row .btn {
  font: inherit;
  font-size: 16px;
  font-weight: 900;
  padding: 10px 20px;
  border: 2px solid #24103d;
  border-radius: 999px;
  color: #2a1240;
  background: linear-gradient(#ffe066, #ff9a1f);
  text-decoration: none;
  cursor: pointer;
}

.overlay .row .ghost {
  color: var(--ink);
  background: transparent;
  border-color: rgba(255, 255, 255, 0.5);
}

.overlay .row [hidden] { display: none; }

.share-card { width: min(460px, 100%); }
.share-card .tip { margin: 10px 0 0; }

#share-img {
  display: block;
  max-width: 100%;
  max-height: 64vh;
  margin: 0 auto;
  border-radius: 12px;
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
}
