/* Pirate King — mobile-first portrait slot (icons never clip) */
.game-shell.pk-mode {
  --pk-wood: #3a2414;
  --pk-gold: #f0d060;
  --pk-red: #e23b3b;
  height: 100%;
  min-height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}
.game-shell.pk-mode .game-top {
  display: none !important;
}
.game-shell.pk-mode .game-stage {
  position: relative;
  height: 100%;
  min-height: 0;
  max-height: 100dvh;
  overflow: hidden;
  background: #0a1528;
}

.pk-screen {
  position: relative;
  width: 100%;
  height: 100%;
  max-height: 100dvh;
  color: #fff;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  overflow: hidden;
  box-sizing: border-box;
}
.pk-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}
.pk-veil {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(
    180deg,
    rgba(8, 20, 40, 0.12) 0%,
    rgba(8, 12, 24, 0.45) 50%,
    rgba(6, 8, 16, 0.92) 100%
  );
  pointer-events: none;
}

/* Main layout: top / hero / banner / reels / foot — reels get remaining space */
.pk-ui {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  height: 100%;
  max-height: 100dvh;
  min-height: 0;
  padding:
    max(4px, env(safe-area-inset-top, 0px))
    max(6px, env(safe-area-inset-right, 0px))
    max(4px, env(safe-area-inset-bottom, 0px))
    max(6px, env(safe-area-inset-left, 0px));
  box-sizing: border-box;
  gap: 4px;
}

.pk-top {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 40px;
  align-items: start;
  gap: 4px;
  flex-shrink: 0;
  min-height: 0;
}
.pk-ico {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 9px;
  padding: 0;
  background: transparent;
  cursor: pointer;
  overflow: hidden;
}
.pk-ico img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: transparent !important;
}
.pk-logo {
  display: block;
  width: min(240px, 58vw);
  max-height: 56px;
  height: auto;
  margin: 0 auto;
  object-fit: contain;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.45));
  background: transparent !important;
}
.pk-top-r {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
.pk-piggy {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  border: none;
  background: transparent;
  color: #ffe9a0;
  font-size: 0.48rem;
  font-weight: 800;
  cursor: pointer;
  padding: 0;
  line-height: 1.1;
}
.pk-piggy img {
  width: 30px;
  height: 30px;
  object-fit: contain;
  border-radius: 50%;
  border: 1.5px solid #f0d060;
  background: transparent !important;
}

.pk-hero {
  position: relative;
  height: clamp(72px, 14vh, 130px);
  min-height: 72px;
  max-height: 130px;
  display: grid;
  place-items: end center;
  overflow: hidden;
}
.pk-pirate {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  height: 108%;
  width: auto;
  max-width: min(58vw, 220px);
  object-fit: contain;
  bottom: -6%;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.5));
  background: transparent !important;
  pointer-events: none;
}
.pk-wheel-wrap {
  position: relative;
  width: clamp(78px, 20vw, 120px);
  height: clamp(78px, 20vw, 120px);
  z-index: 2;
  margin-bottom: 2px;
}
.pk-wheel {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform 2s cubic-bezier(0.15, 0.8, 0.2, 1);
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.5));
  background: transparent !important;
}
.pk-wheel-wrap.spinning .pk-wheel {
  transition-duration: 2.1s;
}
.pk-wheel-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.pk-wheel-labels span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 28px;
  margin-left: -14px;
  margin-top: -7px;
  text-align: center;
  font-size: clamp(0.45rem, 2.2vw, 0.58rem);
  font-weight: 900;
  color: #ffe566;
  text-shadow: 0 1px 2px #000;
  transform: rotate(var(--a)) translateY(-38%) rotate(calc(-1 * var(--a)));
  transform-origin: center;
}

.pk-banner {
  justify-self: center;
  width: min(300px, 88vw);
  margin: 0;
  padding: 5px 12px;
  text-align: center;
  font-weight: 900;
  font-size: clamp(0.75rem, 3.5vw, 0.95rem);
  letter-spacing: 0.03em;
  color: #fff8dc;
  background: linear-gradient(180deg, #6b4424, #3a2414);
  border: 2px solid #e0b040;
  border-radius: 8px;
  box-shadow: inset 0 1px 0 rgba(255, 220, 120, 0.35), 0 3px 10px rgba(0, 0, 0, 0.35);
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Reels — fill leftover height; square-ish cells; icons fully visible */
.pk-reels {
  position: relative;
  min-height: 0;
  height: 100%;
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: clamp(4px, 1.5vw, 8px);
  box-sizing: border-box;
  display: grid;
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: clamp(2px, 0.8vw, 5px);
  background: linear-gradient(180deg, #2a1810, #140c08);
  border: 3px solid #8a5a28;
  border-radius: 12px;
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.55), 0 6px 18px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}
.pk-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(2px, 0.8vw, 5px);
  min-height: 0;
  min-width: 0;
  height: 100%;
}
.pk-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.22);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(180, 120, 50, 0.18);
  padding: 2px;
  box-sizing: border-box;
}
.pk-cell img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
  background: transparent !important;
  pointer-events: none;
}
.pk-cell.win {
  box-shadow: inset 0 0 0 2px #3cf, 0 0 12px rgba(60, 220, 255, 0.5);
  animation: pk-pulse 0.7s ease infinite alternate;
  z-index: 1;
}
.pk-reels.is-spinning .pk-cell img {
  filter: blur(0.6px) brightness(1.08);
}
@keyframes pk-pulse {
  from { transform: scale(1); }
  to { transform: scale(1.03); }
}
.pk-lines {
  position: absolute;
  inset: clamp(4px, 1.5vw, 8px);
  width: auto;
  height: auto;
  pointer-events: none;
  z-index: 3;
}

.pk-foot {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-areas:
    "bal spin bet"
    "fast spin ."
    "meta meta meta";
  align-items: center;
  column-gap: 6px;
  row-gap: 2px;
  margin: 0;
  padding: 4px 4px 2px;
  background: linear-gradient(180deg, rgba(40, 24, 12, 0.95), rgba(16, 10, 6, 0.98));
  border-radius: 12px 12px 0 0;
  border-top: 2px solid #8a5a28;
  flex-shrink: 0;
  min-width: 0;
}
.pk-bal {
  grid-area: bal;
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 900;
  font-size: clamp(0.7rem, 3.2vw, 0.85rem);
  min-width: 0;
  overflow: hidden;
}
.pk-bal b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pk-g {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 30% 30%, #d070ff, #6a1ab0);
  font-size: 0.65rem;
  font-weight: 900;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.pk-fast {
  grid-area: fast;
  justify-self: start;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  border: none;
  background: transparent;
  color: #ffe566;
  font-size: 0.48rem;
  font-weight: 900;
  cursor: pointer;
  opacity: 0.75;
  padding: 0;
}
.pk-fast.on {
  opacity: 1;
  filter: drop-shadow(0 0 6px #ff0);
}
.pk-fast img {
  width: 26px;
  height: 26px;
  object-fit: contain;
  background: transparent !important;
}
.pk-spin {
  grid-area: spin;
  width: clamp(72px, 20vw, 96px);
  height: clamp(72px, 20vw, 96px);
  border-radius: 50%;
  border: 4px solid #c9a040;
  background: radial-gradient(circle at 35% 30%, #7dff7a, #1e9a2e 55%, #0d5a18);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 0 0 2px #5a3810, 0 6px 16px rgba(0, 0, 0, 0.45), inset 0 2px 6px rgba(255, 255, 255, 0.25);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.05;
  padding: 0;
  flex-shrink: 0;
}
.pk-spin strong {
  font-size: clamp(0.85rem, 4vw, 1.1rem);
  letter-spacing: 0.03em;
}
.pk-spin small {
  font-size: 0.38rem;
  opacity: 0.9;
  max-width: 64px;
  line-height: 1.15;
}
.pk-spin.stop {
  background: radial-gradient(circle at 35% 30%, #ff8a8a, #c02020 55%, #6a0a0a);
}
.pk-spin.auto {
  box-shadow: 0 0 0 2px #5a3810, 0 0 18px rgba(80, 255, 120, 0.7);
}
.pk-bet {
  grid-area: bet;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 3px;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 999px;
  padding: 3px 5px;
  border: 1px solid #8a5a28;
  min-width: 0;
}
.pk-bet b {
  min-width: 36px;
  text-align: center;
  font-size: clamp(0.8rem, 3.5vw, 0.95rem);
}
.pk-bet button {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(180deg, #4aa0ff, #1a5ab0);
  color: #fff;
  font-weight: 900;
  font-size: 0.95rem;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  line-height: 1;
}
.pk-meta {
  grid-area: meta;
  display: flex;
  justify-content: space-between;
  font-size: 0.58rem;
  opacity: 0.85;
  padding: 0 2px;
}
.pk-ping {
  color: #6dff8a;
}

.pk-modal {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 10px;
  background: rgba(4, 8, 16, 0.72);
  overflow: auto;
}
.pk-card {
  width: min(420px, 96vw);
  max-height: min(78dvh, 100%);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: linear-gradient(180deg, #f3e2c0, #d8b878);
  color: #2a1808;
  border: 4px solid #6b3e18;
  border-radius: 14px;
  padding: 10px 12px 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  box-sizing: border-box;
}
.pk-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  background: linear-gradient(180deg, #8b4518, #5a2c0c);
  color: #ffe566;
  border-radius: 8px;
  padding: 8px 10px;
  position: sticky;
  top: 0;
  z-index: 1;
}
.pk-card-head h3 {
  margin: 0;
  flex: 1;
  font-size: 1.05rem;
}
.pk-card-head small {
  opacity: 0.7;
  font-size: 0.65rem;
}
.pk-card-head button {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: #e23b3b;
  color: #fff;
  font-weight: 900;
  cursor: pointer;
  flex-shrink: 0;
}
.pk-paytable {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}
.pk-pay-row {
  display: flex;
  gap: 6px;
  align-items: center;
  background: rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  padding: 4px;
  font-size: 0.65rem;
  min-width: 0;
}
.pk-pay-row img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  flex-shrink: 0;
  background: transparent !important;
}
.pk-pay-row div {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.pk-rule-block {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: 8px 0;
  font-size: 0.72rem;
  line-height: 1.35;
}
.pk-rule-block img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  flex-shrink: 0;
  background: transparent !important;
}
.pk-lines-grid h4 {
  margin: 8px 0 6px;
  font-size: 0.85rem;
}
.pk-pl-wrap {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}
.pk-pl {
  background: rgba(255, 255, 255, 0.4);
  border-radius: 6px;
  padding: 3px;
  text-align: center;
  min-width: 0;
}
.pk-pl em {
  font-size: 0.55rem;
  font-style: normal;
  font-weight: 900;
}
.pk-pl-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1px;
}
.pk-pl-grid i {
  aspect-ratio: 1;
  background: #6a90c8;
  border-radius: 1px;
}
.pk-pl-grid i.on {
  background: #f5d030;
}

.pk-stats-table {
  font-size: 0.72rem;
}
.pk-st {
  display: grid;
  grid-template-columns: 1.6fr 0.7fr 0.7fr;
  gap: 6px;
  padding: 6px 2px;
  border-bottom: 1px solid rgba(80, 50, 20, 0.25);
  align-items: center;
}
.pk-st.head {
  font-weight: 900;
  color: #6b3e18;
}
.pk-st.empty {
  display: block;
  text-align: center;
  padding: 16px;
}

.pk-jackpot-toast {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 22px;
  border-radius: 16px;
  background: linear-gradient(180deg, #ffe566, #e0a020);
  color: #5a2200;
  font-weight: 900;
  box-shadow: 0 12px 40px rgba(255, 180, 0, 0.55);
  animation: pk-jp 0.5s ease both;
  max-width: 90vw;
}
.pk-jackpot-toast strong {
  font-size: clamp(1.1rem, 5vw, 1.4rem);
  letter-spacing: 0.08em;
}
.pk-jackpot-toast span {
  font-size: clamp(0.95rem, 4vw, 1.1rem);
}
@keyframes pk-jp {
  from { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* Short phones — shrink chrome, protect reels */
@media (max-height: 720px) {
  .pk-logo {
    max-height: 44px;
    width: min(200px, 52vw);
  }
  .pk-hero {
    height: clamp(64px, 12vh, 100px);
    min-height: 64px;
  }
  .pk-wheel-wrap {
    width: clamp(68px, 18vw, 96px);
    height: clamp(68px, 18vw, 96px);
  }
  .pk-spin {
    width: clamp(64px, 18vw, 84px);
    height: clamp(64px, 18vw, 84px);
  }
}

@media (max-height: 600px) {
  .pk-hero {
    height: 56px;
    min-height: 56px;
  }
  .pk-pirate {
    max-width: 42vw;
    opacity: 0.95;
  }
  .pk-banner {
    padding: 3px 10px;
    font-size: 0.72rem;
  }
  .pk-piggy span {
    display: none;
  }
}

@media (max-width: 380px) {
  .pk-paytable {
    grid-template-columns: 1fr;
  }
  .pk-pl-wrap {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .pk-ui {
    gap: 3px;
    padding-left: 4px;
    padding-right: 4px;
  }
  .pk-reels {
    padding: 4px;
    gap: 2px;
    border-width: 2px;
  }
  .pk-row {
    gap: 2px;
  }
}

/* Landscape phones — keep playable */
@media (orientation: landscape) and (max-height: 480px) {
  .pk-ui {
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "top top"
      "side reels"
      "foot foot";
  }
  .pk-top { grid-area: top; }
  .pk-hero,
  .pk-banner {
    grid-area: side;
  }
  .pk-hero {
    height: auto;
    max-height: none;
    align-self: end;
  }
  .pk-banner {
    align-self: start;
  }
  .pk-reels { grid-area: reels; }
  .pk-foot { grid-area: foot; }
}

