* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Trebuchet MS", sans-serif;
  background: linear-gradient(180deg, #0f172a, #111827);
  color: #e5e7eb;
  min-height: 100vh;
  overflow: hidden;
  height: var(--vh, 100dvh);
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px;
  display: grid;
  gap: 12px;
  min-height: var(--vh, 100dvh);
  height: var(--vh, 100dvh);
  grid-template-rows: auto 1fr;
}

.arena {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 16px;
  align-items: stretch;
  height: 100%;
  min-height: 0;
}

.panel-left,
.panel-right {
  display: grid;
  height: 100%;
  min-height: 0;
}

.panel-left {
  grid-template-rows: 1fr auto;
  gap: 12px;
}

.header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 16px 18px;
  transition: all 220ms ease;
}

.header h1 {
  margin: 0 0 6px;
  font-weight: 700;
  transition: all 220ms ease;
}

.header p {
  margin: 0;
  color: #94a3b8;
}

.howto {
  margin-top: 8px;
  font-size: 12px;
  color: #cbd5f5;
}

.app.is-running .header {
  padding: 2px 10px;
  border-radius: 10px;
}

.app.is-running .header p,
.app.is-running .header .howto,
.app.is-running .settings {
  display: none;
}

.app.is-running .header h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1.1;
}

.app.is-running {
  --header-size: 44px;
  --app-padding: 24px;
}

.header-score {
  display: none;
  align-items: baseline;
  gap: 8px;
  color: #cbd5f5;
}

.header-score strong {
  color: #e5e7eb;
  font-size: 16px;
}

.app.is-running .header-score {
  display: inline-flex;
}


.settings {
  display: grid;
  gap: 10px;
}

.settings label {
  font-size: 12px;
  display: grid;
  gap: 6px;
}

.settings input {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #0b1220;
  color: #e5e7eb;
}

.settings button {
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: #22c55e;
  color: #0b1220;
  font-weight: 700;
  cursor: pointer;
}

.game-wrap {
  position: relative;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 12px;
  display: grid;
  grid-template-rows: 1fr;
  gap: 0;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

canvas#game {
  background: #0b1220;
  border: 2px solid #334155;
  border-radius: 12px;
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  image-rendering: pixelated;
  touch-action: none;
  justify-self: center;
}

.game-overlay {
  position: absolute;
  inset: 12px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.82);
  color: #e5e7eb;
  display: none;
  align-content: start;
  justify-items: center;
  text-align: center;
  gap: 14px;
  font-size: 14px;
  padding-top: 45%;
}

.game-overlay strong {
  font-size: 18px;
  letter-spacing: 0.5px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.restart-btn {
  border: 1px solid #0ea5e9;
  background: linear-gradient(180deg, #38bdf8, #0ea5e9);
  color: #0b1220;
  font-weight: 700;
  border-radius: 999px;
  padding: 10px 18px;
  cursor: pointer;
}

 

.panel-right {
  gap: 16px;
  align-content: start;
  height: 100%;
  overflow: hidden;
  min-height: 0;
}

.panel-left {
  gap: 12px;
}


.controls {
  display: grid;
  grid-template-columns: auto auto;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  touch-action: manipulation;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 70px);
  grid-template-rows: repeat(3, 70px);
  gap: 6px;
  justify-content: center;
}

.dpad-btn {
  border-radius: 16px;
  border: 1px solid #334155;
  background: linear-gradient(180deg, #111827, #0b1220);
  color: #e5e7eb;
  font-size: 22px;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px #0f172a;
  touch-action: manipulation;
}

.dpad-btn:active {
  transform: translateY(1px);
}

.dpad-btn.up {
  grid-column: 2;
  grid-row: 1;
}

.dpad-btn.left {
  grid-column: 1;
  grid-row: 2;
}

.dpad-btn.right {
  grid-column: 3;
  grid-row: 2;
}

.dpad-btn.down {
  grid-column: 2;
  grid-row: 3;
}

.actions {
  display: flex;
  align-items: center;
  gap: 12px;
  align-self: center;
}

.action-btn {
  padding: 16px 24px;
  border-radius: 999px;
  border: 1px solid #0ea5e9;
  background: linear-gradient(180deg, #38bdf8, #0ea5e9);
  color: #0b1220;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  touch-action: manipulation;
}

.action-drop {
  padding: 22px 28px;
  font-size: 16px;
}

.kbd-hint {
  display: none;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.kbd {
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 11px;
  color: #cbd5f5;
  background: #0b1220;
}

.kbd-text {
  font-size: 11px;
  color: #94a3b8;
}

.online {
  margin-top: 0;
}

.online-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.leaderboard {
  margin-top: 0;
}

.leaderboard h2 {
  margin: 0 0 10px;
}

.leaderboard-list {
  display: grid;
  gap: 8px;
}

.leader-row {
  display: grid;
  grid-template-columns: 40px 1fr 80px;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid #1f2937;
  background: rgba(15, 23, 42, 0.6);
  border-radius: 8px;
  font-size: 13px;
  align-items: center;
}

.leader-row span:last-child {
  text-align: right;
}

.leader-row span {
  color: #cbd5f5;
}

.leader-row strong {
  color: #e5e7eb;
}

.leader-highlight {
  border-color: #38bdf8;
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.4);
}

.card {
  border: 1px solid #1f2937;
  background: rgba(15, 23, 42, 0.7);
  border-radius: 10px;
  padding: 10px;
  display: grid;
  gap: 8px;
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.6);
}

.card canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 2;
  border: 1px solid #334155;
  border-radius: 8px;
  background: #0a1222;
}

.card .meta {
  font-size: 12px;
  display: grid;
  gap: 6px;
  color: #cbd5f5;
}

.card .meta-row {
  display: flex;
  justify-content: space-between;
}

.card .meta-row strong {
  color: #e5e7eb;
}

@media (min-width: 801px) {
  .arena {
    grid-template-columns: 2fr 1fr;
  }

  .game-wrap {
    max-height: none;
  }

.app.no-online .panel-right .leaderboard {
  display: block;
}

.app.no-online .panel-right .online {
  display: none;
}

.app:not(.is-running) .panel-right .online {
  display: none;
}

.app:not(.is-running) .panel-right .leaderboard {
  display: block;
}

.app.is-running:not(.no-online) .panel-right .leaderboard {
  display: none;
}

  .app.game-over .panel-right .online {
    display: none;
  }

  .app.game-over .panel-right .leaderboard {
    display: block;
  }

  .controls {
    display: none;
  }

  .online-list {
    grid-auto-rows: 1fr;
  }

  .app.online-1 .online-list {
    grid-template-columns: 1fr;
  }

  .app.online-2 .online-list,
  .app.online-3 .online-list,
  .app.online-4plus .online-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .card {
    height: 100%;
  }
}

@media (max-width: 800px) {
  .arena {
    grid-template-columns: 1fr;
  }

  .panel-right {
    display: none !important;
  }

  .app.is-running .panel-right {
    display: none !important;
  }

  .app.game-over .panel-right {
    display: grid;
  }
}

@media (max-height: 760px) {
  .app {
    padding: 10px;
    gap: 12px;
    --app-gap: 12px;
  }

  .arena {
    gap: 12px;
  }

  .controls {
    gap: 8px;
  }

  .dpad {
    grid-template-columns: repeat(3, 46px);
    grid-template-rows: repeat(3, 46px);
  }

  .action-btn {
    width: 72px;
    height: 72px;
    font-size: 12px;
  }

  .header-score strong {
    font-size: 14px;
  }
}

.app.game-over .game-overlay {
  display: grid;
}
