:root {
  --paper: #f4f1e8;
  --paper-dark: #e8e4d7;
  --ink-deep: #1a1a1a;
  --ink-mid: #3d3d3d;
  --ink-light: #6b6b6b;
  --ink-wash: rgba(26, 26, 26, 0.08);
  --seal-red: #b83c2d;
  --seal-red-soft: rgba(184, 60, 45, 0.85);
  --font-display: "Ma Shan Zheng", "Noto Serif SC", serif;
  --font-body: "Noto Serif SC", "Songti SC", serif;
  --radius: 6px;
  --transition: 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--paper);
  color: var(--ink-deep);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

.game-stage {
  position: relative;
  width: 100vw;
  height: 100vh;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---- Paper & ink atmosphere ---- */
.paper-texture,
.ink-wash,
.seal {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.paper-texture {
  opacity: 0.28;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}

.ink-wash {
  opacity: 0.14;
  background: radial-gradient(circle at 20% 20%, rgba(26, 26, 26, 0.35) 0%, transparent 45%),
              radial-gradient(circle at 85% 75%, rgba(26, 26, 26, 0.28) 0%, transparent 40%);
}

.seal {
  z-index: 20;
  top: auto;
  left: auto;
  right: 36px;
  bottom: 36px;
  width: 56px;
  height: 56px;
  border: 2px solid var(--seal-red);
  color: var(--seal-red);
  font-family: var(--font-display);
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  opacity: 0.75;
  transform: rotate(-4deg);
  box-shadow: inset 0 0 10px rgba(184, 60, 45, 0.15);
}

/* ---- HUD ---- */
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  padding: 32px 40px;
  gap: 24px;
  pointer-events: none;
}

.hud-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hud-block--right {
  align-items: flex-end;
}

.hud-block--center {
  align-items: center;
}

.hud-label {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.32em;
  color: var(--ink-light);
}

.hud-value {
  font-family: var(--font-display);
  font-size: 46px;
  font-weight: 400;
  line-height: 1;
  color: var(--ink-deep);
}

.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
}

.logo__main {
  font-family: var(--font-display);
  font-size: 38px;
  color: var(--ink-deep);
  letter-spacing: 0.18em;
}

.logo__sub {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 300;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--ink-light);
}

/* ---- Overlays ---- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(244, 241, 232, 0.78);
  opacity: 0;
  visibility: hidden;
  transition: opacity 380ms ease, visibility 380ms ease;
  backdrop-filter: blur(3px);
}

.overlay--active {
  opacity: 1;
  visibility: visible;
}

.overlay__panel {
  width: min(500px, 90vw);
  padding: 52px 44px;
  border: 1px solid rgba(26, 26, 26, 0.18);
  border-radius: var(--radius);
  background: rgba(248, 245, 238, 0.92);
  box-shadow: 0 24px 60px rgba(26, 26, 26, 0.08), 0 0 0 1px rgba(255, 255, 255, 0.6) inset;
  text-align: center;
  transform: translateY(18px) scale(0.98);
  transition: transform 420ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.overlay--active .overlay__panel {
  transform: translateY(0) scale(1);
}

.overlay__kicker {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.42em;
  color: var(--ink-light);
  margin-bottom: 14px;
}

.overlay__kicker--alert {
  color: var(--seal-red-soft);
}

.overlay__title {
  font-family: var(--font-display);
  font-size: 52px;
  font-weight: 400;
  line-height: 1.1;
  color: var(--ink-deep);
  margin-bottom: 18px;
}

.overlay__copy {
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.7;
  color: var(--ink-mid);
  margin-bottom: 28px;
}

.overlay__stat {
  color: var(--seal-red);
  font-weight: 700;
}

.overlay__controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 32px;
  font-size: 13px;
  color: var(--ink-light);
}

kbd {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 4px;
  border: 1px solid rgba(26, 26, 26, 0.2);
  background: rgba(26, 26, 26, 0.04);
  color: var(--ink-deep);
}

/* ---- Buttons ---- */
.ink-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 16px 48px;
  border: none;
  border-radius: 0;
  cursor: pointer;
  background: transparent;
  color: var(--ink-deep);
  transition: transform var(--transition);
}

.ink-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid var(--ink-deep);
  border-radius: var(--radius);
  opacity: 0.85;
  transform: skewX(-4deg);
}

.ink-btn--secondary::before {
  border-color: var(--seal-red);
}

.ink-btn:hover {
  transform: translateY(-2px);
}

.ink-btn:hover::before {
  background: rgba(26, 26, 26, 0.04);
}

.ink-btn--secondary:hover::before {
  background: rgba(184, 60, 45, 0.06);
}

.ink-btn__brush {
  position: absolute;
  bottom: 8px;
  left: 50%;
  width: 60%;
  height: 3px;
  background: var(--ink-deep);
  opacity: 0.2;
  transform: translateX(-50%) scaleX(0.8);
  filter: blur(1px);
  transition: opacity var(--transition), transform var(--transition);
}

.ink-btn--secondary .ink-btn__brush {
  background: var(--seal-red);
}

.ink-btn:hover .ink-btn__brush {
  opacity: 0.45;
  transform: translateX(-50%) scaleX(1.1);
}

.ink-btn__text {
  position: relative;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  letter-spacing: 0.2em;
}

/* ---- Mobile tweaks ---- */
@media (max-width: 640px) {
  .hud {
    padding: 22px 24px;
  }

  .hud-value {
    font-size: 32px;
  }

  .logo__main {
    font-size: 28px;
  }

  .logo__sub {
    font-size: 10px;
  }

  .overlay__title {
    font-size: 40px;
  }

  .overlay__panel {
    padding: 38px 28px;
  }

  .seal {
    width: 44px;
    height: 44px;
    font-size: 22px;
    right: 20px;
    bottom: 20px;
  }
}
