:root {
  color-scheme: dark;
  --bg: #111312;
  --panel: rgba(18, 22, 20, 0.88);
  --panel-strong: rgba(24, 29, 27, 0.96);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f5f1e8;
  --muted: #a9b2aa;
  --accent: #e3b341;
  --accent-2: #55c7a6;
  --danger: #f15f56;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 18px;
  background: #232927;
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: rgba(255, 255, 255, 0.28);
}

button.primary {
  border-color: transparent;
  background: var(--accent);
  color: #17140b;
  font-weight: 800;
}

.shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-height: 560px;
  background:
    linear-gradient(rgba(10, 13, 12, 0.35), rgba(10, 13, 12, 0.78)),
    radial-gradient(circle at 22% 20%, rgba(227, 179, 65, 0.12), transparent 26%),
    linear-gradient(135deg, #1f332c 0%, #161d1a 42%, #201c17 100%);
}

.shell::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: linear-gradient(to bottom, black, transparent 82%);
}

.panel,
.game {
  position: relative;
  z-index: 1;
}

.lobby {
  width: min(940px, calc(100vw - 32px));
  min-height: 100svh;
  margin: 0 auto;
  display: grid;
  align-content: center;
  gap: 24px;
  padding: 28px 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.mark {
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background:
    linear-gradient(45deg, transparent 44%, var(--accent) 45% 55%, transparent 56%),
    linear-gradient(-45deg, transparent 44%, var(--accent-2) 45% 55%, transparent 56%),
    #202724;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  max-width: 780px;
  font-size: clamp(36px, 7vw, 74px);
  line-height: 1.02;
}

.room-card {
  display: grid;
  gap: 16px;
  width: min(580px, 100%);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(12px);
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  outline: none;
  background: #0f1312;
  color: var(--text);
}

input:focus,
select:focus {
  border-color: var(--accent);
}

.mode-row,
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.notes {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
}

.notes span {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
}

.hidden {
  display: none;
}

.game {
  width: 100vw;
  height: 100vh;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #1d2924;
}

.hud {
  position: absolute;
  z-index: 3;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-strong);
  backdrop-filter: blur(10px);
}

.top {
  top: env(safe-area-inset-top);
  left: 0;
  right: 0;
  height: 34px;
  display: grid;
  grid-template-columns: 44px repeat(5, minmax(46px, 1fr));
  gap: 4px;
  align-items: center;
  padding: 2px 6px;
  border-radius: 0 0 6px 6px;
  direction: ltr;
}

.top > div,
.stats > div {
  min-width: 0;
}

.top > div {
  text-align: center;
}

.top > div:nth-of-type(1) {
  grid-column: 6;
}

.top > div:nth-of-type(2) {
  grid-column: 5;
}

.top > div:nth-of-type(3) {
  grid-column: 4;
}

.top > div:nth-of-type(4) {
  grid-column: 3;
}

.top > div:nth-of-type(5) {
  grid-column: 2;
}

.hud-label {
  display: block;
  color: var(--muted);
  font-size: 8px;
  font-weight: 800;
  text-transform: uppercase;
  line-height: 1;
}

.hud strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  line-height: 1.05;
}

#leaveGame {
  grid-column: 1;
  grid-row: 1;
  min-height: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 12px;
}

.stats {
  top: calc(env(safe-area-inset-top) + 38px);
  left: 50%;
  transform: translateX(-50%);
  width: min(250px, calc(100vw - 92px));
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 8px;
  padding: 5px 8px;
}

.bar {
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

.bar span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent-2);
  transition: width 120ms linear;
}

.bar.zone span {
  background: var(--accent);
}

.small {
  grid-column: 1 / -1;
  min-height: 11px;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.touch {
  position: absolute;
  z-index: 4;
  display: none;
}

.touch.left {
  left: 22px;
  bottom: max(18px, env(safe-area-inset-bottom));
}

.touch.right {
  right: 22px;
  bottom: max(18px, env(safe-area-inset-bottom));
}

.rotate-hint {
  display: none;
}

#stickBase {
  position: relative;
  width: 148px;
  height: 148px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.24);
  box-shadow: inset 0 0 0 2px rgba(245, 241, 232, 0.06);
  touch-action: none;
}

#aimRing {
  display: none;
}

#stickKnob {
  position: absolute;
  left: 55px;
  top: 55px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(245, 241, 232, 0.82);
  pointer-events: none;
}

#aimKnob {
  position: absolute;
  left: 23px;
  top: 23px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(233, 185, 68, 0.92);
  box-shadow: 0 0 12px rgba(233, 185, 68, 0.35);
}

#aimBase {
  position: relative;
  width: 148px;
  height: 148px;
  border-radius: 50%;
  border: 1px solid rgba(233, 185, 68, 0.55);
  background: rgba(233, 185, 68, 0.13);
  box-shadow: inset 0 0 0 2px rgba(245, 241, 232, 0.06);
  touch-action: none;
}

#aimBase::after {
  content: "Aim";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(245, 241, 232, 0.72);
  font-weight: 900;
  font-size: 16px;
  pointer-events: none;
}

#rightAimKnob {
  position: absolute;
  left: 54px;
  top: 54px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(233, 185, 68, 0.95);
  box-shadow: 0 0 16px rgba(233, 185, 68, 0.42);
  pointer-events: none;
}

@media (pointer: coarse), (max-width: 760px) {
  html,
  body {
    overflow: auto;
  }

  body.in-game {
    overflow: hidden;
  }

  .shell {
    height: auto;
    min-height: 100svh;
    overflow: visible;
  }

  body.in-game .shell {
    height: 100svh;
    overflow: hidden;
  }

  .lobby {
    width: min(100% - 22px, 520px);
    min-height: 100svh;
    align-content: start;
    gap: 14px;
    padding: 14px 0 22px;
  }

  h1 {
    font-size: 30px;
    line-height: 1.08;
  }

  .brand {
    gap: 10px;
  }

  .mark {
    width: 46px;
    height: 46px;
  }

  .room-card {
    gap: 11px;
    padding: 12px;
  }

  label {
    gap: 5px;
  }

  input,
  select {
    height: 42px;
  }

  .mode-row,
  .actions {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .notes {
    gap: 7px;
    font-size: 12px;
  }

  .notes span {
    padding: 6px 8px;
  }

  .touch {
    display: block;
  }

  .stats {
    top: calc(env(safe-area-inset-top) + 36px);
    left: 50%;
    transform: translateX(-50%);
    width: min(230px, calc(100vw - 190px));
    padding: 4px 7px;
    gap: 3px 7px;
  }

  .top {
    top: env(safe-area-inset-top);
    height: 32px;
    grid-template-columns: 40px repeat(3, minmax(48px, 1fr));
    grid-auto-rows: 26px;
    padding: 2px 5px;
  }

  .top > div:nth-of-type(4),
  .top > div:nth-of-type(5) {
    display: none;
  }

  .top > div:nth-of-type(1) {
    grid-column: 4;
  }

  .top > div:nth-of-type(2) {
    grid-column: 3;
  }

  .top > div:nth-of-type(3) {
    grid-column: 2;
  }

  #leaveGame {
    min-height: 26px;
    height: 26px;
    padding: 0 7px;
    font-size: 11px;
  }

  .hud strong {
    font-size: 13px;
  }

  .hud-label {
    font-size: 7px;
  }
}

@media (pointer: coarse) and (orientation: portrait) {
  body.in-game .rotate-hint {
    position: absolute;
    z-index: 8;
    inset: 0;
    display: grid;
    place-content: center;
    gap: 10px;
    padding: 24px;
    text-align: center;
    background: rgba(8, 12, 12, 0.82);
    color: var(--text);
  }

  .rotate-hint strong {
    font-size: 28px;
  }

  .rotate-hint span {
    color: var(--muted);
  }
}
