/*
 * ghosts.css
 * Level 3 ghost counting challenge.
 *
 * Requirements:
 * - The ghost screen must be visually centered.
 * - .ghost-zone must be a clean transparent gameplay layer.
 * - .ghost-zone must have no background, no border, no box-shadow.
 * - Ghosts must stay inside the zone; overflow is hidden as a safety layer.
 * - Desktop/tablet layout must stay stacked vertically, like mobile.
 * - The numeric input must have a clear visible border.
 * - On mobile phones, the whole ghost challenge must fit without vertical scroll.
 */

.ghost-challenge-screen .screen-scroll {
  min-height: 100dvh;
}

.ghost-challenge-screen .screen-inner,
.screen-inner--ghost-centered {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  align-items: center;
  justify-items: center;
  gap: clamp(10px, 2.5dvh, 18px);
  width: min(100%, var(--content-max-width));
  margin-inline: auto;
  padding-top: calc(var(--safe-top) + clamp(8px, 2dvh, 18px));
  padding-bottom: calc(var(--safe-bottom) + clamp(10px, 2.5dvh, 20px));
}

.ghost-challenge-screen .screen-title {
  width: min(100%, 720px);
  margin-inline: auto;
  text-align: center;
  line-height: var(--line-height-title);
}

.ghost-challenge {
  width: min(100%, 780px);
  max-width: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: minmax(220px, 48dvh) auto;
  align-items: stretch;
  justify-items: stretch;
  gap: clamp(10px, 2.4dvh, 18px);
  margin-inline: auto;
}

.ghost-zone {
  position: relative;
  width: min(100%, 760px);
  max-width: 100%;
  height: min(var(--ghost-zone-height, 50dvh), 500px);
  min-height: 220px;
  max-height: 520px;
  margin-inline: auto;
  overflow: hidden;
  isolation: isolate;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}

.ghost-zone::before,
.ghost-zone::after {
  display: none !important;
  content: none !important;
}

.ghost-sprite {
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  width: var(--ghost-size, clamp(44px, 14vw, 76px));
  height: var(--ghost-size, clamp(44px, 14vw, 76px));
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  filter:
    drop-shadow(0 0 10px rgba(255, 255, 255, 0.32))
    drop-shadow(0 8px 16px rgba(0, 0, 0, 0.35));
  will-change: transform;
}

.ghost-control-panel {
  width: min(100%, 760px);
  max-width: 100%;
  display: grid;
  gap: clamp(10px, 2.2dvh, 16px);
  margin-inline: auto;
}

.ghost-control-panel .text-box {
  max-height: min(22dvh, 190px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.ghost-answer-form {
  width: min(100%, 560px);
  max-width: 100%;
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
  margin-inline: auto;
  padding: clamp(12px, 3.6vw, 18px);
  border: 1px solid rgba(255, 218, 155, 0.34);
  border-radius: var(--radius-lg);
  background: rgba(9, 4, 4, 0.5);
  box-shadow: var(--shadow-soft), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.ghost-input-group {
  display: grid;
  gap: 7px;
  width: 100%;
}

.ghost-input-label {
  color: var(--color-gold);
  font-size: var(--font-size-sm);
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.48);
}

.ghost-count-input {
  width: 100%;
  min-height: clamp(48px, 12vw, 60px);
  padding: 10px 14px;
  border: 2px solid rgba(255, 218, 155, 0.72);
  border-radius: var(--radius-md);
  outline: 2px solid rgba(255, 156, 79, 0.14);
  outline-offset: 2px;
  background:
    linear-gradient(180deg, rgba(255, 244, 223, 0.12), rgba(255, 244, 223, 0.05)),
    rgba(6, 2, 2, 0.72);
  color: var(--color-text);
  font-family: var(--font-main);
  font-size: clamp(1.35rem, 7vw, 2rem);
  font-weight: 700;
  line-height: 1;
  text-align: center;
  box-shadow:
    0 10px 28px rgba(0, 0, 0, 0.3),
    0 0 0 1px rgba(255, 255, 255, 0.05),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition:
    border-color var(--duration-base) var(--ease-standard),
    box-shadow var(--duration-base) var(--ease-standard),
    background var(--duration-base) var(--ease-standard);
}

.ghost-count-input::placeholder {
  color: rgba(255, 244, 223, 0.48);
  font-weight: 600;
}

.ghost-count-input:focus {
  border-color: rgba(255, 191, 102, 1);
  outline-color: rgba(255, 168, 83, 0.28);
  background:
    linear-gradient(180deg, rgba(255, 244, 223, 0.16), rgba(255, 244, 223, 0.07)),
    rgba(6, 2, 2, 0.82);
  box-shadow:
    0 12px 34px rgba(0, 0, 0, 0.36),
    0 0 0 4px rgba(255, 168, 83, 0.14),
    0 0 28px rgba(255, 181, 94, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.ghost-status {
  min-height: 1.25em;
}

.ghost-submit {
  justify-self: center;
  width: min(100%, 360px);
}

@media (orientation: landscape) and (min-width: 760px) {
  .ghost-challenge-screen .screen-inner,
  .screen-inner--ghost-centered {
    min-height: 100dvh;
    grid-template-rows: auto minmax(0, 1fr);
    align-items: center;
    padding-inline: clamp(18px, 5vw, 56px);
  }

  .ghost-challenge {
    width: min(100%, 860px);
    grid-template-columns: 1fr;
    grid-template-rows: minmax(260px, 44dvh) auto;
    align-items: stretch;
    gap: clamp(12px, 2.4dvh, 20px);
  }

  .ghost-zone {
    width: min(100%, 860px);
    height: min(44dvh, 420px);
    max-height: 420px;
  }

  .ghost-control-panel {
    width: min(100%, 760px);
    align-self: center;
  }

  .ghost-control-panel .text-box {
    max-height: min(22dvh, 190px);
  }
}

@media (max-width: 520px) {
  .ghost-challenge-screen .screen-inner,
  .screen-inner--ghost-centered {
    gap: 9px;
  }

  .ghost-challenge {
    grid-template-rows: minmax(210px, 44dvh) auto;
    gap: 9px;
  }

  .ghost-zone {
    min-height: 210px;
    height: min(44dvh, 360px);
  }

  .ghost-control-panel .text-box {
    max-height: min(20dvh, 150px);
  }

  .ghost-answer-form {
    gap: 9px;
    padding: 11px;
    border-radius: var(--radius-md);
  }
}

@media (max-height: 640px) and (orientation: portrait) {
  .ghost-challenge-screen .screen-inner,
  .screen-inner--ghost-centered {
    gap: 7px;
    padding-top: calc(var(--safe-top) + 7px);
    padding-bottom: calc(var(--safe-bottom) + 7px);
  }

  .ghost-challenge {
    grid-template-rows: minmax(185px, 42dvh) auto;
    gap: 7px;
  }

  .ghost-zone {
    min-height: 185px;
    height: min(42dvh, 320px);
  }

  .ghost-control-panel .text-box {
    max-height: 16dvh;
  }

  .ghost-answer-form {
    padding: 9px;
  }

  .ghost-count-input {
    min-height: 44px;
    font-size: clamp(1.18rem, 6vw, 1.65rem);
  }
}

/*
 * Mobile phone no-scroll variant for level3.ghostCount.
 *
 * The room-stage container is intentionally locked without vertical scroll on
 * phones so the submit button is always visible. The ghost zone receives the
 * remaining vertical space, while the text/input area is compressed safely.
 */
@media (max-width: 520px) and (orientation: portrait) {
  .room-screen[data-screen-id="level3.ghostCount"] .screen-scroll {
    overflow-y: hidden !important;
  }

  .room-screen[data-screen-id="level3.ghostCount"] .screen-inner,
  .room-screen[data-screen-id="level3.ghostCount"] .screen-inner--ghost-centered {
    height: 100% !important;
    min-height: 100% !important;
    display: grid !important;
    grid-template-rows: auto minmax(0, 1fr) !important;
    align-content: stretch !important;
    align-items: stretch !important;
    gap: 5px !important;
    padding-top: calc(var(--safe-top) + 6px) !important;
    padding-bottom: calc(var(--safe-bottom) + 6px) !important;
  }

  .room-screen[data-screen-id="level3.ghostCount"] .screen-title {
    align-self: start;
    font-size: clamp(1.12rem, 6.1vw, 1.48rem) !important;
    line-height: 1.02;
    margin: 0 auto !important;
  }

  .room-screen[data-screen-id="level3.ghostCount"] .ghost-challenge {
    height: 100%;
    min-height: 0;
    overflow: hidden;
    display: grid;
    grid-template-rows: minmax(112px, 1fr) auto;
    gap: 5px;
    align-items: stretch;
  }

  .room-screen[data-screen-id="level3.ghostCount"] .ghost-zone {
    height: auto !important;
    min-height: 112px !important;
    max-height: none !important;
  }

  .room-screen[data-screen-id="level3.ghostCount"] .ghost-sprite {
    width: var(--ghost-size, clamp(34px, 10.5vw, 56px));
    height: var(--ghost-size, clamp(34px, 10.5vw, 56px));
  }

  .room-screen[data-screen-id="level3.ghostCount"] .ghost-control-panel {
    gap: 5px;
    min-height: 0;
  }

  .room-screen[data-screen-id="level3.ghostCount"] .ghost-control-panel .text-box {
    max-height: 64px !important;
    padding: 8px 10px !important;
    font-size: clamp(0.82rem, 3.35vw, 0.92rem) !important;
    line-height: 1.16 !important;
    overflow-y: auto;
  }

  .room-screen[data-screen-id="level3.ghostCount"] .ghost-answer-form {
    gap: 5px !important;
    padding: 7px !important;
    border-radius: var(--radius-md);
  }

  .room-screen[data-screen-id="level3.ghostCount"] .ghost-input-group {
    gap: 4px;
  }

  .room-screen[data-screen-id="level3.ghostCount"] .ghost-input-label {
    font-size: clamp(0.78rem, 3.1vw, 0.9rem);
  }

  .room-screen[data-screen-id="level3.ghostCount"] .ghost-count-input {
    min-height: 38px !important;
    padding: 6px 10px !important;
    font-size: clamp(1.05rem, 5.2vw, 1.34rem) !important;
    outline-offset: 1px;
  }

  .room-screen[data-screen-id="level3.ghostCount"] .ghost-status {
    min-height: 0;
    font-size: 0.8rem;
    line-height: 1.1;
  }

  .room-screen[data-screen-id="level3.ghostCount"] .ghost-submit {
    min-height: 40px !important;
    padding-top: 8px !important;
    padding-bottom: 8px !important;
    font-size: clamp(0.96rem, 4.1vw, 1.08rem) !important;
  }
}

@media (max-width: 390px) and (max-height: 740px) and (orientation: portrait) {
  .room-screen[data-screen-id="level3.ghostCount"] .screen-inner,
  .room-screen[data-screen-id="level3.ghostCount"] .screen-inner--ghost-centered {
    gap: 4px !important;
    padding-top: calc(var(--safe-top) + 4px) !important;
    padding-bottom: calc(var(--safe-bottom) + 4px) !important;
  }

  .room-screen[data-screen-id="level3.ghostCount"] .ghost-challenge {
    grid-template-rows: minmax(96px, 1fr) auto;
    gap: 4px;
  }

  .room-screen[data-screen-id="level3.ghostCount"] .ghost-zone {
    min-height: 96px !important;
  }

  .room-screen[data-screen-id="level3.ghostCount"] .ghost-control-panel .text-box {
    max-height: 52px !important;
    padding: 7px 9px !important;
  }

  .room-screen[data-screen-id="level3.ghostCount"] .ghost-answer-form {
    padding: 6px !important;
  }

  .room-screen[data-screen-id="level3.ghostCount"] .ghost-count-input {
    min-height: 36px !important;
  }

  .room-screen[data-screen-id="level3.ghostCount"] .ghost-submit {
    min-height: 38px !important;
  }
}
