/* 9ja Kombat - responsive auto-fit + mobile touch controls */
:root {
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  background: #050a07;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
  box-sizing: border-box;
}

#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  display: block;
  width: min(100%, calc((100dvh - var(--safe-t) - var(--safe-b)) * 16 / 9));
  height: auto;
  aspect-ratio: 16 / 9;
  max-height: 100%;
  background: #000;
  image-rendering: pixelated;
  touch-action: none;
}

/* Aligns DOM overlays with the letterboxed canvas. */
#game-frame {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(100%, calc((100dvh - var(--safe-t) - var(--safe-b)) * 16 / 9));
  aspect-ratio: 16 / 9;
  max-height: 100%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 9;
}

/* ---------- AdsRoster sponsor slot (title screen) ---------- */
#sponsor-slot {
  position: absolute;
  left: 2.2%;
  bottom: 5.5%;
  width: min(340px, 28%);
  pointer-events: none;
  font: 400 clamp(10px, 1.15vw, 14px)/1.2 "Trebuchet MS", Arial, sans-serif;
  color: #e9f5ee;
  text-align: left;
}

#sponsor-slot[hidden] { display: none; }

.nk-sponsor {
  pointer-events: auto;
  overflow: hidden;
  border: 2px solid #e8b23a;
  border-radius: 10px;
  background: linear-gradient(160deg, rgba(6, 30, 18, 0.96), rgba(3, 12, 8, 0.96));
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.55);
}

.nk-sponsor__head,
.nk-sponsor__foot {
  display: flex;
  align-items: center;
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.42);
}

.nk-sponsor__head {
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid rgba(232, 178, 58, 0.35);
}

.nk-sponsor__tag {
  color: #ffd23f;
  font-size: 0.68em;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.nk-sponsor__nav {
  display: flex;
  align-items: center;
  gap: 3px;
  color: #9fd8b8;
}

.nk-sponsor__arrow {
  border: 0;
  background: none;
  color: #ffd23f;
  padding: 0 2px;
  font: 700 1.25em/1 "Trebuchet MS", Arial, sans-serif;
  cursor: pointer;
}

.nk-sponsor__arrow:hover,
.nk-sponsor__arrow:focus-visible { color: #ffffff; }

.nk-sponsor__count {
  min-width: 2.6em;
  color: #9fd8b8;
  font-size: 0.72em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.nk-sponsor__slot { display: block; }

.nk-sponsor__body {
  display: flex;
  align-items: center;
  gap: 0.7em;
  padding: 0.55em 0.7em;
  color: inherit;
  text-decoration: none;
}

.nk-sponsor__body:hover .nk-sponsor__title { color: #ffd23f; }

.nk-sponsor__img,
.nk-sponsor__plus {
  flex: 0 0 auto;
  width: 3.8em;
  height: 3.8em;
  border-radius: 6px;
}

.nk-sponsor__img {
  object-fit: cover;
  border: 1px solid rgba(232, 178, 58, 0.35);
  background: #0a1a10;
}

.nk-sponsor__plus {
  display: grid;
  place-items: center;
  border: 1px dashed rgba(232, 178, 58, 0.7);
  color: #ffd23f;
  font-size: 1.45em;
  line-height: 1;
}

.nk-sponsor__copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 0.12em;
}

.nk-sponsor__brand {
  overflow: hidden;
  color: #ffd23f;
  font-size: 0.7em;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.nk-sponsor__title {
  display: -webkit-box;
  overflow: hidden;
  color: #ffffff;
  font-size: 0.98em;
  font-weight: 700;
  line-height: 1.15;
  text-transform: uppercase;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.nk-sponsor__desc {
  display: -webkit-box;
  overflow: hidden;
  color: #a9c8b8;
  font-size: 0.76em;
  line-height: 1.25;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.nk-sponsor__foot {
  justify-content: flex-end;
  border-top: 1px solid rgba(232, 178, 58, 0.28);
}

.nk-sponsor__mode {
  border: 0;
  background: none;
  color: #ffd23f;
  padding: 1px 0;
  font: 700 0.68em/1.2 "Trebuchet MS", Arial, sans-serif;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
}

.nk-sponsor__mode:hover,
.nk-sponsor__mode:focus-visible { color: #ffffff; }

.nk-sponsor__arrow:focus-visible,
.nk-sponsor__mode:focus-visible,
.nk-sponsor__body:focus-visible {
  outline: 2px solid #ffd23f;
  outline-offset: 2px;
}

/* ---------- touch controls (only shown on touch devices) ---------- */
#touch-controls {
  display: none;
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

#touch-controls button {
  pointer-events: auto;
  position: absolute;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  background: rgba(20, 30, 25, 0.45);
  color: rgba(255, 255, 255, 0.85);
  font: 700 22px/1 "Trebuchet MS", Arial, sans-serif;
  padding: 0;
  touch-action: none;
  cursor: pointer;
}

#touch-controls button:active,
#touch-controls button.tc-down-on {
  background: rgba(0, 135, 81, 0.65);
  border-color: #ffd23f;
  color: #ffd23f;
}

/* D-pad */
#tc-left, #tc-right { width: 64px; height: 64px; bottom: 24px; }
#tc-up, #tc-down { width: 64px; height: 64px; }
#tc-up-left, #tc-up-right { width: 64px; height: 64px; bottom: 96px; }
#tc-left  { left: 16px; }
#tc-right { left: 152px; }
#tc-up    { left: 84px; bottom: 96px; }
#tc-up-left  { left: 16px; }
#tc-up-right { left: 152px; }
#tc-down  { left: 84px; bottom: 24px; }
#touch-controls .tc-diag { color: #ffd23f; border-color: rgba(255, 210, 63, 0.45); }

/* action buttons */
#act-zone .tc-act { width: 68px; height: 68px; bottom: 24px; }
#tc-punch   { right: 156px; }
#tc-kick    { right: 84px; }
#tc-special { right: 16px; bottom: 96px !important; }
#tc-special { background: rgba(60, 30, 10, 0.5); border-color: rgba(255, 170, 60, 0.5); color: #ffcc55; }

/* menu / pause buttons */
#tc-ok, #tc-back { width: 62px; height: 46px; border-radius: 10px; font-size: 15px; }
#tc-ok   { right: 96px; bottom: 110px; }
#tc-back { right: 24px; bottom: 184px; }
#tc-pause { width: 46px; height: 46px; top: 12px; right: 12px; font-size: 16px; border-radius: 10px; }
#tc-quit {
  display: none;
  width: 74px; height: 40px; border-radius: 10px; font-size: 14px;
  left: 50%; transform: translateX(-50%); bottom: 16px;
}

/* ---------- portrait: canvas on top, controls below ---------- */
@media (orientation: portrait) {
  body { justify-content: flex-start; }

  #stage { flex: 0 0 auto; width: 100%; }

  #game {
    width: 100%;
    max-height: none;
  }

  #touch-controls {
    position: fixed;
    left: 0; right: 0;
    top: auto;
    bottom: calc(var(--safe-b) + env(keyboard-inset-height, 0px));
    height: 170px;
    display: none; /* re-enabled by JS on touch devices */
    pointer-events: none;
    background: linear-gradient(180deg, rgba(0, 60, 36, 0.25), rgba(0, 40, 24, 0.55));
    border-top: 1px solid rgba(0, 135, 81, 0.5);
  }

  /* re-anchor buttons inside the bottom bar */
  #tc-left, #tc-right { bottom: 40px; }
  #tc-up, #tc-down { bottom: 40px; }
  #tc-up-left, #tc-up-right { bottom: 112px; }
  #tc-left  { left: calc(var(--safe-l) + 16px); }
  #tc-right { left: calc(var(--safe-l) + 152px); }
  #tc-up    { left: calc(var(--safe-l) + 84px); bottom: 112px; }
  #tc-up-left  { left: calc(var(--safe-l) + 16px); }
  #tc-up-right { left: calc(var(--safe-l) + 152px); }
  #tc-down  { left: calc(var(--safe-l) + 84px); bottom: 40px; }

  #act-zone .tc-act { bottom: 40px; }
  #tc-punch   { right: calc(var(--safe-r) + 156px); }
  #tc-kick    { right: calc(var(--safe-r) + 84px); }
  #tc-special { right: calc(var(--safe-r) + 16px); bottom: 112px !important; }

  #tc-ok   { right: calc(var(--safe-r) + 96px); bottom: 112px; }
  #tc-back { right: calc(var(--safe-r) + 24px); bottom: 112px; }
  #tc-pause { top: calc(var(--safe-t) + 12px); right: calc(var(--safe-r) + 12px); }
  #tc-quit { bottom: 8px; }
}

/* ---------- landscape: overlay corners ---------- */
@media (orientation: landscape) {
  #touch-controls {
    position: absolute;
    display: none; /* re-enabled by JS on touch devices */
  }
}

/* touch device + currently on the fight screen (JS toggles .tc-show on <html>) */
html.tc-show #touch-controls { display: block; }

/* ---------- join-code native input ---------- */
#code-input {
  display: none;
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  width: min(320px, 70%);
  padding: 12px 16px;
  font: 700 40px/1 "Trebuchet MS", Arial, sans-serif;
  letter-spacing: 0.4em;
  text-align: center;
  text-transform: uppercase;
  color: #ffd23f;
  background: rgba(0, 0, 0, 0.85);
  border: 3px solid #008751;
  border-radius: 10px;
  outline: none;
  z-index: 20;
  touch-action: manipulation;
  user-select: text;
  -webkit-user-select: text;
}

#code-input.show { display: block; }

/* ---------- sign-in floating panel (email/password + Google) ---------- */
#signin-float {
  display: none;
  position: absolute;
  left: 50%;
  top: 54%;
  transform: translate(-50%, -50%);
  z-index: 30;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  padding: 14px 22px;
  width: min(340px, 88vw);
  max-height: calc(100% - 16px);
  overflow-y: auto;
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.88);
  border: 3px solid #008751;
  border-radius: 14px;
  touch-action: manipulation;
}

#signin-float.show { display: flex; }

#email-signin {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

#signin-float input {
  width: 100%;
  box-sizing: border-box;
  padding: 9px 12px;
  border: 2px solid #3a4a40;
  border-radius: 8px;
  background: #101714;
  color: #fff;
  font: 600 16px/1.2 "Trebuchet MS", Arial, sans-serif;
  outline: none;
  touch-action: manipulation;
  user-select: text;
  -webkit-user-select: text;
}

#signin-float input::placeholder { color: #7d8b83; }
#signin-float input:focus { border-color: #ffd23f; background: #16211b; }

/* Password field + SHOW/HIDE control (one wrapper per password input). */
.pw-wrap { position: relative; width: 100%; }
.pw-wrap input { padding-right: 62px; }
.pw-eye {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  border-radius: 6px;
  background: rgba(0, 135, 81, 0.18);
  color: #9fd8b8;
  font: 700 11px/1 "Trebuchet MS", Arial, sans-serif;
  letter-spacing: 0.06em;
  padding: 9px 10px;
  cursor: pointer;
  touch-action: manipulation;
}
.pw-eye:active { background: rgba(255, 210, 63, 0.22); color: #ffd23f; }

#forgot-password {
  align-self: flex-end;
  border: 0;
  background: none;
  color: #9fd8b8;
  font: 600 12px/1.2 "Trebuchet MS", Arial, sans-serif;
  padding: 1px 2px;
  text-decoration: underline;
  cursor: pointer;
  touch-action: manipulation;
}
#forgot-password:active { color: #ffd23f; }

#reset-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

/* Author display rules below would otherwise beat the hidden attribute. */
#email-signin[hidden], #reset-form[hidden], #email-toggle[hidden],
#forgot-password[hidden], #gsi-button[hidden], #skip-signin[hidden],
.pw-wrap[hidden] { display: none; }

#email-submit, #reset-submit {
  width: 100%;
  border: 2px solid #00a062;
  border-radius: 8px;
  background: #008751;
  color: #fff;
  font: 700 16px/1 "Trebuchet MS", Arial, sans-serif;
  padding: 11px 16px;
  cursor: pointer;
  touch-action: manipulation;
}

#email-submit:active, #reset-submit:active { background: #006b40; }
#email-submit:disabled, #reset-submit:disabled { opacity: 0.6; cursor: default; }

#email-toggle {
  border: 0;
  background: none;
  color: #ffd23f;
  font: 600 13px/1.2 "Trebuchet MS", Arial, sans-serif;
  padding: 3px 4px;
  text-decoration: underline;
  cursor: pointer;
  touch-action: manipulation;
}

#signin-msg {
  display: none;
  max-width: 100%;
  color: #ff8a7a;
  font: 600 12px/1.35 "Trebuchet MS", Arial, sans-serif;
  text-align: center;
  overflow-wrap: anywhere;
}

#signin-msg.show { display: block; }
#signin-msg.ok { color: #9fd8b8; }

#signin-or {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  color: #777;
  font: 700 11px/1 "Trebuchet MS", Arial, sans-serif;
  letter-spacing: 0.12em;
}

#signin-or[hidden] { display: none; }
#signin-or::before, #signin-or::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #333;
}

#gsi-button { display: flex; justify-content: center; min-height: 0; }
#gsi-button:empty { display: none; }

#skip-signin {
  border: 2px solid #666;
  border-radius: 8px;
  background: #1a1a1a;
  color: #ddd;
  font: 700 14px/1 "Trebuchet MS", Arial, sans-serif;
  padding: 10px 18px;
  cursor: pointer;
  touch-action: manipulation;
}

#skip-signin:active { background: #333; color: #fff; }

/* landscape: pull the sign-in panel a bit higher so it clears thumbs */
@media (orientation: landscape) {
  #signin-float { top: 50%; padding: 10px 20px; gap: 7px; }
  #email-signin { gap: 6px; }
  #reset-form { gap: 6px; }
  #signin-float input { padding: 7px 10px; }
  .pw-wrap input { padding-right: 62px; }
  #email-submit, #reset-submit { padding: 9px 16px; }
  #skip-signin { padding: 8px 16px; }
}

/* very short landscape screens: trim the panel further */
@media (orientation: landscape) and (max-height: 420px) {
  #signin-float { border-width: 2px; gap: 5px; padding: 8px 16px; }
  #email-signin { gap: 5px; }
  #reset-form { gap: 5px; }
  #signin-float input { padding: 6px 10px; font-size: 15px; }
  .pw-wrap input { padding-right: 58px; }
  #email-submit, #reset-submit { padding: 8px 16px; font-size: 15px; }
  #skip-signin { padding: 7px 14px; font-size: 13px; }
  #email-toggle { font-size: 12px; padding: 2px; }
  #forgot-password { font-size: 11px; }
  #signin-or { display: none; }
}

/* ---------- strict landscape: block play in portrait (touch devices only) ---------- */
#rotate-lock {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: #050a07;
  color: #ffd23f;
  text-align: center;
  padding: 24px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#rotate-lock .rl-icon {
  font-size: 64px;
  line-height: 1;
  animation: rl-spin 2.4s ease-in-out infinite;
}

#rotate-lock .rl-text {
  font: 700 22px/1.4 "Trebuchet MS", Arial, sans-serif;
  letter-spacing: 2px;
  text-transform: uppercase;
}

#rotate-lock .rl-sub {
  font: 400 14px/1.5 "Trebuchet MS", Arial, sans-serif;
  color: rgba(255, 255, 255, 0.6);
  letter-spacing: 1px;
}

@keyframes rl-spin {
  0%, 40%   { transform: rotate(0deg); }
  60%, 100% { transform: rotate(90deg); }
}

@media (orientation: portrait) and (pointer: coarse) {
  #rotate-lock { display: flex; }
}
