:root {
  --bg: #0b0b0f;
  --surface: rgba(255, 255, 255, 0.055);
  --surface-hi: rgba(255, 255, 255, 0.12);
  --line: rgba(255, 255, 255, 0.09);
  --line-hi: rgba(255, 255, 255, 0.22);
  --text: #ececf1;
  --muted: rgba(236, 236, 241, 0.55);
  --accent: #c8f65b;
  --live: #ff5a4f;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --spring: cubic-bezier(0.34, 1.5, 0.64, 1);
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(120% 70% at 50% -10%, rgba(200, 246, 91, 0.07), transparent 60%),
    radial-gradient(90% 60% at 50% 110%, rgba(255, 255, 255, 0.04), transparent 60%),
    var(--bg);
  overflow: hidden;
  position: fixed;
  inset: 0;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  touch-action: none;
}

[hidden] { display: none !important; }

#haptic { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; overflow: hidden; }

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

.mark { width: 22px; height: 22px; color: var(--text); flex: none; }

/* ---------- Connect ---------- */

#connect {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 20px) calc(env(safe-area-inset-right) + 24px)
    calc(env(safe-area-inset-bottom) + 20px) calc(env(safe-area-inset-left) + 24px);
  max-width: 560px;
  margin: 0 auto;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -0.01em; }
.brand .mark { width: 28px; height: 28px; }

.connect-body { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 12px; }

h1 { font-size: 30px; line-height: 1.12; font-weight: 650; letter-spacing: -0.025em; }

.hosts { list-style: none; display: grid; gap: 10px; margin-top: 18px; }

.host {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  text-align: left;
  transition: transform 0.25s var(--spring), background 0.2s;
  touch-action: manipulation;
}
.host:active { transform: scale(0.97); background: var(--surface-hi); }
.host .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.host b { display: block; font-weight: 600; }
.host small { color: var(--muted); }
.host .go { margin-left: auto; color: var(--muted); font-size: 22px; }

.code { margin-top: 16px; }
.digits { margin-top: 10px; font: 600 54px/1 ui-monospace, "SF Mono", monospace; letter-spacing: 0.22em; }

.connect-foot { font-size: 13px; display: grid; gap: 6px; }

.pulse { animation: pulse 1.6s var(--ease) infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

/* ---------- Pad ---------- */

#pad {
  position: fixed;
  inset: 0;
  display: grid;
  gap: 14px;
  padding: calc(env(safe-area-inset-top) + 10px) calc(env(safe-area-inset-right) + 14px)
    calc(env(safe-area-inset-bottom) + 14px) calc(env(safe-area-inset-left) + 14px);
  touch-action: none;
  /* Portrait: sticks under the thumbs, talk along the bottom. */
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto 1fr auto auto;
  grid-template-areas:
    "bar bar"
    "sh sh"
    "lstick rstick"
    "dpad face"
    "talk talk";
}

@media (orientation: landscape) {
  #pad {
    gap: 10px 18px;
    grid-template-columns: 1fr minmax(0, 1.1fr) 1fr;
    grid-template-rows: auto 1fr 1fr;
    grid-template-areas:
      "bar bar bar"
      "dpad sh face"
      "lstick rstick talk";
  }
}

.side { display: contents; }
.side.left .stick { grid-area: lstick; }
.side.right .stick { grid-area: rstick; }
.dpad { grid-area: dpad; }
.face { grid-area: face; }
.bar { grid-area: bar; }
.shoulders { grid-area: sh; }
.talk { grid-area: talk; }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 550;
  max-width: 40vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: transform 0.2s var(--spring), background 0.15s;
}
.chip .mark { width: 18px; height: 18px; }
.chip.down { transform: scale(0.94); background: var(--surface-hi); }

.status { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.status.live i { background: var(--live); box-shadow: 0 0 12px var(--live); }
.status.live { color: var(--text); }
.status.lost i { background: #777; box-shadow: none; }

.shoulders { display: flex; gap: 10px; justify-content: center; align-items: center; }

.shoulder {
  flex: 1;
  max-width: 150px;
  height: 46px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
  transition: transform 0.18s var(--spring), background 0.12s, border-color 0.12s;
}
.shoulder small { font-size: 10px; font-weight: 500; color: var(--muted); letter-spacing: 0.04em; }

/* Sticks: the whole area is live; the ring recenters where the thumb lands. */
.stick {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  touch-action: none;
}
.stick .ring {
  --size: min(100%, 38vmin, 190px);
  width: var(--size);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.025) 70%);
  border: 1px solid var(--line);
  position: relative;
  transition: transform 0.35s var(--ease), border-color 0.2s;
}
.stick .knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44%;
  aspect-ratio: 1;
  border-radius: 50%;
  translate: -50% -50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.1));
  border: 1px solid var(--line-hi);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: transform 0.3s var(--spring);
}
.stick.active .ring { border-color: var(--line-hi); }
.stick.active .knob { transition: none; }
.stick-label {
  position: absolute;
  bottom: 2px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.7;
  pointer-events: none;
}

/* D-pad and face buttons: four buttons around a center. */
.dpad, .face {
  --size: min(34vmin, 170px);
  justify-self: center;
  align-self: center;
  width: var(--size);
  aspect-ratio: 1;
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  gap: 4px;
}
.dpad [data-key="up"], .face .triangle { grid-area: 1 / 2; }
.dpad [data-key="left"], .face .square { grid-area: 2 / 1; }
.dpad [data-key="right"], .face .circle { grid-area: 2 / 3; }
.dpad [data-key="down"], .face .cross { grid-area: 3 / 2; }

.dpad button {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  position: relative;
  transition: transform 0.18s var(--spring), background 0.12s;
}
.dpad button::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 0;
  height: 0;
  border: 7px solid transparent;
  border-bottom-color: var(--muted);
  translate: 0 -3px;
}
.dpad [data-key="down"]::after { rotate: 180deg; translate: 0 3px; }
.dpad [data-key="left"]::after { rotate: -90deg; translate: -3px 0; }
.dpad [data-key="right"]::after { rotate: 90deg; translate: 3px 0; }

.face button {
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 22px;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: transform 0.18s var(--spring), background 0.12s, color 0.12s;
}
.face .triangle { color: #7fe0c4; }
.face .circle { color: #ff8a80; }
.face .cross { color: #9fb7ff; }
.face .square { color: #f2a7d8; }

/* Pressed, for every control. */
.down { transform: scale(0.9); background: var(--surface-hi) !important; border-color: var(--line-hi) !important; }

.talk {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 76px;
  border-radius: 26px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
  border: 1px solid var(--line-hi);
  font-weight: 650;
  font-size: 17px;
  letter-spacing: -0.01em;
  overflow: hidden;
  transition: transform 0.25s var(--spring), background 0.2s, box-shadow 0.3s var(--ease), border-color 0.2s;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.talk svg { width: 26px; height: 26px; fill: currentColor; position: relative; }
.talk span { position: relative; }
.talk canvas { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; transition: opacity 0.2s; }

@media (orientation: landscape) {
  .talk {
    justify-self: center;
    align-self: center;
    width: min(100%, 42vmin, 210px);
    aspect-ratio: 1;
    min-height: 0;
    border-radius: 50%;
    flex-direction: column;
    gap: 6px;
    font-size: 14px;
  }
}

.talk.down {
  transform: scale(0.95);
  background: linear-gradient(180deg, rgba(255, 90, 79, 0.32), rgba(255, 90, 79, 0.16)) !important;
  border-color: rgba(255, 90, 79, 0.7) !important;
  box-shadow: 0 0 0 6px rgba(255, 90, 79, 0.12), 0 0 48px rgba(255, 90, 79, 0.35);
}
.talk.down canvas { opacity: 1; }

.no-mic .talk span::after { content: " (no microphone)"; color: var(--muted); font-weight: 500; }

/* Short screens in landscape: drop the stick captions. */
@media (orientation: landscape) and (max-height: 380px) {
  .stick-label { display: none; }
  .shoulder { height: 40px; }
}
