:root {
  --brand: #43b047;
  --brand-2: #2d8031;
  --accent: #fbd000;
  --grad: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
  --bg: #1F2421;
  --surface: #2a2f2c;
  --text: #f7f4ef;
  --pixel-bg: #5c9fd8;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Press Start 2P', 'Courier New', monospace;
  font-size: 10px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

.pixel-clouds {
  position: fixed;
  inset: 0;
  background: 
    radial-gradient(circle at 20% 30%, rgba(92,159,216,0.15) 0%, transparent 40%),
    radial-gradient(circle at 80% 60%, rgba(67,176,71,0.1) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.screen {
  min-height: 100vh;
  display: none;
  flex-direction: column;
  position: relative;
  z-index: 1;
}
.screen.active { display: flex; }

.topbar {
  padding: 1.5rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  backdrop-filter: blur(8px);
  background: rgba(31,36,33,0.85);
  border-bottom: 2px solid var(--brand);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}
.brand.small { font-size: 1rem; }
.brand-mark {
  width: 32px;
  height: 32px;
  background: var(--brand);
  border-radius: 50% 50% 0 0;
  border: 3px solid var(--accent);
  border-bottom: none;
  position: relative;
  display: block;
  flex-shrink: 0;
}
.brand-mark::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
  top: 8px;
  left: 6px;
}
.brand-name { color: var(--accent); }

.tag {
  font-size: 0.7rem;
  padding: 0.4rem 0.8rem;
  background: var(--surface);
  border: 2px solid var(--brand);
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.online-tag { animation: pulse 2s infinite; }
@keyframes pulse {
  0%, 100% { border-color: var(--brand); }
  50% { border-color: var(--accent); }
}

.menu-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4rem;
  padding: 0 2rem 4rem;
}

.menu-hero {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 3rem;
  align-items: center;
  margin-top: 2rem;
}
.menu-hero-copy { display: flex; flex-direction: column; gap: 1.5rem; }
.eyebrow {
  font-size: 0.65rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 0;
}
h1 {
  font-size: clamp(1.5rem, 3vw, 2.2rem);
  line-height: 1.2;
  margin: 0;
  color: var(--text);
  white-space: pre-line;
}
.lead {
  font-size: 0.8rem;
  line-height: 1.7;
  color: rgba(247,244,239,0.8);
  margin: 0;
}

.card, .panel {
  background: var(--surface);
  border: 3px solid rgba(67,176,71,0.4);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.identity { display: flex; flex-direction: column; gap: 1.5rem; }

.field { display: flex; flex-direction: column; gap: 0.5rem; }
.field label {
  font-size: 0.7rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
input[type="text"], .sel {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.9rem 1rem;
  background: var(--bg);
  border: 2px solid rgba(67,176,71,0.5);
  border-radius: 8px;
  color: var(--text);
  outline: none;
  transition: border-color 150ms, box-shadow 150ms;
}
input[type="text"]:focus, .sel:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(67,176,71,0.2);
}
input[type="text"]::placeholder { color: rgba(247,244,239,0.4); }

.swatches {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.swatch {
  width: 40px;
  height: 40px;
  border: 3px solid transparent;
  border-radius: 8px;
  background: var(--sw);
  cursor: pointer;
  transition: transform 100ms, border-color 100ms;
  position: relative;
}
.swatch:hover { transform: scale(1.1); }
.swatch.sel {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--bg), 0 0 12px var(--accent);
}

.btn {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 1rem 1.5rem;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 150ms, box-shadow 150ms, background 150ms;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-weight: 700;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }

.btn-play {
  background: var(--grad);
  color: white;
  box-shadow: 0 4px 16px rgba(67,176,71,0.5);
}
.btn-play:hover { box-shadow: 0 6px 24px rgba(67,176,71,0.7); }

.btn-ghost2 {
  background: transparent;
  border: 2px solid var(--brand);
  color: var(--brand);
}
.btn-ghost2:hover {
  background: rgba(67,176,71,0.15);
  box-shadow: 0 4px 12px rgba(67,176,71,0.3);
}
.btn-ghost2.sm { padding: 0.6rem 1rem; font-size: 0.7rem; }

.btn-ready {
  background: rgba(251,208,0,0.2);
  border: 2px solid var(--accent);
  color: var(--accent);
}
.btn-ready.ready-yes {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}

.btn-send {
  background: var(--brand);
  color: white;
  padding: 0.7rem 1rem;
  box-shadow: 0 2px 8px rgba(67,176,71,0.4);
}

.btn-join {
  background: var(--accent);
  color: var(--bg);
  font-weight: 700;
  padding: 0.7rem 1.2rem;
  font-size: 0.75rem;
  box-shadow: 0 3px 12px rgba(251,208,0,0.5);
}
.btn-join:hover { box-shadow: 0 4px 16px rgba(251,208,0,0.7); }

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.joincode {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}
#join-code {
  flex: 1;
  text-transform: uppercase;
  text-align: center;
  font-weight: 700;
}

.link-btn {
  font-family: inherit;
  font-size: 0.7rem;
  background: none;
  border: none;
  color: var(--brand);
  cursor: pointer;
  text-decoration: underline;
  padding: 0.5rem 0;
  transition: color 150ms;
}
.link-btn:hover { color: var(--accent); }

.menu-hero-visual {
  position: relative;
  height: 360px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.stage {
  position: relative;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, var(--pixel-bg) 0%, var(--pixel-bg) 75%, #97c553 75%, #97c553 100%);
  border: 4px solid var(--brand);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 -4px 8px rgba(0,0,0,0.3);
}

.s-ground {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 25%;
  background: repeating-linear-gradient(90deg, #8b6914 0px, #8b6914 32px, #a57c1a 32px, #a57c1a 64px);
  border-top: 4px solid #6d5410;
}
.s-hill {
  position: absolute;
  bottom: 25%;
  width: 120px;
  height: 60px;
  background: #43b047;
  border-radius: 50% 50% 0 0;
  border: 3px solid #2d8031;
}
.s-hill.h1 { left: 10%; }
.s-hill.h2 { right: 15%; width: 90px; height: 50px; }

.s-coin {
  position: absolute;
  width: 24px;
  height: 24px;
  background: var(--accent);
  border: 3px solid #c99700;
  border-radius: 50%;
  animation: coin-spin 1.5s infinite ease-in-out;
}
.s-coin.c1 { top: 35%; left: 25%; animation-delay: 0s; }
.s-coin.c2 { top: 28%; left: 50%; animation-delay: 0.2s; }
.s-coin.c3 { top: 40%; right: 20%; animation-delay: 0.4s; }
@keyframes coin-spin {
  0%, 100% { transform: scaleX(1) rotate(0deg); }
  50% { transform: scaleX(0.3) rotate(180deg); }
}

.s-block {
  position: absolute;
  width: 40px;
  height: 40px;
  background: #f2a03d;
  border: 3px solid #c97d1f;
  border-radius: 4px;
  top: 40%;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.4);
}
.s-block.b1 { left: 35%; }
.s-block.b2 { right: 30%; }

.s-hero {
  position: absolute;
  bottom: calc(25% + 5px);
  left: 15%;
  width: 36px;
  height: 48px;
  background: #e52521;
  border: 3px solid #a01e1b;
  border-radius: 8px 8px 0 0;
  animation: hero-jump 2s infinite ease-in-out;
}
.s-hero::before {
  content: '';
  position: absolute;
  top: 8px;
  left: 8px;
  width: 12px;
  height: 12px;
  background: white;
  border-radius: 50%;
}
@keyframes hero-jump {
  0%, 100% { transform: translateY(0); }
  40%, 60% { transform: translateY(-60px); }
}

.s-goomba {
  position: absolute;
  bottom: calc(25% + 5px);
  left: 45%;
  width: 32px;
  height: 28px;
  background: #8b4513;
  border: 3px solid #5a2d0f;
  border-radius: 50% 50% 0 0;
  animation: goomba-walk 3s infinite linear;
}
@keyframes goomba-walk {
  0%, 100% { left: 45%; }
  50% { left: 55%; }
}

.s-flag {
  position: absolute;
  bottom: 25%;
  right: 8%;
  width: 4px;
  height: 120px;
  background: #555;
  border-radius: 2px;
}
.s-flag::before {
  content: '';
  position: absolute;
  top: 0;
  left: 4px;
  width: 36px;
  height: 24px;
  background: var(--accent);
  border: 2px solid #c99700;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.modes {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.modes h2 {
  font-size: 1.3rem;
  text-align: center;
  color: var(--accent);
  margin: 0;
}
.modes-grid {
  --grid-min: 280px;
  gap: 1.5rem;
}
.mode-card {
  background: var(--surface);
  border: 3px solid rgba(67,176,71,0.4);
  border-radius: 16px;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  transition: transform 150ms, box-shadow 150ms, border-color 150ms;
}
.mode-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
  border-color: var(--brand);
}
.mode-ico {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  display: block;
}
.mode-gonka .mode-ico { background: linear-gradient(135deg, #e52521, #f39c12); }
.mode-koop .mode-ico { background: linear-gradient(135deg, #43b047, #27ae60); }
.mode-monety .mode-ico { background: linear-gradient(135deg, #fbd000, #f39c12); }
.mode-card h3 {
  font-size: 1rem;
  margin: 0;
  color: var(--accent);
}
.mode-card p {
  font-size: 0.75rem;
  line-height: 1.6;
  margin: 0;
  color: rgba(247,244,239,0.8);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.panel h2, .panel h3 {
  font-size: 1.2rem;
  margin: 0;
  color: var(--accent);
}
.panel.wide {
  max-width: 900px;
  margin: 2rem auto;
}

.cluster {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.controls-grid {
  display: grid;
  gap: 1rem;
  margin-top: 1.5rem;
}
.ctl {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.8rem;
}
.keys {
  display: flex;
  gap: 0.4rem;
}
kbd {
  font-family: inherit;
  font-size: 0.75rem;
  padding: 0.4rem 0.7rem;
  background: var(--bg);
  border: 2px solid var(--brand);
  border-radius: 6px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.tips {
  margin-top: 1.5rem;
}
.tips h3 {
  font-size: 1rem;
  margin: 0 0 1rem;
  color: var(--accent);
}
.tick-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.tick-list li {
  font-size: 0.75rem;
  line-height: 1.6;
  padding-left: 1.5rem;
  position: relative;
  color: rgba(247,244,239,0.9);
}
.tick-list li::before {
  content: '✓';
  position: absolute;
  left: 0;
  color: var(--brand);
  font-weight: 700;
}

.rooms-list {
  display: grid;
  gap: 1rem;
}
.room-item {
  background: var(--bg);
  border: 2px solid rgba(67,176,71,0.3);
  border-radius: 12px;
  padding: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  transition: border-color 150ms, transform 100ms;
  cursor: pointer;
}
.room-item:hover {
  border-color: var(--brand);
  transform: translateX(4px);
}
.room-main {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex: 1;
}
.room-name {
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 700;
}
.room-meta {
  font-size: 0.65rem;
  color: rgba(247,244,239,0.6);
  display: flex;
  gap: 1rem;
}
.room-badge {
  font-size: 0.65rem;
  padding: 0.3rem 0.6rem;
  background: rgba(67,176,71,0.2);
  border: 1px solid var(--brand);
  border-radius: 6px;
  text-transform: uppercase;
  color: var(--brand);
}

.room-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 2rem;
  padding: 2rem;
  align-items: start;
}
.room-code {
  font-size: 0.7rem;
  color: rgba(247,244,239,0.7);
  margin-top: 0.3rem;
}

.players-lobby {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  margin: 1.5rem 0;
}
.player-card {
  background: var(--bg);
  border: 2px solid rgba(67,176,71,0.3);
  border-radius: 10px;
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.player-card.ready { border-color: var(--brand); box-shadow: 0 0 8px rgba(67,176,71,0.4); }
.player-avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  flex-shrink: 0;
}
.player-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.player-nick {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
}
.player-status {
  font-size: 0.65rem;
  color: rgba(247,244,239,0.6);
}
.player-crown {
  font-size: 1.2rem;
}

.room-controls {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  margin-top: 1.5rem;
}
.hint {
  font-size: 0.7rem;
  color: rgba(247,244,239,0.6);
  text-align: center;
}

.chatbox {
  display: flex;
  flex-direction: column;
  max-height: 600px;
}
.chatbox h3 {
  font-size: 0.9rem;
  margin: 0 0 1rem;
  color: var(--accent);
}
.chat-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.5rem;
  margin-bottom: 1rem;
  min-height: 200px;
  background: var(--bg);
  border-radius: 8px;
}
.chat-msg {
  font-size: 0.7rem;
  line-height: 1.5;
  word-wrap: break-word;
}
.chat-nick {
  font-weight: 700;
  margin-right: 0.4rem;
}
.chat-form {
  display: flex;
  gap: 0.6rem;
}
.chat-form input {
  flex: 1;
  font-size: 0.75rem;
  padding: 0.7rem;
}

.game-screen {
  background: black;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 10;
  gap: 2rem;
}
.hud-left, .hud-right {
  display: flex;
  gap: 1.5rem;
  align-items: center;
}
.hud-item {
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: white;
}
.hud-item b { color: var(--accent); }
.lives::before {
  content: '❤';
  font-size: 1rem;
  color: #e52521;
}
.hud-standings {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.65rem;
}
.hud-player {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: rgba(255,255,255,0.8);
}
.hud-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.hud-player.finish { color: var(--accent); }

.canvas-holder {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100vh;
}
#gamecanvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.touch-controls {
  position: absolute;
  bottom: 2rem;
  left: 0;
  right: 0;
  display: none;
  justify-content: space-between;
  padding: 0 2rem;
  pointer-events: none;
  z-index: 20;
}
.tc-move, .tc-jump {
  pointer-events: auto;
}
.tc-move {
  display: flex;
  gap: 0.8rem;
}
.tc-btn {
  font-family: inherit;
  font-size: 1.5rem;
  width: 60px;
  height: 60px;
  background: rgba(67,176,71,0.7);
  border: 3px solid var(--brand);
  border-radius: 12px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.6);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.tc-btn:active {
  background: rgba(67,176,71,0.9);
  transform: scale(0.95);
}
@media (max-width: 768px) {
  .touch-controls { display: flex; }
}

.results-podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 1rem;
  margin: 2rem 0;
}
.podium-place {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}
.podium-avatar {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  border: 3px solid;
}
.podium-place:nth-child(1) .podium-avatar { border-color: #ffd700; }
.podium-place:nth-child(2) .podium-avatar { border-color: #c0c0c0; }
.podium-place:nth-child(3) .podium-avatar { border-color: #cd7f32; }
.podium-nick {
  font-size: 0.75rem;
  color: var(--text);
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.podium-medal {
  font-size: 1.5rem;
}
.podium-base {
  width: 60px;
  background: var(--surface);
  border: 2px solid var(--brand);
  border-radius: 8px 8px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
}
.podium-place:nth-child(1) .podium-base { height: 80px; }
.podium-place:nth-child(2) .podium-base { height: 60px; }
.podium-place:nth-child(3) .podium-base { height: 50px; }

.results-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.75rem;
}
.results-table th {
  text-align: left;
  padding: 0.8rem;
  background: var(--bg);
  color: var(--accent);
  border-bottom: 2px solid var(--brand);
  font-size: 0.7rem;
  text-transform: uppercase;
}
.results-table td {
  padding: 0.8rem;
  border-bottom: 1px solid rgba(67,176,71,0.2);
  color: var(--text);
}
.results-table tr:hover {
  background: rgba(67,176,71,0.1);
}
.res-avatar {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: inline-block;
  vertical-align: middle;
  margin-right: 0.6rem;
}

.site-footer {
  background: var(--surface);
  border-top: 3px solid var(--brand);
  padding: 3rem 2rem 1.5rem;
  margin-top: auto;
}
.footer-inner {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 2rem;
  max-width: 1000px;
  margin: 0 auto 2rem;
}
.footer-col h4 {
  font-size: 0.8rem;
  color: var(--accent);
  margin: 0 0 0.8rem;
}
.footer-col p {
  font-size: 0.7rem;
  line-height: 1.6;
  margin: 0;
}
.footer-bottom {
  text-align: center;
  font-size: 0.65rem;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(67,176,71,0.3);
}

@media (max-width: 768px) {
  body { font-size: 9px; }
  .topbar { padding: 1rem 1.5rem; }
  .menu-wrap { padding: 0 1.5rem 3rem; }
  .menu-hero {
    grid-template-columns: 1fr;
    gap: 2rem;
  }
  .menu-hero-visual { height: 280px; }
  .modes-grid { --grid-min: 100%; }
  .room-layout {
    grid-template-columns: 1fr;
    padding: 1.5rem;
  }
  .hud {
    padding: 0.8rem 1rem;
    gap: 1rem;
    flex-direction: column;
    align-items: flex-start;
  }
  .hud-left, .hud-right {
    gap: 1rem;
    flex-wrap: wrap;
  }
}