:root {
  --paper: #ECE8DD;
  --ink: #1C211D;
  --ink-soft: #575D53;
  --moss: #3F5D48;
  --rust: #A15C3B;
  --line: rgba(28, 33, 29, 0.14);
  --serif: 'Fraunces', serif;
  --sans: 'Work Sans', sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent,
      transparent 27px,
      var(--line) 28px
    ),
    var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  text-align: center;
  padding: 24px;
}

.mark {
  margin: 0;
  font-size: 18px;
  color: var(--ink-soft);
  opacity: 0;
  animation: fadeIn 0.6s ease forwards;
}

.name {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(56px, 12vw, 120px);
  line-height: 1;
  overflow: hidden;
}

.name {
  transform: translateY(110%);
  animation: rise 0.7s cubic-bezier(0.22, 1, 0.36, 1) forwards 0.1s;
}

.play-btn {
  display: inline-block;
  margin-top: 12px;
  padding: 14px 32px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: transparent;
  text-decoration: none;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  opacity: 0;
  animation: fadeIn 0.6s ease forwards 0.5s;
}

.play-btn:hover,
.play-btn:focus-visible {
  background: var(--moss);
  border-color: var(--moss);
  color: var(--paper);
}

.play-btn:focus-visible {
  outline: 2px solid var(--rust);
  outline-offset: 3px;
}

@keyframes rise { to { transform: translateY(0); } }
@keyframes fadeIn { to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .mark, .name, .play-btn {
    animation: none;
    transform: none;
    opacity: 1;
  }
}

/* ---- Arcade hub ---- */
.game-wrap {
  max-width: 900px;
  margin: 0 auto;
  padding: 40px 20px 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.hud {
  margin: 0;
  font-size: 14px;
  color: var(--ink-soft);
  max-width: 46ch;
}

.tc-only { display: none; }

@media (pointer: coarse) {
  .kb-only { display: none; }
  .tc-only { display: inline; }
}

.canvas-shell {
  position: relative;
  width: 100%;
}

#world {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 900 / 540;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.prompt {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--paper);
  border: 1px solid var(--ink);
  border-radius: 999px;
  padding: 6px 8px 6px 18px;
  font-size: 14px;
}

.prompt .play-btn {
  margin-top: 0;
  padding: 8px 18px;
  animation: none;
  opacity: 1;
}

.prompt.hidden { display: none; }

.joystick {
  display: none;
  position: absolute;
  left: 18px;
  bottom: 18px;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  border: 1.5px dashed var(--ink-soft);
  background: rgba(236, 232, 221, 0.55);
  touch-action: none;
}

@media (pointer: coarse) {
  .joystick { display: block; }
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 38px;
  height: 38px;
  margin-left: -19px;
  margin-top: -19px;
  border-radius: 50%;
  background: var(--moss);
}

/* ---- Mini-game overlay ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 33, 29, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.overlay.hidden { display: none; }

.overlay-panel {
  background: var(--paper);
  border: 1px solid var(--ink);
  border-radius: 10px;
  padding: 24px;
  max-width: 460px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  overflow-x: hidden;
}

.overlay-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  gap: 16px;
}

.overlay-head h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 22px;
  margin: 0;
}

.overlay-head .play-btn {
  margin-top: 0;
  padding: 8px 18px;
  animation: none;
  opacity: 1;
}

.game-canvas {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  touch-action: none;
}

.score-line {
  text-align: center;
  font-size: 14px;
  color: var(--ink-soft);
  margin: 12px 0 0;
}

.dpad {
  display: none;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 44px);
  gap: 6px;
  justify-content: center;
  margin: 16px auto 0;
}

@media (pointer: coarse) {
  .dpad { display: grid; }
}

.dpad button {
  border: 1.5px solid var(--ink);
  background: var(--paper);
  border-radius: 8px;
  font-size: 14px;
  color: var(--ink);
}

.dpad button:active {
  background: var(--moss);
  color: var(--paper);
  border-color: var(--moss);
}

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

.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  max-width: 320px;
  margin: 0 auto;
}

.memory-card {
  aspect-ratio: 1;
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.memory-card.flipped,
.memory-card.matched {
  background: var(--moss);
  border-color: var(--moss);
}

.memory-card.matched { opacity: 0.55; }
