@import url('https://fonts.googleapis.com/css2?family=Chakra+Petch:wght@500;600;700&family=Inter:wght@400;600;700;800&display=swap');

:root {
  color-scheme: dark;
  --ink: #f8f5e9;
  --muted: #a9b3cc;
  --night: #050a1d;
  --panel: rgba(7, 13, 36, 0.88);
  --gold: #ffc857;
  --orange: #ff7b46;
  --cyan: #6ee7f2;
  --line: rgba(179, 200, 255, 0.2);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -20%, #263b75 0, transparent 42rem),
    linear-gradient(180deg, #07102b, var(--night));
  font-family: Inter, system-ui, sans-serif;
  overscroll-behavior: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .26;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.14'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

button, canvas { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

.game-shell {
  width: min(1480px, 100%);
  min-height: 100vh;
  margin: auto;
  padding: 18px clamp(12px, 2.5vw, 40px) 22px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  align-items: center;
}

.topbar, .game-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  text-decoration: none;
  font-family: "Chakra Petch", sans-serif;
  letter-spacing: .08em;
  line-height: .86;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: #09102b;
  background: var(--gold);
  border: 2px solid #fff3c1;
  box-shadow: 4px 4px 0 #e05c3f;
  font-size: 22px;
  font-weight: 800;
  transform: skew(-5deg);
}

.brand span:last-child { display: grid; gap: 5px; }
.brand strong { font-size: 16px; }
.brand em { color: var(--orange); font-size: 11px; font-style: normal; }

.topbar-actions { display: flex; gap: 9px; }
.controller-status {
  min-height: 44px;
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: #687491;
  background: rgba(7, 14, 39, .55);
  font: 700 9px/1 "Chakra Petch", sans-serif;
  letter-spacing: .1em;
}
.controller-status.connected { color: var(--cyan); border-color: rgba(110, 231, 242, .5); }
.controller-status.connected span { color: var(--gold); }
.icon-button, .text-button {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  background: rgba(7, 14, 39, .72);
  cursor: pointer;
}
.text-button { padding: 0 15px; font: 700 11px/1 "Chakra Petch", sans-serif; letter-spacing: .12em; }
.icon-button:hover, .text-button:hover { border-color: var(--gold); color: var(--gold); }

.game-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid rgba(165, 193, 255, .35);
  border-radius: 6px;
  background: #081332;
  box-shadow: 0 30px 100px rgba(0, 0, 0, .48), 0 0 0 6px rgba(28, 39, 78, .45);
}

.game-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 70px rgba(1, 4, 17, .48);
}

canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }

.screen-overlay {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(18px, 5vw, 72px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .28s ease, visibility .28s;
  background: linear-gradient(90deg, rgba(3, 8, 27, .92), rgba(5, 10, 30, .45) 58%, rgba(3, 8, 27, .12));
}
.screen-overlay.active { opacity: 1; visibility: visible; }

.title-card { width: min(580px, 100%); justify-self: start; }
.eyebrow {
  margin: 0 0 14px;
  color: var(--cyan);
  font: 700 clamp(10px, 1.2vw, 13px)/1.2 "Chakra Petch", sans-serif;
  letter-spacing: .22em;
}

h1, h2 { font-family: "Chakra Petch", sans-serif; text-transform: uppercase; }
h1 {
  margin: 0;
  max-width: 600px;
  font-size: clamp(54px, 8vw, 108px);
  line-height: .74;
  letter-spacing: -.055em;
  text-shadow: 5px 6px 0 rgba(26, 30, 67, .75);
}
h1 span { display: block; color: var(--gold); font-size: .48em; letter-spacing: .08em; }

.lede { max-width: 520px; margin: 27px 0; color: #d3d9e9; font-size: clamp(13px, 1.4vw, 17px); line-height: 1.65; }

.primary-button {
  min-height: 52px;
  padding: 0 23px;
  border: 1px solid #ffe6a0;
  border-radius: 3px;
  color: #161228;
  background: linear-gradient(135deg, #ffe074, #ff9d55);
  box-shadow: 5px 6px 0 rgba(118, 42, 51, .75);
  cursor: pointer;
  font: 800 13px/1 "Chakra Petch", sans-serif;
  letter-spacing: .1em;
  transition: transform .14s ease, box-shadow .14s ease;
}
.primary-button:hover { transform: translate(2px, 2px); box-shadow: 3px 4px 0 rgba(118, 42, 51, .75); }
.primary-button:focus-visible, button:focus-visible, canvas:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }
.completed-act-select { margin-top: 14px; display: grid; gap: 8px; }
.completed-act-select[hidden] { display: none; }
.completed-act-select > span { color: var(--muted); font: 700 9px/1 "Chakra Petch", sans-serif; letter-spacing: .14em; }
.completed-act-select > div { display: flex; flex-wrap: wrap; gap: 7px; }
.completed-act-select button {
  min-height: 40px; padding: 0 14px; border: 1px solid #52617f; background: rgba(8,15,39,.82); color: #cbd5ec;
  font: 800 10px/1 "Chakra Petch", sans-serif; letter-spacing: .09em; cursor: pointer;
}
.completed-act-select button.selected-act { border-color: var(--gold); color: var(--gold); box-shadow: inset 0 -3px 0 rgba(255,200,87,.22); }
.secondary-button {
  min-height: 48px;
  padding: 0 20px;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--ink);
  background: rgba(8, 15, 40, .82);
  cursor: pointer;
  font: 700 11px/1 "Chakra Petch", sans-serif;
  letter-spacing: .1em;
}
.secondary-button:hover { color: var(--gold); border-color: var(--gold); }

.controls-card {
  width: min(470px, 100%);
  margin-top: 36px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: clamp(16px, 4vw, 40px);
}
.controls-card > div { display: grid; gap: 8px; color: var(--muted); font: 700 9px/1 "Chakra Petch", sans-serif; letter-spacing: .15em; }
.keys { display: flex; gap: 3px; }
kbd {
  min-width: 27px;
  height: 25px;
  padding: 0 7px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.36);
  border-radius: 3px;
  color: white;
  background: rgba(9, 17, 47, .82);
  box-shadow: 0 2px 0 rgba(255,255,255,.12);
  font: 700 9px/1 Inter, sans-serif;
}

.character-screen {
  background: radial-gradient(circle at 50% 45%, rgba(44, 48, 101, .78), rgba(3, 7, 23, .95));
  backdrop-filter: blur(7px);
}
.character-panel { width: min(900px, 100%); text-align: center; }
.character-panel h2 { margin: 0 0 24px; font-size: clamp(28px, 4vw, 52px); line-height: .9; }
.hero-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.hero-card {
  min-height: 270px;
  padding: 24px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink);
  background: linear-gradient(160deg, rgba(20, 28, 67, .94), rgba(7, 13, 36, .9));
  cursor: pointer;
  transition: border-color .18s, transform .18s, background .18s;
}
.hero-card:hover { transform: translateY(-3px); border-color: rgba(255, 200, 87, .65); }
.hero-card.selected { border-color: var(--gold); background: linear-gradient(160deg, rgba(66, 55, 91, .96), rgba(18, 22, 55, .94)); box-shadow: inset 0 0 0 2px rgba(255, 200, 87, .18), 0 12px 35px rgba(0,0,0,.25); }
.hero-name { margin-top: 4px; font: 700 25px/1 "Chakra Petch", sans-serif; letter-spacing: .08em; }
.hero-title { color: var(--gold); font: 700 9px/1 "Chakra Petch", sans-serif; letter-spacing: .18em; }
.hero-description { max-width: 300px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.pixel-hero { position: relative; width: 76px; height: 86px; display: block; filter: drop-shadow(7px 8px 0 rgba(0,0,0,.24)); }
.pixel-hero::before { content: ""; position: absolute; z-index: 2; left: 23px; top: 8px; width: 31px; height: 29px; background: #f2b37c; box-shadow: -5px 5px 0 #442c45, 0 -7px 0 #442c45, 7px -4px 0 #442c45; }
.pixel-hero::after { content: ""; position: absolute; left: 18px; top: 37px; width: 42px; height: 37px; background: #32438b; box-shadow: -7px 31px 0 -1px #11162d, 15px 31px 0 -1px #11162d, -8px 5px 0 -2px #ff6b4a; }
.pixel-hero i { position: absolute; z-index: 3; right: 2px; top: 46px; width: 34px; height: 6px; background: #d8f2ff; box-shadow: -5px -4px 0 #ffc857; transform: rotate(-18deg); }
.maya-preview::before { background: #c98262; box-shadow: -7px 5px 0 #241d3f, 0 -7px 0 #241d3f, 8px -3px 0 #241d3f, -8px 17px 0 #241d3f; }
.maya-preview::after { background: #7b3f89; box-shadow: -7px 31px 0 -1px #12132d, 15px 31px 0 -1px #12132d, -8px 5px 0 -2px #62e1d5; }
.character-actions { margin-top: 20px; display: flex; justify-content: center; gap: 12px; }
.selection-hint { margin: 15px 0 0; color: #6f7b99; font: 700 9px/1 "Chakra Petch", sans-serif; letter-spacing: .1em; }

#messageScreen { background: rgba(3, 7, 23, .74); backdrop-filter: blur(5px); }
.level-transition {
  position: absolute;
  z-index: 6;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  text-align: center;
  background:
    radial-gradient(circle at 50% 62%, rgba(255, 183, 105, .3), transparent 25%),
    linear-gradient(145deg, #080b25 5%, #241943 52%, #6e365a 100%);
}
.level-transition::before,
.level-transition::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0 8%, rgba(255,255,255,.025) 8% 8.2%);
  transform: translateX(-100%);
}
.level-transition::after {
  background: linear-gradient(90deg, transparent, rgba(255, 210, 132, .17), transparent);
  transform: translateX(-130%);
}
.level-transition.active {
  visibility: visible;
  animation: transition-curtain 2.55s ease-in-out both;
}
.level-transition.active::before { animation: transition-lines 2.3s ease-out both; }
.level-transition.active::after { animation: transition-glint 1.5s .35s ease-in-out both; }
.transition-sun {
  position: absolute;
  left: 50%;
  top: 63%;
  width: clamp(110px, 16vw, 220px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: #ffd68b;
  box-shadow: 0 0 80px rgba(255, 174, 103, .6);
  transform: translate(-50%, 80%) scale(.55);
}
.active .transition-sun { animation: transition-sunrise 2.3s cubic-bezier(.22,.7,.2,1) both; }
.transition-copy { position: relative; z-index: 2; display: grid; justify-items: center; }
.transition-copy p {
  margin: 0 0 12px;
  color: #ffc975;
  font: 700 clamp(10px, 1.2vw, 13px)/1 "Chakra Petch", sans-serif;
  letter-spacing: .26em;
}
.transition-copy h2 {
  margin: 0;
  font-size: clamp(70px, 12vw, 155px);
  line-height: .72;
  letter-spacing: -.06em;
  text-shadow: 6px 7px 0 rgba(10, 8, 30, .3);
}
.transition-copy strong {
  margin-top: 23px;
  color: #ffd991;
  font: 700 clamp(19px, 3vw, 35px)/1 "Chakra Petch", sans-serif;
  letter-spacing: .12em;
}
.transition-copy span {
  margin-top: 16px;
  color: #c4c8dd;
  font-size: clamp(10px, 1.2vw, 14px);
}
.active .transition-copy { animation: transition-copy 2.3s ease-in-out both; }

@keyframes transition-curtain {
  0% { opacity: 0; }
  14%, 80% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes transition-lines { from { transform: translateX(-30%); } to { transform: translateX(30%); } }
@keyframes transition-glint { 0% { transform: translateX(-130%); } 100% { transform: translateX(130%); } }
@keyframes transition-sunrise {
  0% { transform: translate(-50%, 90%) scale(.55); opacity: 0; }
  35%, 75% { opacity: 1; }
  100% { transform: translate(-50%, -35%) scale(1); opacity: 0; }
}
@keyframes transition-copy {
  0%, 12% { opacity: 0; transform: translateY(20px); }
  28%, 72% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-14px); }
}
.message-card {
  width: min(480px, 100%);
  padding: clamp(28px, 5vw, 54px);
  text-align: center;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 10px 12px 0 rgba(2, 5, 18, .48);
}
.message-card h2 { margin: 0 0 16px; font-size: clamp(30px, 4vw, 52px); line-height: .95; }
.message-card p:not(.eyebrow) { color: var(--muted); line-height: 1.6; }
.message-card .primary-button { margin-top: 14px; }

.score-screen { padding: clamp(18px, 3vw, 45px); background: rgba(3, 7, 23, .93); backdrop-filter: blur(8px); }
.score-panel { width: min(1050px, 100%); display: grid; grid-template-columns: 1.08fr .92fr; border: 1px solid var(--line); background: rgba(7, 13, 36, .95); box-shadow: 12px 14px 0 rgba(2,5,18,.4); }
.score-summary, .leaderboard-panel { padding: clamp(22px, 3vw, 42px); }
.score-summary { border-right: 1px solid var(--line); }
.score-summary h2 { margin: 0; font-size: clamp(35px, 5vw, 65px); line-height: .85; }
#scoreHeroLine { margin: 13px 0 20px; color: var(--cyan); font: 700 10px/1 "Chakra Petch", sans-serif; letter-spacing: .16em; }
.final-score { padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; border: 1px solid rgba(255,200,87,.35); background: rgba(255,200,87,.08); }
.final-score span { color: var(--gold); font: 700 10px/1 "Chakra Petch", sans-serif; letter-spacing: .16em; }
.final-score strong { color: #fff1ba; font: 700 clamp(27px, 4vw, 43px)/1 "Chakra Petch", sans-serif; letter-spacing: .08em; }
.score-breakdown { margin: 12px 0 18px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.score-breakdown div { padding: 9px 7px; display: grid; gap: 5px; text-align: center; background: rgba(255,255,255,.035); }
.score-breakdown dt { color: #6f7b99; font: 700 8px/1 "Chakra Petch", sans-serif; letter-spacing: .1em; }
.score-breakdown dd { margin: 0; color: #dce4f7; font: 700 13px/1 "Chakra Petch", sans-serif; }
.initials-form { display: grid; grid-template-columns: 1fr auto; gap: 9px; }
.initials-form label { grid-column: 1 / -1; color: var(--muted); font: 700 9px/1 "Chakra Petch", sans-serif; letter-spacing: .13em; }
.controller-entry-hint { grid-column: 1 / -1; margin: 1px 0 0; color: #6f7b99; font: 700 8px/1.4 "Chakra Petch", sans-serif; letter-spacing: .06em; }
.initials-form input {
  min-width: 0;
  height: 52px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--gold);
  background: #080f28;
  text-transform: uppercase;
  font: 700 28px/1 "Chakra Petch", sans-serif;
  letter-spacing: .28em;
}
.initials-form input:focus { outline: 2px solid var(--cyan); border-color: transparent; }
.initials-form.saved { opacity: .55; pointer-events: none; }
#playAgainButton { width: 100%; margin-top: 10px; }
.leaderboard-panel h3 { margin: 0 0 22px; font: 700 34px/1 "Chakra Petch", sans-serif; }
.leaderboard-panel table { width: 100%; border-collapse: collapse; font: 700 11px/1.2 "Chakra Petch", sans-serif; }
.leaderboard-panel th { padding: 0 8px 10px; color: #697694; text-align: left; font-size: 8px; letter-spacing: .11em; }
.leaderboard-panel td { padding: 11px 8px; border-top: 1px solid rgba(255,255,255,.07); color: #cbd3e8; }
.leaderboard-panel td:nth-child(2) { color: var(--gold); letter-spacing: .14em; }
.leaderboard-panel td:last-child, .leaderboard-panel th:last-child { text-align: right; }
#emptyLeaderboard { color: #687491; font-size: 11px; }

.mobile-controls { display: none; }

.game-note {
  color: #7885a4;
  font: 700 9px/1 "Chakra Petch", sans-serif;
  letter-spacing: .18em;
}
.game-note span:last-child { color: #596680; }

@media (max-width: 760px), (pointer: coarse) {
  .game-shell { min-height: 100svh; padding: 8px; grid-template-rows: auto 1fr; }
  .topbar { min-height: 48px; }
  .game-note { display: none; }
  .game-frame { align-self: center; }
  .text-button { display: none; }
  .controller-status { min-width: 44px; width: 44px; padding: 0; justify-content: center; font-size: 0; }
  .controller-status span { font-size: 16px; }
  .brand-mark { width: 32px; height: 32px; font-size: 18px; }
  .screen-overlay { padding: 22px; }
  .lede { margin: 16px 0; line-height: 1.4; }
  .controls-card { display: none; }
  .character-screen, .score-screen { padding: 14px; overflow-y: auto; align-items: start; }
  .character-panel { margin: auto; }
  .hero-card { min-height: 210px; padding: 14px; }
  .pixel-hero { transform: scale(.78); margin: -8px 0; }
  .score-panel { grid-template-columns: 1fr; }
  .score-summary { border-right: 0; border-bottom: 1px solid var(--line); }
  .leaderboard-panel { padding-top: 24px; }
  .mobile-controls { position: absolute; z-index: 2; inset: auto 12px 12px; display: flex; justify-content: space-between; pointer-events: none; }
  .mobile-controls > div { display: flex; gap: 8px; pointer-events: auto; }
  .mobile-controls button {
    width: clamp(48px, 11vw, 68px);
    height: clamp(48px, 11vw, 68px);
    border: 1px solid rgba(255,255,255,.35);
    border-radius: 50%;
    color: white;
    background: rgba(7, 14, 39, .6);
    backdrop-filter: blur(5px);
    touch-action: none;
    font-weight: 800;
  }
  .mobile-controls button:active, .mobile-controls button.pressed { color: var(--gold); background: rgba(35, 35, 67, .84); transform: scale(.95); }
  .mobile-controls button span { display: block; margin-top: 2px; font-size: 7px; letter-spacing: .08em; }
}

@media (max-height: 560px) {
  .game-shell { padding-top: 6px; }
  .topbar { position: absolute; z-index: 5; top: 8px; left: 12px; right: 12px; pointer-events: none; }
  .topbar a, .topbar button { pointer-events: auto; }
  .game-frame { max-height: calc(100svh - 12px); width: auto; max-width: 100%; height: calc(100svh - 12px); }
  .game-note { display: none; }
  h1 { font-size: clamp(48px, 15vh, 82px); }
  .lede { display: none; }
  .controls-card { margin-top: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
