/* QA report follow-up fixes for Blackout Repair Crew.
   Scope: interaction stability, command clarity, and small-screen layout resilience. */

.command-bar {
  pointer-events: auto;
  align-items: center;
  gap: 10px;
  touch-action: manipulation;
}

.command-bar button,
.switch-card,
.map-building,
.stage-card {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.command-bar button {
  min-height: 54px;
  position: relative;
}

.command-helper {
  grid-column: 1 / -1;
  display: none;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 8px 12px;
  border: 1px solid rgba(77, 220, 255, .22);
  border-radius: 14px;
  color: #cfe0f8;
  background: rgba(77, 220, 255, .08);
  font-size: 12px;
  font-weight: 850;
  line-height: 1.35;
}

.command-helper::before {
  content: "안내";
  flex: 0 0 auto;
  padding: 3px 7px;
  border-radius: 999px;
  color: #06101a;
  background: var(--cyan);
  font-size: 10px;
  font-weight: 950;
}

.command-bar[data-has-helper="1"] .command-helper {
  display: flex;
}

.apply-btn {
  min-height: 60px;
  border: 2px solid rgba(77, 220, 255, .42);
  background: linear-gradient(135deg, rgba(77, 220, 255, .22), rgba(67, 240, 162, .10));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06), 0 14px 34px rgba(0,0,0,.22);
}

.apply-btn:not(:disabled) {
  color: #f8fcff;
  border-color: rgba(77, 220, 255, .72);
  box-shadow: 0 0 0 2px rgba(77,220,255,.14), 0 16px 44px rgba(77,220,255,.16);
}

.apply-btn:not(:disabled)::after {
  content: "한 번만 눌러 적용";
  position: absolute;
  right: 12px;
  bottom: 6px;
  color: rgba(207, 224, 248, .78);
  font-size: 10px;
  font-weight: 850;
}

.apply-btn[data-busy="1"],
.apply-btn.is-applying {
  cursor: progress;
  opacity: .78;
  pointer-events: none;
}

#undo-button:not(:disabled) {
  border-color: rgba(255, 209, 102, .34);
  background: rgba(255, 209, 102, .08);
}

#finalize-button:not(:disabled) {
  border: 2px solid rgba(67, 240, 162, .62);
  box-shadow: 0 0 0 2px rgba(67,240,162,.16), 0 16px 44px rgba(67,240,162,.12);
}

.switch-card {
  min-height: 128px;
}

.switch-card.selected {
  outline: 2px solid rgba(77, 220, 255, .34);
  outline-offset: 2px;
}

.switch-card.selected::after {
  content: "선택됨 · 아래 큰 버튼으로 적용";
  display: inline-flex;
  width: fit-content;
  margin-top: 2px;
  padding: 4px 8px;
  border-radius: 999px;
  color: #06101a;
  background: linear-gradient(135deg, var(--cyan), var(--ok));
  font-size: 11px;
  font-weight: 950;
}

.switch-card.on::after {
  content: "켜짐 · 다시 선택해 끌 수 있음";
  color: #031b12;
  background: var(--ok);
}

.building-list,
.switch-list {
  scrollbar-width: thin;
  scrollbar-color: rgba(77, 220, 255, .58) rgba(255, 255, 255, .06);
}

.building-list::-webkit-scrollbar,
.switch-list::-webkit-scrollbar {
  width: 8px;
}

.building-list::-webkit-scrollbar-thumb,
.switch-list::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(77, 220, 255, .58);
}

.building-list::-webkit-scrollbar-track,
.switch-list::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, .06);
}

.event-log {
  max-height: 132px;
  overflow: auto;
}

@media (max-width: 1180px) {
  .app {
    padding-left: 12px;
    padding-right: 12px;
  }

  .game-layout {
    grid-template-columns: minmax(240px, .84fr) minmax(360px, 1.22fr);
    grid-template-areas:
      "buildings district"
      "switches switches";
  }

  .building-panel { grid-area: buildings; }
  .district-panel { grid-area: district; min-height: auto; }
  .switch-panel { grid-area: switches; }

  .building-list {
    max-height: 48vh;
    overflow-y: auto;
    padding-bottom: 4px;
  }

  .switch-list {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    max-height: 36vh;
  }

  .district-map {
    min-height: 500px;
  }

  .command-bar {
    grid-template-columns: repeat(3, minmax(56px, auto)) minmax(130px, .82fr) minmax(240px, 1.35fr) minmax(190px, 1fr);
  }
}

@media (max-width: 860px) {
  .topbar {
    grid-template-columns: 44px 1fr 44px;
  }

  .game-layout {
    display: grid;
    grid-template-columns: 1fr;
  }

  .card-panel {
    padding: 14px;
  }

  .building-list,
  .switch-list {
    max-height: none;
    overflow: visible;
  }

  .district-panel {
    min-height: 0;
  }

  .district-map {
    min-height: 440px;
  }

  .switch-panel {
    padding-bottom: calc(210px + env(safe-area-inset-bottom));
  }

  .switch-list {
    display: grid;
    grid-template-columns: 1fr;
  }

  .command-bar {
    bottom: 8px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    padding: 8px;
    background: rgba(7, 13, 25, .94);
    backdrop-filter: blur(16px);
  }

  .command-helper,
  #undo-button,
  #apply-button,
  #finalize-button {
    grid-column: 1 / -1;
  }

  #apply-button,
  #finalize-button {
    min-height: 58px;
  }

  .apply-btn:not(:disabled)::after {
    right: 10px;
  }
}

@media (max-width: 520px) {
  .app {
    padding: 10px;
  }

  .topbar h1 {
    font-size: 22px;
  }

  .district-head {
    display: grid;
  }

  .turn-box {
    width: 100%;
  }

  .objective-strip {
    gap: 6px;
  }

  .district-map {
    min-height: 390px;
  }

  .map-building {
    width: 90px;
    min-width: 86px;
    min-height: 78px;
    padding: 7px;
  }

  .map-building strong {
    max-width: 76px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .substation {
    width: 104px;
    height: 104px;
  }

  .substation-core {
    width: 46px;
    height: 46px;
  }

  .stat-chip {
    min-height: 40px;
  }
}
