:root {
  color-scheme: dark;
  --bg: #10130f;
  --panel: #1b2018;
  --panel-strong: #242b20;
  --line: rgba(246, 243, 232, 0.14);
  --text: #f6f3e8;
  --muted: #adb49f;
  --green: #48bf75;
  --green-deep: #205d3c;
  --amber: #f2bd54;
  --coral: #ee705f;
  --blue: #73a7ff;
  --nav-height: 66px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tg-content-safe-top: 0px;
  --tg-content-safe-bottom: 0px;
  --tg-chrome-top: 0px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  overscroll-behavior: none;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  touch-action: none;
  user-select: none;
}

body.is-telegram-webapp {
  --tg-chrome-top: 64px;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #2a3026;
  color: var(--text);
  min-height: 44px;
  padding: 0 14px;
  cursor: pointer;
}

button:active,
button.is-pressed {
  transform: translateY(1px) scale(0.98);
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #11150f;
  color: var(--text);
  min-height: 44px;
  padding: 0 12px;
  outline: none;
}

h1,
h2,
p {
  margin: 0;
}

.app-shell {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) calc(var(--nav-height) + max(var(--safe-bottom), var(--tg-content-safe-bottom)));
  background:
    radial-gradient(circle at 50% 0%, rgba(72, 191, 117, 0.16), transparent 18rem),
    linear-gradient(180deg, #11160f 0%, #151912 100%);
}

.screen {
  min-height: 0;
  display: none;
}

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

.game-screen {
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
}

.game-hud {
  padding: calc(8px + var(--tg-content-safe-top) + var(--tg-chrome-top)) 12px 8px;
  background: rgba(12, 15, 11, 0.9);
  border-bottom: 1px solid var(--line);
}

.hud-strip {
  min-height: 38px;
  display: grid;
  grid-template-columns: minmax(64px, max-content) auto minmax(52px, max-content);
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.game-hud p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  min-width: 0;
  max-width: 116px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#timer {
  justify-self: center;
  min-width: 56px;
  min-height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #171d14;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.scoreboard {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 14px;
  white-space: nowrap;
}

.scoreboard strong {
  font-size: 28px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.team-left {
  color: var(--blue);
  text-align: right;
}

.team-right {
  color: var(--amber);
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 6px 8px calc(10px + max(var(--safe-bottom), var(--tg-content-safe-bottom)));
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.24), transparent 10%, transparent 90%, rgba(0, 0, 0, 0.24)),
    #11160f;
  touch-action: none;
}

#gameCanvas {
  display: block;
  width: min(
    calc(100vw - 16px),
    calc((100dvh - var(--nav-height) - var(--tg-content-safe-top) - var(--tg-chrome-top) - 64px) * 0.5833)
  );
  height: auto;
  max-height: 100%;
  aspect-ratio: 7 / 12;
  border-radius: 12px;
  background: #2f8a55;
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.28),
    inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}

.touch-controls {
  position: absolute;
  left: 14px;
  right: 110px;
  bottom: calc(12px + max(var(--safe-bottom), var(--tg-content-safe-bottom)));
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  user-select: none;
  pointer-events: none;
  transition: opacity 0.16s ease;
  z-index: 4;
}

.touch-controls.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.joystick-pad {
  position: relative;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, rgba(255, 255, 255, 0.12), transparent 33%),
    rgba(246, 243, 232, 0.08);
  border: 1px solid rgba(246, 243, 232, 0.18);
  box-shadow: inset 0 0 0 8px rgba(0, 0, 0, 0.12);
  touch-action: none;
  pointer-events: auto;
  backdrop-filter: blur(12px);
}

.joystick-thumb {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: linear-gradient(180deg, #f8f1dc, #c9d4b7);
  border: 2px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.32);
  transform: translate(0, 0);
  pointer-events: none;
}

.action-buttons {
  display: grid;
  grid-template-columns: 86px;
  gap: 10px;
  pointer-events: auto;
}

.action-button {
  min-height: 58px;
  padding: 0 10px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 850;
  letter-spacing: 0;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.32);
}

.lobby-overlay {
  position: absolute;
  inset: 8px;
  display: grid;
  place-items: center;
  z-index: 5;
  pointer-events: none;
}

.lobby-overlay[hidden] {
  display: none;
}

.lobby-card {
  width: min(100%, 390px);
  border: 1px solid rgba(246, 243, 232, 0.18);
  border-radius: 12px;
  background: rgba(14, 18, 12, 0.88);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(14px);
  padding: 12px;
  display: grid;
  gap: 12px;
  pointer-events: auto;
}

.lobby-card header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.lobby-card p,
.spectator-list {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.lobby-card h1 {
  margin: 2px 0 0;
  font-size: 20px;
  line-height: 1.12;
}

.ready-button {
  min-width: 92px;
  border-radius: 14px;
  background: var(--green);
  border-color: #73d895;
  color: #07140b;
  font-weight: 900;
}

.ready-button.is-ready {
  background: #2a3026;
  color: var(--text);
}

.team-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.team-board section {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(6, 9, 5, 0.45);
  padding: 8px;
}

.team-board h2 {
  font-size: 12px;
  line-height: 1.2;
  margin-bottom: 8px;
  color: var(--muted);
}

.roster-list {
  display: grid;
  gap: 6px;
  list-style: none;
  padding: 0;
  margin: 0;
}

.roster-item {
  min-width: 0;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 7px;
  align-items: center;
}

.roster-avatar {
  grid-row: 1 / 3;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #e9e4d4;
  color: #10120d;
  font-size: 10px;
  font-weight: 900;
}

.roster-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.roster-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 850;
}

.ready-state {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

.ready-state.is-ready {
  color: var(--green);
}

.roster-empty {
  color: rgba(246, 243, 232, 0.44);
  font-size: 12px;
}

.lobby-overlay.is-spectating {
  place-items: start center;
}

.lobby-overlay.is-spectating .lobby-card {
  width: min(100%, 340px);
}

.action-button.primary {
  background: var(--coral);
  border-color: #ff9b8d;
  color: #220806;
}

.action-button.secondary {
  background: var(--amber);
  border-color: #ffd780;
  color: #211503;
}

.panel-screen {
  overflow: auto;
  padding: calc(18px + var(--tg-content-safe-top)) 16px 18px;
  background:
    radial-gradient(circle at 70% 0%, rgba(242, 189, 84, 0.12), transparent 15rem),
    var(--panel);
}

.panel-screen.is-active {
  display: block;
}

.panel-header {
  display: grid;
  gap: 6px;
  margin-bottom: 16px;
}

.panel-header h1 {
  font-size: 26px;
  line-height: 1.08;
}

.panel-header p,
.shop-item p,
.event-list,
.stats-grid span,
.wallet-line span,
.dev-panel label {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.profile-card,
.feed-card,
.dev-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(15, 18, 13, 0.7);
  padding: 12px;
  margin-bottom: 12px;
}

.wallet-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 52px;
}

.wallet-line strong {
  color: var(--amber);
  font-size: 34px;
  font-variant-numeric: tabular-nums;
}

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

.stats-grid div {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #11150f;
  padding: 10px;
}

.stats-grid strong {
  display: block;
  margin-top: 3px;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.shop-list {
  display: grid;
  gap: 10px;
}

.shop-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(15, 18, 13, 0.74);
  padding: 12px;
  display: grid;
  gap: 10px;
}

.shop-item header {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.shop-item header div {
  min-width: 0;
}

.swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.36);
  flex: 0 0 auto;
}

.shop-item h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.25;
}

.shop-item h3,
.shop-item p {
  min-width: 0;
  overflow-wrap: anywhere;
}

.shop-item footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.price {
  color: var(--amber);
  font-size: 13px;
  font-weight: 850;
}

.event-list {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
  display: grid;
  gap: 7px;
}

.event-list li {
  border-left: 3px solid var(--green);
  padding-left: 9px;
}

.dev-panel {
  display: grid;
  gap: 10px;
}

.dev-panel summary {
  cursor: pointer;
  font-weight: 800;
}

.dev-panel label {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.dev-panel button {
  width: 100%;
  margin-top: 8px;
}

.dev-panel input {
  overflow-wrap: anywhere;
}

.bottom-nav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 8px 12px calc(8px + max(var(--safe-bottom), var(--tg-content-safe-bottom)));
  background: rgba(10, 12, 9, 0.98);
  border-top: 1px solid var(--line);
}

.bottom-nav button {
  min-height: 48px;
  border-radius: 14px;
  color: var(--muted);
  font-weight: 800;
}

.bottom-nav button.is-active {
  background: var(--green);
  border-color: #73d895;
  color: #07140b;
}

@media (min-width: 760px) {
  .app-shell {
    max-width: 460px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
}

@media (max-height: 720px) {
  #gameCanvas {
    width: min(
      calc(100vw - 16px),
      calc((100dvh - var(--nav-height) - var(--tg-content-safe-top) - var(--tg-chrome-top) - 58px) * 0.5833)
    );
  }

  .joystick-pad {
    width: 112px;
    height: 112px;
  }

  .joystick-thumb {
    width: 48px;
    height: 48px;
    margin: -24px 0 0 -24px;
  }

  .action-button {
    min-height: 52px;
  }
}
