:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  color: #f5f6ef;
  background: #141713;
}

body {
  box-sizing: border-box;
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}

.welcome {
  width: min(100%, 420px);
  padding-block: 14px;
}

h1 {
  margin: 0;
  font-family: "Arial Black", system-ui, sans-serif;
  font-size: clamp(3rem, 19vw, 5.3rem);
  font-weight: 950;
  letter-spacing: -0.075em;
  line-height: 1;
}

p {
  margin: 12px 0 0;
  font-size: clamp(1.05rem, 5.6vw, 1.5rem);
  color: #b3b89b;
  overflow-wrap: anywhere;
}

.action {
  display: grid;
  place-items: center;
  box-sizing: border-box;
  width: 100%;
  min-height: 60px;
  margin-top: 28px;
  border: 0;
  padding: 10px;
  color: #141713;
  background: #ccfa49;
  font: 800 clamp(1.1rem, 6vw, 1.5rem) / 1.15 system-ui, sans-serif;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

[hidden] { display: none !important; }
.action:hover { background: #ddff79; }
.action:focus-visible { outline: 2px solid #f5f6ef; outline-offset: 4px; }

body.playing {
  padding: max(8px, env(safe-area-inset-top), var(--tg-content-safe-area-inset-top, 0px))
    max(8px, env(safe-area-inset-right), var(--tg-content-safe-area-inset-right, 0px))
    max(8px, env(safe-area-inset-bottom), var(--tg-content-safe-area-inset-bottom, 0px))
    max(8px, env(safe-area-inset-left), var(--tg-content-safe-area-inset-left, 0px));
}
.training { width: 100%; --game-chrome: 84px; }
.training:fullscreen { box-sizing: border-box; padding: 12px; overflow: auto; background: #141713; }
html[data-touch-game] .training { --game-chrome: 202px; }
.training > .training-bar { align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; }
#game-players { flex: auto; text-align: center; }
.training-bar { display: flex; justify-content: space-between; margin-bottom: 12px; }
.training button {
  min-height: 48px;
  min-width: 48px;
  padding-inline: 10px;
  border: 1px solid #747966;
  border-radius: 6px;
  background: #262a21;
  color: inherit;
  font: inherit;
}
.training canvas {
  display: block;
  width: min(100%, max(120px, calc((100dvh - var(--game-chrome) - var(--tg-content-safe-area-inset-top, 0px) - var(--tg-content-safe-area-inset-bottom, 0px)) * 256 / 240)));
  margin: auto;
  aspect-ratio: 256 / 240;
  image-rendering: pixelated;
  touch-action: none;
  background: #0e100d;
}
.training p { font-size: 1rem; }
.training p:empty { display: none; }
.touch-controls { display: none; }
html[data-touch-game] .touch-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  touch-action: none;
  user-select: none;
}
.directions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.directions button:first-child { grid-area: 1 / 2; }
.directions button:nth-child(2) { grid-area: 2 / 1; }
.fire { display: flex; gap: 8px; }

.duo-lobby { width: min(100%, 420px); }
.duo-lobby h2 { margin: 0; font-size: clamp(1.8rem, 9vw, 2.5rem); }
.duo-lobby p:empty { display: none; }
.duo-lobby button:not(:first-of-type) { margin-top: 10px; }

.ranking { width: min(100%, 580px); align-self: start; }
.ranking h2 { margin: 0; font-size: clamp(1.5rem, 6vw, 2.1rem); }
.ranking button {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid #747966;
  border-radius: 6px;
  color: inherit;
  background: #262a21;
  font: inherit;
}
.ranking button[aria-pressed="true"] { color: #141713; background: #ccfa49; border-color: #ccfa49; }
.ranking button:disabled { opacity: 0.45; }
.ranking-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-block: 12px; }
.ranking table { width: 100%; border-collapse: collapse; text-align: left; }
.ranking th, .ranking td { padding: 8px; border-bottom: 1px solid #424835; overflow-wrap: anywhere; }
.ranking th:first-child, .ranking td:first-child { padding-left: 0; }
.ranking th:last-child, .ranking td:last-child { padding-right: 0; text-align: right; }
.ranking-gpt { color: #ccfa49; }
.ranking p { font-size: 1rem; }
.ranking p:empty, .ranking ul:empty { display: none; }
.ranking #ranking-share { margin-top: 12px; }

.admin #admin-data { display: grid; gap: 12px; }
.admin section { border: 1px solid #424835; border-radius: 6px; padding: 12px 16px; }
.admin h3 { margin: 0; }
.admin dl { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; margin-bottom: 0; }
.admin dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }

.admin-filters { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; margin-block: 12px; }
.admin-filters label { display: grid; gap: 4px; font-size: .9rem; }
.admin-filters input, .admin-filters select {
  min-height: 44px; max-width: 100%; box-sizing: border-box; color: inherit; background: #262a21;
  border: 1px solid #747966; border-radius: 6px; padding-inline: 8px; font: inherit;
}
.admin-table { overflow: auto; max-height: 360px; }
.admin-table th { position: sticky; top: 0; background: #141713; }
.admin-table th, .admin-table td { white-space: nowrap; }
.admin-table meter { display: block; width: 100%; min-width: 48px; }
#admin-history a { display: inline-block; color: #ccfa49; margin-top: 12px; }
