* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --ink: #14201c;
  --muted: #4d635a;
  --paper: #eef5f1;
  --mint: #7ec8a3;
  --teal: #1f6f5b;
  --coral: #e07a5f;
  --line: rgba(20, 32, 28, 0.12);
}

html,
body {
  height: 100%;
}

body {
  font-family: "IBM Plex Sans", "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(900px 480px at 0% 0%, rgba(126, 200, 163, 0.35), transparent 60%),
    radial-gradient(800px 420px at 100% 10%, rgba(31, 111, 91, 0.18), transparent 55%),
    var(--paper);
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(0px, env(safe-area-inset-top))
    max(0px, env(safe-area-inset-right))
    max(0px, env(safe-area-inset-bottom))
    max(0px, env(safe-area-inset-left));
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#box {
  position: relative;
  width: min(480px, 100vw);
  max-height: 100dvh;
  padding: clamp(0.8rem, 3vw, 1.4rem);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.back-home {
  align-self: flex-start;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--teal);
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
}

.back-home:active {
  background: rgba(255, 255, 255, 0.85);
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 0.95rem;
}

.hud-item span {
  color: var(--teal);
  font-weight: 800;
  font-size: 1.05rem;
}

.stage {
  position: relative;
  width: min(100%, calc(100dvh - 210px));
  aspect-ratio: 1;
  margin: 0 auto;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 14px;
  background: #f4faf6;
  box-shadow: 0 8px 30px rgba(31, 111, 91, 0.18);
  border: 1px solid var(--line);
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(20, 32, 28, 0.45);
  backdrop-filter: blur(4px);
  border-radius: 14px;
  padding: 16px;
}

.overlay.show {
  display: flex;
}

.overlay-card {
  text-align: center;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 14px;
  padding: 1.4rem 1.6rem;
  max-width: 82%;
}

.overlay-card h1 {
  font-size: 1.6rem;
  margin-bottom: 0.5rem;
  color: var(--teal);
}

.overlay-card p {
  color: var(--muted);
  font-size: 0.92rem;
  margin-bottom: 1.1rem;
  line-height: 1.4;
}

.overlay-card .diff-label {
  font-size: 0.82rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  margin-bottom: 0.55rem;
}

.overlay-card .diff-list {
  display: inline-flex;
  gap: 0.45rem;
  margin-bottom: 1.1rem;
  padding: 3px;
  border-radius: 10px;
  background: rgba(31, 111, 91, 0.08);
}

.overlay-card .diff-btn {
  font: inherit;
  font-weight: 600;
  padding: 0.45rem 0.85rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.overlay-card .diff-btn.active {
  background: #fff;
  color: var(--teal);
  box-shadow: 0 2px 8px rgba(20, 32, 28, 0.12);
}

.overlay-card .primary-btn {
  font: inherit;
  font-weight: 700;
  padding: 0.6rem 1.6rem;
  border: none;
  border-radius: 10px;
  background: var(--teal);
  color: #fff;
  cursor: pointer;
}

.overlay-card .primary-btn:active {
  background: #175040;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 56px);
  gap: 0.4rem;
  justify-content: center;
  margin: 0 auto;
}

.dpad-btn {
  font-size: 1.4rem;
  line-height: 1;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.6);
  color: var(--teal);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dpad-btn:active {
  background: var(--mint);
  color: #fff;
}

.dpad .up { grid-column: 2; grid-row: 1; }
.dpad .left { grid-column: 1; grid-row: 2; }
.dpad .down { grid-column: 2; grid-row: 3; }
.dpad .right { grid-column: 3; grid-row: 2; }

.tip {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
}

@media (max-height: 640px) {
  .stage {
    width: min(100%, calc(100dvh - 150px));
  }

  .dpad {
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(3, 44px);
  }

  .tip {
    display: none;
  }
}
