@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Space+Mono:wght@400;700&display=swap');

:root {
  color-scheme: dark;
  --ink: #100c1c;
  --ink-2: #19132a;
  --paper: #fff4d6;
  --muted: #a49ab7;
  --red: #ff4d5e;
  --red-dark: #9c263f;
  --blue: #43c5ff;
  --blue-dark: #176caa;
  --gold: #ffc84a;
  --green: #68e082;
  --pixel: 'Press Start 2P', 'Courier New', monospace;
  --mono: 'Space Mono', Consolas, monospace;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 15% 0%, rgba(88, 49, 138, .26), transparent 34rem),
    radial-gradient(circle at 90% 100%, rgba(22, 110, 132, .18), transparent 38rem),
    var(--ink);
  color: var(--paper);
  font-family: var(--mono);
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .14;
  background-image: linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: linear-gradient(to bottom, #000, transparent 78%);
}

button, a { font: inherit; }
button { color: inherit; }

.game-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 14px 20px 18px;
  position: relative;
}

.topbar {
  height: 48px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
}

.back-link {
  justify-self: start;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .08em;
  transition: color .15s, transform .15s;
}

.back-link:hover { color: var(--paper); transform: translateX(-2px); }

.mini-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--pixel);
  font-size: 10px;
  letter-spacing: .08em;
}

.mini-mark { display: flex; align-items: center; gap: 1px; }
.mini-mark i { width: 9px; height: 13px; display: block; background: var(--red); border: 2px solid var(--paper); }
.mini-mark i:last-child { background: var(--blue); }

.top-actions { justify-self: end; display: flex; gap: 8px; }

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255,255,255,.13);
  background: rgba(255,255,255,.04);
  border-radius: 5px;
  cursor: pointer;
  font-size: 17px;
  transition: background .15s, border-color .15s, transform .15s;
}

.icon-button:hover { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.3); transform: translateY(-1px); }

.stage-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #1a1530;
  border: 4px solid #342849;
  border-radius: 8px;
  box-shadow: 0 22px 60px rgba(0,0,0,.45), 0 0 0 1px rgba(255,255,255,.07);
  isolation: isolate;
}

.stage-frame::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 8;
  background: repeating-linear-gradient(to bottom, transparent 0, transparent 3px, rgba(16,12,28,.09) 4px);
  mix-blend-mode: multiply;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  image-rendering: pixelated;
  cursor: crosshair;
}

.hud {
  position: absolute;
  z-index: 5;
  left: 20px;
  right: 20px;
  top: 17px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 18px;
  pointer-events: none;
  text-shadow: 2px 2px 0 rgba(16,12,28,.8);
}

.hud-left { display: flex; flex-direction: column; gap: 6px; }
.eyebrow { color: var(--gold); font-size: clamp(7px, .7vw, 10px); font-family: var(--pixel); }
.hud-left strong { font-family: var(--pixel); font-size: clamp(8px, .85vw, 12px); }
.objective { padding: 8px 13px; border: 1px solid rgba(255,255,255,.15); background: rgba(16,12,28,.66); font-size: clamp(9px, .9vw, 13px); border-radius: 4px; backdrop-filter: blur(6px); }
.hud-right { justify-self: end; display: flex; align-items: center; gap: 13px; }

.key-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  color: var(--gold);
  background: rgba(16,12,28,.66);
  border: 1px solid rgba(255,200,74,.35);
  border-radius: 4px;
  font-family: var(--pixel);
  font-size: clamp(7px, .66vw, 9px);
}

.key-chip.has-key { color: var(--green); border-color: rgba(104,224,130,.5); }
.key-icon { transform: rotate(45deg); display: inline-block; }

.coin-chip {
  padding: 7px 9px;
  color: var(--gold);
  background: rgba(16,12,28,.66);
  border: 1px solid rgba(255,200,74,.28);
  border-radius: 4px;
  font-family: var(--pixel);
  font-size: clamp(7px, .66vw, 9px);
}

.tension { display: grid; grid-template-columns: auto 62px; gap: 7px; align-items: center; font-family: var(--pixel); font-size: 7px; color: var(--muted); }
.tension-track { height: 8px; border: 2px solid rgba(255,255,255,.3); background: var(--ink); padding: 1px; }
.tension-track i { display: block; height: 100%; width: 15%; background: var(--green); transition: width .08s, background .1s; }

.overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(11,8,22,.8);
  backdrop-filter: blur(8px);
  transition: opacity .22s, visibility .22s;
}

.overlay.hidden, .room-card.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.start-screen {
  background:
    linear-gradient(90deg, rgba(255,77,94,.06), transparent 28%, transparent 72%, rgba(67,197,255,.06)),
    rgba(11,8,22,.86);
}

.start-panel { width: min(770px, 92%); text-align: center; padding: 18px 12px 15px; }

.rope-logo { display: flex; align-items: center; justify-content: center; margin: 0 auto 8px; }
.rope-logo b { display: block; width: 72px; height: 20px; border-bottom: 4px dashed #d6ae78; transform: translateY(-5px); }
.pixel-bro { position: relative; display: block; width: 28px; height: 34px; background: var(--red); border: 4px solid var(--paper); box-shadow: 4px 4px 0 var(--red-dark); }
.pixel-bro.blue { background: var(--blue); box-shadow: 4px 4px 0 var(--blue-dark); }
.pixel-bro i { position: absolute; width: 4px; height: 4px; background: var(--ink); right: 4px; top: 7px; box-shadow: -8px 0 0 var(--ink); }

.kicker { margin: 8px 0; color: var(--gold); font-family: var(--pixel); font-size: clamp(8px, .75vw, 11px); letter-spacing: .07em; }

h1, h2 { margin: 0; font-family: var(--pixel); line-height: .92; letter-spacing: -.04em; }
h1 { font-size: clamp(40px, 6vw, 78px); text-shadow: 5px 5px 0 #5a234c; }
h1 em { color: var(--gold); font-style: normal; }

.pitch { max-width: 650px; margin: 13px auto 15px; color: #d5ccdc; font-size: clamp(11px, 1vw, 14px); line-height: 1.45; }

.control-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 760px; margin: 0 auto; }
.control-card { display: grid; grid-template-columns: 1.05fr repeat(4, auto); align-items: center; gap: 6px; padding: 10px 9px; text-align: left; background: rgba(255,255,255,.045); border: 2px solid rgba(255,255,255,.1); border-left-color: var(--red); }
.control-card.blue-card { border-left-color: var(--blue); }
.player-label { font-family: var(--pixel); font-size: 7px; white-space: nowrap; }
.player-label i, .p1-dot, .p2-dot { display: inline-block; width: 8px; height: 8px; margin-right: 6px; background: var(--red); }
.blue-card .player-label i, .p2-dot { background: var(--blue); }
.keys { display: flex; align-items: center; gap: 3px; }
.keys span { margin-left: 1px; color: var(--muted); font-family: var(--pixel); font-size: 5px; white-space: nowrap; }
kbd { min-width: 23px; height: 23px; display: inline-grid; place-items: center; padding: 0 5px; border: 1px solid rgba(255,255,255,.3); border-bottom-width: 3px; border-radius: 3px; background: #251d36; color: var(--paper); font: 700 10px var(--mono); }

.rules { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px 17px; margin: 12px auto; color: var(--muted); font-size: 9px; }
.rules b { color: var(--gold); font-family: var(--pixel); font-size: 7px; margin-right: 4px; }

.primary-button {
  min-width: 230px;
  padding: 13px 19px 11px;
  cursor: pointer;
  border: 3px solid var(--paper);
  background: var(--red);
  box-shadow: 5px 5px 0 var(--red-dark);
  color: var(--paper);
  font-family: var(--pixel);
  font-size: 10px;
  letter-spacing: .04em;
  transition: transform .12s, box-shadow .12s, background .12s;
}
.primary-button:hover { transform: translate(2px, 2px); box-shadow: 3px 3px 0 var(--red-dark); background: #ff6573; }
.primary-button span { margin-left: 13px; }
.start-actions { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 12px; }
.secondary-button {
  min-width: 190px;
  padding: 12px 16px 10px;
  cursor: pointer;
  border: 2px solid rgba(255,255,255,.42);
  background: rgba(255,255,255,.055);
  color: var(--muted);
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: .04em;
  transition: transform .12s, border-color .12s, background .12s, color .12s;
}
.secondary-button:hover { transform: translateY(-1px); border-color: var(--gold); background: rgba(255,200,74,.1); color: var(--gold); }
.start-panel small { display: block; margin-top: 12px; color: #796e8b; font-size: 9px; }

.compact-overlay { background: rgba(11,8,22,.76); }
.compact-panel { width: min(480px, 88%); padding: 36px 30px; text-align: center; border: 3px solid #4f4263; background: #191329; box-shadow: 10px 10px 0 rgba(0,0,0,.35); }
.compact-panel h2 { margin: 12px 0 18px; color: var(--paper); font-size: clamp(30px, 4vw, 54px); }
.compact-panel p:not(.kicker) { color: var(--muted); font-size: 13px; }
.compact-panel .primary-button { margin-top: 18px; }
.shortcut { display: block; margin-top: 15px; color: #756a87; font-size: 9px; }

.shop-overlay { background: rgba(11,8,22,.84); }
.shop-panel {
  width: min(860px, 92%);
  max-height: 92%;
  overflow: auto;
  padding: 24px;
  text-align: center;
  border: 3px solid #5f4a70;
  background:
    radial-gradient(circle at 15% 0%, rgba(255,200,74,.12), transparent 18rem),
    #191329;
  box-shadow: 10px 10px 0 rgba(0,0,0,.36);
}
.shop-panel h2 {
  margin: 8px 0 12px;
  color: var(--gold);
  font-size: clamp(26px, 3.6vw, 48px);
  text-shadow: 4px 4px 0 var(--red-dark);
}
.shop-copy {
  max-width: 680px;
  margin: 0 auto 12px;
  color: var(--muted);
  font-size: 12px;
}
.shop-status {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px auto 14px;
}
.shop-status span {
  padding: 7px 9px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(16,12,28,.62);
  color: var(--paper);
  font-family: var(--pixel);
  font-size: 7px;
}
.shop-status span:first-child { color: var(--gold); border-color: rgba(255,200,74,.38); }
.shop-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
  margin: 12px auto 18px;
}
.shop-item {
  min-height: 132px;
  display: grid;
  align-content: space-between;
  gap: 8px;
  padding: 12px 10px;
  cursor: pointer;
  text-align: left;
  border: 2px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.045);
  box-shadow: 4px 4px 0 rgba(0,0,0,.28);
  transition: transform .12s, border-color .12s, background .12s;
}
.shop-item:hover:not(:disabled) { transform: translate(1px, 1px); border-color: rgba(255,200,74,.55); background: rgba(255,255,255,.075); }
.shop-item:disabled { cursor: default; opacity: .7; }
.shop-item-title { color: var(--paper); font-family: var(--pixel); font-size: 8px; line-height: 1.45; }
.shop-item-desc { color: var(--muted); font-size: 11px; line-height: 1.2; }
.shop-item-cost {
  justify-self: start;
  padding: 5px 7px;
  background: var(--gold);
  color: var(--ink);
  font: normal 7px var(--pixel);
}
.shop-item.is-equipped { border-color: rgba(104,224,130,.64); background: rgba(104,224,130,.08); }
.shop-item.is-equipped .shop-item-cost { background: var(--green); }
.shop-item.is-maxed .shop-item-cost { background: #827690; color: var(--paper); }
.silk-item { border-left-color: #7ce4ff; }
.bungee-item { border-left-color: #ff6ac1; }
.chain-item { border-left-color: #aeb8c3; }

.room-card {
  position: absolute;
  z-index: 9;
  left: 50%; top: 50%;
  width: min(470px, 80%);
  padding: 21px 24px;
  transform: translate(-50%, -50%) skew(-4deg);
  text-align: center;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 9px 9px 0 var(--red), -9px -9px 0 var(--blue);
  transition: opacity .2s, visibility .2s;
}
.room-card span { display: block; margin-bottom: 8px; color: var(--red-dark); font-family: var(--pixel); font-size: 9px; }
.room-card strong { font-family: var(--pixel); font-size: clamp(14px, 2vw, 26px); }

.toast {
  position: absolute;
  z-index: 7;
  left: 50%; bottom: 55px;
  padding: 9px 14px;
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  border: 2px solid var(--paper);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--pixel);
  font-size: clamp(7px, .75vw, 10px);
  transition: opacity .16s, transform .16s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.flash { position: absolute; z-index: 6; inset: 0; pointer-events: none; opacity: 0; background: var(--red); }
.flash.hit { animation: hitFlash .42s steps(2); }
@keyframes hitFlash { 0% { opacity: .62; } 100% { opacity: 0; } }

.win-knot { color: var(--gold); font: 80px/1 var(--pixel); }
.win-panel h2 { color: var(--gold); text-shadow: 4px 4px 0 var(--red-dark); }
.win-stats { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin: 18px 0 4px; }
.win-stats span { padding: 6px 8px; border: 1px solid #4f4263; color: var(--muted); font-size: 8px; }

.game-footer { min-height: 42px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding-top: 12px; color: var(--muted); font-size: 10px; }
.game-footer > span:last-child { justify-self: end; }
.game-footer kbd { min-width: 19px; height: 18px; font-size: 8px; border-bottom-width: 2px; }
.footer-tip { color: #6d627e; text-align: center; }

@media (max-width: 800px) {
  .game-shell { padding: 8px; }
  .topbar { height: 42px; }
  .stage-frame { border-width: 2px; }
  .hud { left: 10px; right: 10px; top: 9px; }
  .objective, .tension { display: none; }
  .hud { grid-template-columns: 1fr 1fr; }
  .hud-right { grid-column: 2; }
  .coin-chip { display: none; }
  .start-panel { transform: scale(.88); width: 105%; }
  .rules { gap: 8px; font-size: 8px; }
  .game-footer { display: none; }
  .control-card { grid-template-columns: 1fr repeat(3,auto); }
  .shop-panel { width: 96%; padding: 16px; }
  .shop-grid { grid-template-columns: 1fr 1fr; }
  .shop-item { min-height: 100px; }
}

@media (max-width: 570px) {
  .control-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
  .control-card { display: flex; flex-direction: column; align-items: flex-start; padding: 7px; gap: 5px; }
  .rules { display: none; }
  .pitch { margin: 8px auto; }
  .start-panel small { display: none; }
  .mini-brand { font-size: 8px; }
  .start-panel { transform: scale(.8); width: 120%; }
}

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