:root {
  color-scheme: dark;
  --ink: #f7faf7;
  --muted: rgba(247, 250, 247, 0.7);
  --soft: rgba(247, 250, 247, 0.1);
  --panel: rgba(13, 17, 15, 0.78);
  --panel-strong: rgba(9, 12, 11, 0.92);
  --line: rgba(255, 255, 255, 0.16);
  --line-strong: rgba(255, 255, 255, 0.26);
  --accent: #17d6b0;
  --accent-2: #ffcf4c;
  --danger: #ff5a67;
  --field: rgba(255, 255, 255, 0.09);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #101312;
}

button,
canvas {
  touch-action: none;
}

input {
  touch-action: manipulation;
}

button,
input {
  border: 0;
  color: inherit;
  font: inherit;
}

button {
  cursor: pointer;
}

.noscript-message {
  position: fixed;
  inset: auto 16px 16px;
  z-index: 20;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  font-weight: 800;
  text-align: center;
}

.game-shell {
  width: 100vw;
  min-height: 100svh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 0%, rgba(23, 214, 176, 0.16), transparent 36%),
    radial-gradient(circle at 0% 100%, rgba(255, 207, 76, 0.12), transparent 34%),
    linear-gradient(135deg, #161915 0%, #101312 48%, #1c1714 100%);
  padding: 18px;
}

.game-stage {
  position: relative;
  width: min(100%, 1140px);
  height: min(calc(100svh - 36px), 780px);
  min-height: 560px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: #101312;
  box-shadow: var(--shadow);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.top-hud {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  z-index: 4;
  width: min(calc(100vw - 28px), 760px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: 1.15fr repeat(3, minmax(0, 1fr));
  gap: 8px;
  pointer-events: none;
}

.hud-block {
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(13, 17, 15, 0.84), rgba(9, 12, 11, 0.68));
  backdrop-filter: blur(14px);
}

.hud-label {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hud-block strong {
  display: block;
  min-width: 0;
  color: var(--ink);
  font-size: 1.35rem;
  line-height: 1.05;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.power-strip {
  position: absolute;
  top: calc(max(14px, env(safe-area-inset-top)) + 76px);
  left: 50%;
  z-index: 4;
  min-height: 34px;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  justify-content: center;
  pointer-events: none;
}

.power-pill {
  min-width: 74px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(8, 13, 12, 0.72);
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 900;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(12px);
}

.screen-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  gap: 18px;
  align-items: center;
  justify-content: center;
  padding: 118px 28px 90px;
  overflow-x: hidden;
  overflow-y: auto;
  background:
    radial-gradient(circle at 50% 18%, rgba(23, 214, 176, 0.16), transparent 32%),
    linear-gradient(180deg, rgba(9, 12, 11, 0.24), rgba(9, 12, 11, 0.84));
}

.screen-layer.active {
  display: grid;
}

.menu-screen,
.result-screen {
  grid-template-columns: minmax(0, 640px) minmax(0, 350px);
}

.start-panel,
.result-panel,
.scoreboard-panel {
  width: 100%;
  max-width: calc(100vw - 24px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(13, 17, 15, 0.86), rgba(8, 11, 10, 0.72));
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(18px);
}

.start-panel,
.result-panel {
  padding: 24px;
}

.scoreboard-panel {
  padding: 16px;
}

.brand-lockup,
.result-panel {
  text-align: left;
}

.tag {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 5px 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--accent-2);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  max-width: 11ch;
  margin-top: 14px;
  color: var(--ink);
  font-size: 5.6rem;
  line-height: 0.88;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow: 0 8px 26px rgba(0, 0, 0, 0.42);
}

h2 {
  color: var(--ink);
  font-size: 5.2rem;
  line-height: 0.92;
  letter-spacing: 0;
}

p {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 800;
}

.player-form {
  margin-top: 26px;
}

.player-form label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.name-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.name-row input {
  width: 100%;
  min-width: 0;
  min-height: 54px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: var(--field);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 850;
}

.name-row input::placeholder {
  color: rgba(247, 250, 247, 0.44);
}

.name-row input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 214, 176, 0.18);
}

.form-message {
  min-height: 22px;
  margin-top: 9px;
  color: var(--accent-2);
  font-size: 0.85rem;
}

.primary-button,
.secondary-button,
.ghost-button {
  display: inline-flex;
  min-height: 50px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: 8px;
  font-weight: 950;
  text-decoration: none;
}

.primary-button {
  min-width: 126px;
  padding: 0 20px;
  background: linear-gradient(135deg, var(--accent), #47f77b);
  color: #07100d;
  box-shadow: 0 18px 42px rgba(23, 214, 176, 0.28);
}

.secondary-button {
  min-width: 102px;
  padding: 0 18px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
}

.ghost-button {
  width: 100%;
  margin-top: 12px;
  min-height: 42px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
}

.primary-button svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.panel-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-heading strong {
  color: var(--ink);
  font-size: 1rem;
  font-weight: 950;
}

.scoreboard-list {
  display: grid;
  gap: 8px;
  min-height: 230px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.score-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
}

.score-row:first-child {
  border-color: rgba(255, 207, 76, 0.48);
  background: linear-gradient(135deg, rgba(255, 207, 76, 0.18), rgba(23, 214, 176, 0.08));
}

.score-rank {
  color: var(--accent-2);
  font-weight: 950;
}

.score-name {
  min-width: 0;
  color: var(--ink);
  font-weight: 900;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-points {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-weight: 950;
}

.score-coins,
.score-date {
  grid-column: 2 / -1;
  color: rgba(247, 250, 247, 0.58);
  font-size: 0.74rem;
  font-weight: 800;
}

.scoreboard-empty {
  display: grid;
  min-height: 230px;
  place-items: center;
  padding: 18px;
  border: 1px dashed rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: var(--muted);
  font-weight: 850;
  text-align: center;
}

.result-panel p {
  margin-top: 8px;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 22px 0;
}

.result-stats div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
}

.result-stats span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.result-stats strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  font-size: 1.25rem;
  line-height: 1.05;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.touch-controls {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  left: max(14px, env(safe-area-inset-left));
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(4, 52px);
  gap: 9px;
  justify-content: center;
  pointer-events: none;
}

.icon-button {
  width: 52px;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(8, 13, 12, 0.64);
  color: var(--ink);
  pointer-events: auto;
  backdrop-filter: blur(12px);
}

.icon-button svg {
  width: 28px;
  height: 28px;
  stroke: currentColor;
  stroke-width: 2.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.icon-button:active,
.primary-button:active,
.secondary-button:active,
.ghost-button:active {
  transform: translateY(1px);
}

@media (min-width: 1100px) {
  .touch-controls {
    grid-template-columns: repeat(4, 48px);
  }

  .icon-button {
    width: 48px;
  }
}

@media (max-width: 920px) {
  .game-shell {
    padding: 0;
  }

  .game-stage {
    width: 100vw;
    height: 100svh;
    min-height: 100svh;
    border: 0;
    border-radius: 0;
  }

  .top-hud {
    width: min(calc(100vw - 20px), 760px);
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .hud-block.runner {
    display: none;
  }

  .hud-block {
    padding: 8px 10px;
  }

  .hud-block strong {
    font-size: 1.1rem;
  }

  .screen-layer {
    align-items: start;
    padding: 94px 12px 94px;
  }

  .menu-screen,
  .result-screen {
    grid-template-columns: minmax(0, 1fr);
  }

  .start-panel,
  .result-panel,
  .scoreboard-panel {
    padding: 14px;
  }

  h1 {
    font-size: 4.2rem;
  }

  h2 {
    font-size: 4.1rem;
  }

  .name-row {
    grid-template-columns: 1fr;
  }

  .primary-button {
    width: 100%;
  }

  .button-row .primary-button,
  .button-row .secondary-button {
    flex: 1 1 120px;
  }

  .scoreboard-list,
  .scoreboard-empty {
    min-height: 190px;
  }

  .touch-controls {
    grid-template-columns: repeat(4, 56px);
  }

  .icon-button {
    width: 56px;
  }
}

@media (max-width: 460px) {
  .top-hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hud-block.compact {
    display: none;
  }

  .screen-layer {
    padding-top: 88px;
  }

  h1 {
    font-size: 3.35rem;
  }

  h2 {
    font-size: 3.45rem;
  }

  .result-stats {
    grid-template-columns: 1fr;
  }

  .touch-controls {
    grid-template-columns: repeat(4, 54px);
    gap: 7px;
  }

  .icon-button {
    width: 54px;
  }
}

@media (max-height: 660px) and (min-width: 921px) {
  .screen-layer {
    padding-top: 94px;
    padding-bottom: 76px;
  }

  h1 {
    font-size: 4.5rem;
  }

  h2 {
    font-size: 4.4rem;
  }
}

@media (hover: hover) and (pointer: fine) {
  .touch-controls {
    opacity: 0.72;
  }

  .icon-button:hover,
  .primary-button:hover,
  .secondary-button:hover,
  .ghost-button:hover {
    filter: brightness(1.08);
  }
}
