:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, Segoe UI, sans-serif;
  background: #0e0e14;
  color: #ececf4;
}

body {
  margin: 0;
}

.lab {
  max-width: 640px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

.lab__header h1 {
  margin: 0 0 0.35rem;
  font-size: 1.5rem;
}

.lab__header p {
  margin: 0;
  color: #a8a8bc;
}

.lab__card {
  margin-top: 1.25rem;
  padding: 1rem 1.1rem;
  border-radius: 12px;
  background: #171722;
  border: 1px solid #2a2a3a;
}

.lab__field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.9rem;
  font-size: 0.9rem;
}

.lab__fieldset {
  border: 1px solid #2a2a3a;
  border-radius: 10px;
  padding: 0.75rem 0.9rem 0.2rem;
  margin: 0 0 0.9rem;
}

.lab__fieldset legend {
  padding: 0 0.35rem;
  color: #b8b8d0;
  font-size: 0.9rem;
}

.lab__field textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  min-height: 6rem;
  resize: vertical;
  border-radius: 8px;
  border: 1px solid #3a3a50;
  background: #101018;
  color: #ececf4;
  padding: 0.55rem 0.65rem;
}

.lab__field input,
.lab__field select {
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid #3a3a50;
  background: #101018;
  color: inherit;
}

.lab__button {
  width: 100%;
  padding: 0.7rem 1rem;
  border: none;
  border-radius: 8px;
  background: #4f6bff;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.lab__status {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  color: #9cb4ff;
}

.lab__hint {
  margin: 0.65rem 0 0;
  font-size: 0.85rem;
  color: #a8a8bc;
}

.lab__help ol {
  margin: 0.5rem 0 0;
  padding-left: 1.2rem;
  color: #b8b8c8;
}

.lab__qr-card h2 {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
}

.lab__qr-hint {
  margin: 0 0 0.75rem;
  color: #a8a8bc;
  font-size: 0.9rem;
}

.lab__qr-host {
  display: flex;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.lab__qr-host svg {
  display: block;
  width: 200px;
  height: 200px;
}

.lab__qr-link {
  display: block;
  word-break: break-all;
  font-size: 0.82rem;
  color: #9cb4ff;
  text-decoration: none;
}

.lab__qr-link:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

.controller-body {
  margin: 0;
  overscroll-behavior: none;
  background: #0e0e14;
}

.controller-rotate-hint {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: #0e0e14;
  color: #ececf4;
  text-align: center;
  font-size: 1.1rem;
}

.controller--gamepad {
  max-width: none;
  width: 100%;
  min-height: 100dvh;
  margin: 0;
  padding:
    max(0.35rem, env(safe-area-inset-top))
    max(0.35rem, env(safe-area-inset-right))
    max(0.35rem, env(safe-area-inset-bottom))
    max(0.35rem, env(safe-area-inset-left));
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.controller__topbar {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  min-height: 2.5rem;
  flex-shrink: 0;
}

.controller__topbar-left {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

.controller__status-dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: #6a6a7a;
  flex-shrink: 0;
}

.controller__status-dot--ok {
  background: #3ecf8e;
  box-shadow: 0 0 0 2px rgba(62, 207, 142, 0.25);
}

.controller__status-dot--warn {
  background: #e8b84a;
  box-shadow: 0 0 0 2px rgba(232, 184, 74, 0.25);
}

.controller__status-dot--err {
  background: #e85d5d;
  box-shadow: 0 0 0 2px rgba(232, 93, 93, 0.25);
}

.controller__screen-chip {
  border: 1px solid #3a3a50;
  background: #171722;
  color: #ececf4;
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.82rem;
  max-width: 11rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  touch-action: manipulation;
  cursor: pointer;
}

.controller__marquee {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  border-radius: 8px;
  background: #171722;
  border: 1px solid #2a2a3a;
  display: flex;
  align-items: center;
}

.controller__marquee-track {
  display: flex;
  width: max-content;
  animation: controller-marquee 28s linear infinite;
  padding: 0 0.75rem;
  gap: 2.5rem;
}

.controller__marquee-track span {
  white-space: nowrap;
  font-size: 0.82rem;
  color: #b8b8d0;
  line-height: 2.25rem;
}

@keyframes controller-marquee {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-50%);
  }
}

.controller__stage {
  flex: 1;
  min-height: 0;
  display: grid;
  position: relative;
}

.controller__nick {
  position: absolute;
  top: 0.35rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: rgba(8, 8, 14, 0.72);
  color: #ececf4;
  font: 600 0.85rem/1.2 system-ui, sans-serif;
  pointer-events: none;
  white-space: nowrap;
}

.controller__stage-main {
  position: relative;
  min-height: 0;
  height: 100%;
  width: 100%;
}

.controller__stick {
  position: absolute;
  touch-action: none;
  left: max(0.1rem, env(safe-area-inset-left));
  bottom: max(1.85rem, calc(env(safe-area-inset-bottom) + 1rem));
  width: min(34vmin, 168px);
  height: min(34vmin, 168px);
  border-radius: 50%;
  background: #1e1e2c;
  border: 2px solid #3a3a50;
  z-index: 2;
}

.controller__stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(14vmin, 58px);
  height: min(14vmin, 58px);
  border-radius: 50%;
  background: #4f6bff;
  transform: translate(-50%, -50%);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.controller__buttons {
  position: absolute;
  right: max(1.75rem, env(safe-area-inset-right));
  bottom: max(1.85rem, calc(env(safe-area-inset-bottom) + 1rem));
  width: min(28vw, 148px);
  height: min(28vw, 148px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 0.35rem;
  z-index: 2;
}

.controller__btn {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: none;
  border-radius: 14px;
  background: #4f6bff;
  color: #fff;
  font-weight: 700;
  font-size: clamp(1rem, 4vw, 1.35rem);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.28);
}

.controller__btn--a {
  grid-column: 1;
  grid-row: 2;
}

.controller__btn--b {
  grid-column: 2;
  grid-row: 1;
}

.controller__btn-start {
  position: absolute;
  left: 50%;
  bottom: max(1.1rem, calc(env(safe-area-inset-bottom) + 0.45rem));
  transform: translateX(-50%);
  z-index: 2;
  min-width: 5.75rem;
  min-height: 3rem;
  padding: 0.55rem 1.25rem;
  border: none;
  border-radius: 14px;
  background: #3ecf8e;
  color: #0e0e14;
  font: 700 clamp(0.85rem, 3.5vw, 1rem) system-ui, sans-serif;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.28);
}

.controller__btn-start:active,
.controller__btn-start.controller__btn--pressed {
  transform: translateX(-50%) scale(0.96);
  background: #2fb878;
}

.controller__btn:active,
.controller__btn.controller__btn--pressed {
  transform: scale(0.96);
  background: #3d56d4;
}

.controller__emoji-btn.controller__emoji-btn--pressed {
  transform: scale(0.94);
  background: #252538;
}

.controller__emoji {
  display: flex;
  touch-action: manipulation;
  z-index: 1;
}

.controller__emoji-btn {
  font-size: clamp(1.25rem, 4.5vw, 1.65rem);
  padding: 0.35rem;
  border-radius: 10px;
  border: 1px solid #3a3a50;
  background: #171722;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  flex-shrink: 0;
}

@media (orientation: landscape) {
  .controller__stage {
    grid-template-columns: 1fr auto;
  }

  .controller__stage-main {
    grid-column: 1;
    grid-row: 1;
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
    align-self: end;
    box-sizing: border-box;
    width: 100%;
    min-height: min(34vmin, 168px);
    padding:
      0
      max(1.25rem, env(safe-area-inset-right))
      max(1.85rem, calc(env(safe-area-inset-bottom) + 1rem))
      max(1.25rem, env(safe-area-inset-left));
  }

  .controller__stick {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    flex-shrink: 0;
    margin-left: 0;
  }

  .controller__btn-start {
    position: absolute;
    left: 50%;
    bottom: max(0.55rem, calc(env(safe-area-inset-bottom) + 0.15rem));
    transform: translateX(-50%);
    flex-shrink: 0;
  }

  .controller__btn-start:active,
  .controller__btn-start.controller__btn--pressed {
    transform: translateX(-50%) scale(0.96);
  }

  .controller__buttons {
    position: static;
    left: auto;
    right: auto;
    bottom: auto;
    flex-shrink: 0;
    margin-right: 0;
  }

  .controller__emoji {
    grid-column: 2;
    grid-row: 1;
    align-self: stretch;
    flex-direction: column;
    justify-content: space-evenly;
    align-items: center;
    width: 3.75rem;
    padding: 0.35rem 0.25rem;
    box-sizing: border-box;
  }
}

@media (orientation: portrait) {
  .controller--gamepad {
    min-height: 100dvh;
    padding-bottom: 0;
  }

  .controller__topbar,
  .controller__stage-main {
    display: none;
  }

  .controller__stage {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    min-height: 100dvh;
  }

  .controller-rotate-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 4.75rem;
    z-index: 5;
    padding: 2rem 1.5rem;
    background: #0e0e14;
  }

  .controller__emoji {
    position: relative;
    z-index: 10;
    flex-direction: row;
    justify-content: space-evenly;
    align-items: center;
    width: 100%;
    padding: 0.65rem 0.5rem max(0.65rem, env(safe-area-inset-bottom));
    box-sizing: border-box;
    border-top: 1px solid #2a2a3a;
    background: #12121a;
  }
}

.controller__sheet {
  border: 1px solid #3a3a50;
  border-radius: 14px 14px 0 0;
  padding: 0;
  background: #171722;
  color: #ececf4;
  max-width: 100%;
  width: 100%;
  margin: 0;
}

.controller__sheet::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.controller__sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid #2a2a3a;
}

.controller__sheet-head h2 {
  margin: 0;
  font-size: 1rem;
}

.controller__sheet-close {
  border: none;
  background: transparent;
  color: #a8a8bc;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem 0.45rem;
}

.controller__screen-list {
  list-style: none;
  margin: 0;
  padding: 0.35rem 0 0.75rem;
  max-height: 50vh;
  overflow: auto;
}

.controller__screen-list li button {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: #ececf4;
  padding: 0.75rem 1rem;
  font-size: 0.92rem;
  cursor: pointer;
}

.controller__screen-list li button:hover,
.controller__screen-list li button:focus {
  background: #1e1e2c;
}

.controller__screen-list li button[aria-current='true'] {
  background: #252538;
  color: #9cb4ff;
}
