@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;600;700;800&family=Russo+One&display=swap');

:root {
  --bg-top: #2d4d6f;
  --bg-bottom: #132536;
  --panel: rgba(23, 33, 44, 0.84);
  --panel-border: rgba(159, 200, 229, 0.34);
  --card: rgba(18, 27, 37, 0.63);
  --card-border: rgba(163, 191, 213, 0.23);
  --text: #f4f8fc;
  --muted: #9fb0bf;
  --accent: #f4bf5a;
  --accent-ink: #251502;
  --accent-cold: #5ccde0;
  --focus: #87f0ff;
  --shadow: 0 20px 50px rgba(5, 10, 16, 0.5);
  --radius: 18px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  font-family: 'Manrope', 'Segoe UI', sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 15% -10%, #35597b 0%, rgba(53, 89, 123, 0) 46%), linear-gradient(190deg, var(--bg-top) 0%, var(--bg-bottom) 58%);
}

body::before,
body::after {
  content: '';
  position: fixed;
  pointer-events: none;
  z-index: 0;
}

body::before {
  top: -16vmax;
  right: -12vmax;
  width: 44vmax;
  height: 44vmax;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(131, 209, 236, 0.28), rgba(120, 201, 214, 0));
}

body::after {
  bottom: -26vmax;
  left: -26vmax;
  width: 54vmax;
  height: 54vmax;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 203, 116, 0.2), rgba(244, 191, 90, 0));
}

a {
  color: var(--accent-cold);
  text-decoration: none;
}

#app {
  position: relative;
  height: 100%;
  width: 100%;
  isolation: isolate;
}

#c {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
  touch-action: none;
}

.shotHint {
  position: absolute;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 28px));
  z-index: 26;
  pointer-events: none;
  border-radius: 14px;
  border: 1px solid rgba(174, 209, 232, 0.35);
  background: linear-gradient(180deg, rgba(30, 45, 59, 0.85), rgba(18, 27, 36, 0.8));
  box-shadow: 0 12px 30px rgba(8, 14, 21, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 11px 12px 10px;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.shotHint.hidden {
  opacity: 0;
  transform: translate(-50%, 12px);
}

.shotHintTitle {
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.02em;
}

.shotHintSub {
  margin-top: 2px;
  color: rgba(229, 241, 250, 0.86);
  font-size: 12px;
}

.shotPower {
  margin-top: 8px;
  height: 6px;
  border-radius: 999px;
  background: rgba(80, 111, 133, 0.45);
  overflow: hidden;
}

#shotPowerFill {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(0);
  background: linear-gradient(90deg, #82cff0, #7ce58d, #ffd170);
  border-radius: inherit;
  transition: transform 0.08s linear;
}

#hud {
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 20;
  width: clamp(300px, 29vw, 420px);
  padding: calc(10px + env(safe-area-inset-top, 0px)) 12px calc(10px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: linear-gradient(190deg, rgba(34, 49, 64, 0.9), rgba(17, 26, 36, 0.76));
  border-right: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(163, 190, 209, 0.45) rgba(0, 0, 0, 0.15);
}

.hudHeader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.hudHeaderMain {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  flex: 1 1 auto;
}

.hudExpandHint {
  display: none;
  margin: 0;
  padding: 4px 8px 5px;
  line-height: 1.22;
  text-align: center;
  border-radius: 10px;
  border: 1px dashed rgba(153, 208, 232, 0.52);
  background: linear-gradient(180deg, rgba(35, 58, 75, 0.44), rgba(16, 26, 36, 0.42));
  color: #d7f1ff;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

@keyframes hintPulse {
  0%, 100% {
    border-color: rgba(153, 208, 232, 0.52);
    box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  }
  50% {
    border-color: rgba(182, 232, 255, 0.78);
    box-shadow: 0 0 0 2px rgba(130, 207, 240, 0.08);
  }
}

.hudMiniStats {
  display: flex;
  gap: 8px;
  align-items: stretch;
  flex-wrap: wrap;
}

.hudMiniStats > div {
  flex: 1 1 92px;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  background: rgba(8, 14, 20, 0.42);
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.hudMiniStats b {
  font-size: 14px;
}

.hudHeaderToggle {
  display: none;
  min-height: 42px;
  padding: 10px 12px;
  white-space: nowrap;
  align-self: flex-start;
}

#hud::-webkit-scrollbar {
  width: 10px;
}

#hud::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 20px;
}

#hud::-webkit-scrollbar-thumb {
  background: rgba(163, 190, 209, 0.45);
  border-radius: 20px;
}

.brand {
  font-family: 'Russo One', 'Segoe UI', sans-serif;
  letter-spacing: 0.14em;
  font-size: clamp(16px, 1.6vw, 22px);
  color: #f6d48d;
  text-shadow: 0 0 16px rgba(246, 212, 141, 0.35);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 10px;
  transition: max-height 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.row > * {
  min-width: 0;
}

.modeRow {
  align-items: center;
}

.modeLabel {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.row.stats {
  justify-content: space-between;
  gap: 12px;
  font-weight: 700;
  padding: 2px 2px 0;
}

.row.stats > div {
  flex: 1 1 90px;
}

.metricsRow {
  margin-top: -2px;
  border-top: 1px dashed rgba(160, 189, 209, 0.28);
  padding-top: 8px;
}

.metricsRow > div {
  font-size: 12px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.tiny {
  font-size: 11px;
}

button,
input,
select {
  font-family: inherit;
  touch-action: manipulation;
}

button {
  cursor: pointer;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  min-height: 44px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 800;
  transition: transform 0.1s ease, filter 0.2s ease, box-shadow 0.2s ease;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

button:not(.secondary) {
  background: linear-gradient(180deg, #ffd585, var(--accent));
  color: var(--accent-ink);
  box-shadow: 0 8px 24px rgba(244, 191, 90, 0.22);
}

button.secondary {
  background: linear-gradient(180deg, rgba(129, 158, 179, 0.17), rgba(56, 76, 92, 0.25));
  color: var(--text);
}

button.smallBtn {
  min-height: 38px;
  padding: 8px 10px;
  font-size: 12px;
}

button:hover:not(:disabled) {
  filter: brightness(1.05);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.row button {
  flex: 1 1 150px;
}

.compactRow button {
  min-height: 40px;
  padding: 8px 10px;
}

#btnInstallApp {
  flex: 1 1 100%;
  border-color: rgba(151, 204, 231, 0.42);
  background: linear-gradient(180deg, rgba(124, 207, 236, 0.24), rgba(54, 97, 122, 0.42));
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(155, 180, 199, 0.35);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: rgba(6, 9, 14, 0.55);
  color: var(--text);
}

select {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(155, 180, 199, 0.35);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  padding-right: 34px;
  background: rgba(6, 9, 14, 0.55);
  color: var(--text);
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, rgba(179, 203, 219, 0.92) 50%),
    linear-gradient(135deg, rgba(179, 203, 219, 0.92) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 50%,
    calc(100% - 12px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.modeRow select {
  flex: 1 1 180px;
}

select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.nickStatus {
  min-height: 14px;
}

.nickStatus.error {
  color: #ffb9b9;
}

.nickStatus.success {
  color: #9fe4ba;
}

input::placeholder {
  color: rgba(163, 179, 191, 0.72);
}

.help,
.profile,
.leaders {
  border: 1px solid var(--card-border);
  border-radius: 14px;
  background: rgba(8, 12, 17, 0.46);
  padding: 10px;
}

.help summary {
  cursor: pointer;
  user-select: none;
  font-weight: 700;
}

.helpText {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  line-height: 1.38;
}

.divider {
  height: 1px;
  background: linear-gradient(90deg, rgba(143, 173, 195, 0), rgba(143, 173, 195, 0.48), rgba(143, 173, 195, 0));
  margin: 6px 0;
}

.tableWrap {
  max-height: min(38vh, 260px);
  overflow: auto;
  border: 1px solid rgba(143, 173, 195, 0.34);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.25);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

thead th {
  position: sticky;
  top: 0;
  background: rgba(18, 28, 38, 0.95);
  border-bottom: 1px solid rgba(142, 170, 188, 0.44);
}

th,
td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

tbody tr:hover {
  background: rgba(122, 150, 172, 0.13);
}

td:nth-child(1) {
  width: 26px;
  color: var(--muted);
}

td:nth-child(3) {
  font-weight: 800;
}

td:nth-child(4) {
  color: var(--muted);
  white-space: nowrap;
}

#overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 8, 13, 0.6);
  backdrop-filter: blur(2px);
}

#overlay.hidden {
  display: none !important;
}

.authGate,
#stalledOverlay {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 8, 13, 0.64);
  backdrop-filter: blur(3px);
}

.authGate.hidden,
#stalledOverlay.hidden {
  display: none !important;
}

.authCard {
  width: min(520px, 94vw);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stallCard {
  width: min(480px, 92vw);
}

.authRow {
  align-items: stretch;
}

.authRow input {
  flex: 1 1 250px;
}

.authRow button {
  flex: 0 0 auto;
  min-width: 160px;
}

.card {
  width: min(440px, 92vw);
  background: linear-gradient(170deg, rgba(23, 35, 47, 0.96), rgba(9, 15, 22, 0.95));
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.title {
  font-size: clamp(18px, 1.8vw, 22px);
  font-weight: 900;
  margin-bottom: 6px;
}

@media (max-width: 1280px) {
  #hud {
    width: clamp(300px, 32vw, 400px);
  }
}

@media (max-width: 900px) {
  #hud {
    inset: 0 0 auto 0;
    width: 100%;
    max-height: none;
    height: auto;
    min-height: 0;
    padding: calc(2px + env(safe-area-inset-top, 0px)) 8px 4px;
    gap: 3px;
    border-right: 0;
    border-bottom: 1px solid var(--panel-border);
    border-radius: 0 0 16px 16px;
    overflow: hidden;
    background: linear-gradient(190deg, rgba(34, 49, 64, 0.94), rgba(17, 26, 36, 0.88));
  }

  #hud.open {
    inset: 0;
    height: 100dvh;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
  }

  .panel {
    margin-top: 0;
    padding: 0;
    max-height: 0;
    opacity: 0;
    transform: translateY(-8px);
    overflow: hidden;
    pointer-events: none;
    border-width: 0;
  }

  #hud.open .panel {
    max-height: none;
    flex: 1 1 auto;
    min-height: 0;
    margin-top: 2px;
    padding: 8px;
    opacity: 1;
    transform: translateY(0);
    overflow: auto;
    pointer-events: auto;
    border-width: 1px;
  }

  .hudHeader {
    gap: 4px;
    margin: 0;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
  }

  .hudHeaderMain {
    gap: 2px;
    align-items: center;
    text-align: center;
  }

  .hudHeaderToggle {
    display: none !important;
  }

  .hudExpandHint {
    display: block;
    padding: 3px 7px 4px;
    margin: 0;
    animation: hintPulse 2.1s ease-in-out infinite;
  }

  .hudMiniStats {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
  }

  .hudMiniStats > div {
    flex-basis: auto;
    min-height: 36px;
    padding: 4px 5px;
    gap: 1px;
    text-align: center;
  }

  .hudMiniStats b {
    font-size: 12px;
  }

  .row button {
    flex: 1 1 44%;
    min-height: 42px;
    padding: 9px 10px;
  }

  button,
  input,
  select {
    font-size: 16px;
  }

  .row.stats {
    font-size: 13px;
    gap: 8px;
  }

  .row.stats > div {
    flex-basis: 32%;
  }

  .metricsRow {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 8px;
    margin-top: 0;
    padding-top: 6px;
  }

  .metricsRow > div {
    font-size: 11.5px;
  }

  .metricsRow > div:last-child {
    grid-column: 1 / -1;
    text-align: center;
  }

  .tableWrap {
    max-height: min(22vh, 180px);
  }

  #leadersTable th:nth-child(4),
  #leadersTable td:nth-child(4) {
    display: none;
  }

  .shotHint {
    width: min(620px, calc(100vw - 24px));
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  #app.hud-open .shotHint {
    opacity: 0;
    transform: translate(-50%, 12px);
  }

  .authRow button {
    min-width: 0;
    flex: 1 1 100%;
  }
}

@media (max-width: 640px) {
  .brand {
    font-size: 13px;
    letter-spacing: 0.11em;
  }

  .hudMiniStats {
    gap: 3px;
  }

  .hudMiniStats > div {
    flex: 1 1 auto;
    min-height: 34px;
  }

  .hudExpandHint {
    padding: 3px 7px 4px;
    font-size: 10px;
  }

  .panel {
    gap: 8px;
  }

  .helpText {
    font-size: 12px;
  }

  .tiny {
    font-size: 10px;
  }

  .row {
    gap: 7px;
  }

  .row button,
  #btnSaveNick {
    flex: 1 1 100%;
  }

  .metricsRow > div {
    font-size: 11px;
  }

  .metricsRow {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .metricsRow > div:last-child {
    text-align: left;
  }

  .shotHint {
    border-radius: 12px;
    padding: 10px 11px 9px;
  }

  .shotHintTitle {
    font-size: 12px;
  }

  .shotHintSub {
    font-size: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hudExpandHint {
    animation: none !important;
  }
}

@media (max-height: 540px) and (max-width: 950px) {
  #hud.open .panel {
    max-height: 46vh;
  }

  .tableWrap {
    max-height: 22vh;
  }
}
