/* Mobile Portrait First + PC 9:16 Centered Frame */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0b0e13;
  color: #f3f5f8;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
}

#pc-backdrop {
  width: 100vw;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, #18202c 0%, #090c10 100%);
}

#game-shell {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #141920;
}

/* On desktop / wide landscape screens, lock cleanly to a 9:16 portrait mobile frame */
@media (min-aspect-ratio: 3/4) {
  #game-shell {
    height: min(96dvh, 880px);
    aspect-ratio: 9 / 16;
    width: auto;
    border-radius: 26px;
    border: 2px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.72);
  }
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hidden {
  display: none !important;
}

/* ==================== TOP MINIMAL HUD ==================== */
#top-hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: max(10px, env(safe-area-inset-top)) 12px 8px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
  z-index: 10;
  background: linear-gradient(180deg, rgba(10, 14, 19, 0.82) 0%, rgba(10, 14, 19, 0) 100%);
}

.hud-left, .hud-right {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hud-right {
  align-items: flex-end;
}

.hp-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(15, 20, 28, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 5px 8px;
  border-radius: 10px;
}

.hud-tag {
  font-size: 11px;
  font-weight: 800;
  color: #8ee09e;
  letter-spacing: 0.4px;
}

.bar-track {
  width: 84px;
  height: 9px;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 99px;
  overflow: hidden;
}

.bar-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #56d97e, #8ef0a8);
  border-radius: 99px;
  transition: width 0.12s ease-out, background 0.2s;
}

.bar-fill.low {
  background: linear-gradient(90deg, #f25555, #ff8b6b);
}

.hud-num {
  font-size: 12px;
  font-weight: 800;
  min-width: 24px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.pill-btn {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(18, 24, 33, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #f3f5f8;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 10px;
  cursor: pointer;
}

.pill-btn:active {
  transform: scale(0.96);
  background: rgba(38, 49, 66, 0.95);
}

.ammo-badge {
  color: #ffd369;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.timer-box {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(15, 20, 28, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 5px 10px;
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
}

.timer-label {
  font-size: 10px;
  font-weight: 700;
  color: #88d6a6;
}

#raid-timer {
  font-size: 13px;
  font-weight: 800;
}

.hud-mini-btns {
  display: flex;
  align-items: center;
  gap: 6px;
}

.gold-text {
  color: #ffd369;
  font-weight: 800;
}

.icon-mini-btn {
  pointer-events: auto;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(18, 24, 33, 0.86);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}

/* ==================== BANNERS ==================== */
#toast-banner {
  position: absolute;
  top: 96px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(17, 23, 32, 0.9);
  border: 1px solid rgba(255, 211, 105, 0.45);
  color: #fff7dc;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 99px;
  white-space: nowrap;
  z-index: 12;
  pointer-events: none;
}

#extract-banner {
  position: absolute;
  top: 128px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(12, 42, 27, 0.92);
  border: 2px solid #59e38a;
  border-radius: 14px;
  padding: 8px 18px;
  text-align: center;
  z-index: 12;
  pointer-events: none;
  box-shadow: 0 0 24px rgba(89, 227, 138, 0.35);
}

.extract-title {
  font-size: 11px;
  font-weight: 800;
  color: #9bf5b9;
}

.extract-sec {
  font-size: 24px;
  font-weight: 900;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
}

/* ==================== TOUCH CONTROLS ==================== */
#controls-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 8;
}

.stick-zone {
  position: absolute;
  bottom: 0;
  height: 44%;
  width: 50%;
  pointer-events: auto;
}

#left-stick-zone {
  left: 0;
}

#right-stick-zone {
  right: 0;
}

#action-cluster {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(14px, env(safe-area-inset-bottom));
  pointer-events: none;
  height: 220px;
}

.act-btn {
  pointer-events: auto;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 16px;
  border: 1.5px solid rgba(255, 255, 255, 0.22);
  background: rgba(18, 25, 35, 0.78);
  color: #f3f5f8;
  font-weight: 800;
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: transform 0.08s ease, border-color 0.15s, background 0.15s;
}

.act-btn:active {
  transform: scale(0.93);
}

.act-icon {
  font-size: 17px;
  line-height: 1;
}

.act-label {
  font-size: 10px;
  letter-spacing: -0.2px;
}

/* Fire Toggle sits right above the right thumb stick */
.fire-toggle {
  position: absolute;
  right: 14px;
  bottom: 166px;
  width: 78px;
  height: 52px;
  border-radius: 16px;
  border-color: rgba(255, 198, 92, 0.45);
}

.fire-toggle.active {
  background: rgba(217, 68, 49, 0.9);
  border-color: #ffd369;
  box-shadow: 0 0 18px rgba(235, 86, 62, 0.55);
}

/* Contextual Loot button sits centered above thumb area */
.interact-btn {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 168px;
  min-width: 118px;
  height: 46px;
  flex-direction: row;
  gap: 6px;
  padding: 0 14px;
  border-radius: 99px;
  background: rgba(246, 194, 68, 0.95);
  border-color: #fff3c2;
  color: #1a1610;
  box-shadow: 0 6px 20px rgba(246, 194, 68, 0.4);
}

.interact-btn .act-label {
  font-size: 13px;
}

.interact-btn:active {
  transform: translateX(-50%) scale(0.95);
}

.sub-actions {
  position: absolute;
  left: 14px;
  bottom: 166px;
  display: flex;
  gap: 8px;
  pointer-events: none;
}

.sm-btn {
  width: 54px;
  height: 52px;
  border-radius: 14px;
}

.cd-overlay {
  position: absolute;
  inset: 0;
  border-radius: 13px;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 900;
  color: #ffd369;
}

/* ==================== LOOT & BAG MODAL SHEET ==================== */
.modal-sheet {
  position: absolute;
  inset: 0;
  background: rgba(7, 10, 14, 0.52);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 25;
  padding: 12px;
}

.sheet-card {
  width: 100%;
  background: #171e28;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 20px;
  padding: 14px;
  box-shadow: 0 -10px 36px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sheet-header h3 {
  font-size: 15px;
  font-weight: 800;
}

.close-btn {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 9px;
  cursor: pointer;
}

.slot-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-sub {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  color: #b7c3d4;
}

.hint-text {
  color: #8ee09e;
  font-size: 11px;
}

.slot-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.slot-tile {
  min-height: 68px;
  background: rgba(11, 16, 22, 0.85);
  border: 1.5px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 7px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-align: center;
  cursor: pointer;
}

.slot-tile.empty {
  border-style: dashed;
  border-color: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.22);
  font-size: 11px;
  cursor: default;
}

.slot-tile.rarity-rare {
  border-color: #63b3ff;
  background: rgba(31, 63, 102, 0.35);
}

.slot-tile.rarity-epic {
  border-color: #ffd369;
  background: rgba(115, 88, 22, 0.32);
}

.slot-tile:not(.empty):active {
  transform: scale(0.95);
}

.slot-emoji {
  font-size: 20px;
  line-height: 1;
}

.slot-name {
  font-size: 11px;
  font-weight: 700;
  color: #f3f5f8;
  line-height: 1.15;
}

.slot-meta {
  font-size: 10px;
  color: #ffd369;
  font-weight: 700;
}

.sheet-tip {
  font-size: 11px;
  color: #8a97aa;
  text-align: center;
}

/* ==================== START & RESULT OVERLAYS ==================== */
.full-overlay {
  position: absolute;
  inset: 0;
  background: rgba(9, 12, 17, 0.86);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 30;
}

.overlay-card {
  width: 100%;
  max-width: 340px;
  background: #171e28;
  border: 1.5px solid rgba(255, 255, 255, 0.14);
  border-radius: 24px;
  padding: 22px 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}

.badge-pill {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.8px;
  padding: 4px 10px;
  border-radius: 99px;
  background: rgba(255, 211, 105, 0.16);
  color: #ffd369;
  border: 1px solid rgba(255, 211, 105, 0.35);
}

.badge-pill.kia {
  background: rgba(235, 86, 62, 0.18);
  color: #ff8c7a;
  border-color: rgba(235, 86, 62, 0.45);
}

.badge-pill.ok {
  background: rgba(89, 227, 138, 0.18);
  color: #7df2a5;
  border-color: rgba(89, 227, 138, 0.45);
}

.game-title {
  font-size: 30px;
  font-weight: 900;
  letter-spacing: -0.6px;
  color: #ffffff;
}

.game-sub {
  font-size: 13px;
  color: #b7c3d4;
  line-height: 1.45;
}

.portrait-preview {
  width: 108px;
  height: 108px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #2a3648 0%, #131922 100%);
  border: 2px solid rgba(255, 255, 255, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#preview-canvas {
  width: 108px;
  height: 108px;
}

.rule-list {
  width: 100%;
  text-align: left;
  list-style: none;
  background: rgba(10, 14, 20, 0.7);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: #d0dae8;
}

.rule-list strong {
  color: #ffd369;
}

.primary-cta {
  width: 100%;
  padding: 14px 18px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffd369 0%, #f0ad38 100%);
  color: #1a150e;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(240, 173, 56, 0.35);
}

.primary-cta:active {
  transform: scale(0.97);
}

.pc-hint {
  font-size: 10.5px;
  color: #7c899c;
  line-height: 1.4;
}

.result-title {
  font-size: 26px;
  font-weight: 900;
}

.result-quote {
  font-size: 13px;
  color: #c8d3e3;
  font-style: italic;
}

.result-stats {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-item {
  background: rgba(10, 14, 20, 0.72);
  border-radius: 12px;
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat-k {
  font-size: 10px;
  color: #8b99ad;
}

.stat-v {
  font-size: 14px;
  font-weight: 900;
}

.res-loot-list {
  width: 100%;
  max-height: 112px;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.loot-chip {
  font-size: 11px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 4px 8px;
  border-radius: 8px;
}

.loot-chip.lost {
  text-decoration: line-through;
  color: #ff8c7a;
  border-color: rgba(255, 140, 122, 0.3);
}
