/* Sunny Mahjong — Joyful Storybook Pastel UI (100% Kid-Safe, Zero Overflow) */

:root {
  --sky-top: #7ED6FF;
  --sky-mid: #BEEBFF;
  --meadow-low: #E9FBC8;
  --cream: #FFFDF5;
  --ink: #3D271C;
  --ink-soft: #6B4F3B;
  --sun: #FFD43B;
  --sun-deep: #F0A500;
  --coral: #FF707A;
  --mint: #53D487;
  --lavender: #A986FF;
  --shadow: rgba(61, 39, 28, 0.16);
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  font-family: 'Fredoka', 'Nunito', 'Rounded Mplus 1c', ui-rounded, 'Hiragino Maru Gothic ProN', system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 58%, var(--meadow-low) 100%);
  user-select: none;
  -webkit-user-select: none;
}

body {
  position: fixed;
  inset: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

/* Soft storybook drifting clouds in the background */
.sky-clouds {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.cloud {
  position: absolute;
  background: rgba(255, 255, 255, 0.65);
  border-radius: 999px;
  filter: blur(0.5px);
}

.cloud::before,
.cloud::after {
  content: '';
  position: absolute;
  background: inherit;
  border-radius: 50%;
}

.cloud-1 { width: 130px; height: 42px; top: 8%; left: 6%; opacity: 0.72; }
.cloud-1::before { width: 58px; height: 58px; top: -24px; left: 20px; }
.cloud-1::after { width: 44px; height: 44px; top: -16px; left: 62px; }

.cloud-2 { width: 160px; height: 48px; top: 14%; right: 7%; opacity: 0.62; }
.cloud-2::before { width: 66px; height: 66px; top: -28px; left: 28px; }
.cloud-2::after { width: 52px; height: 52px; top: -18px; left: 78px; }

.cloud-3 { width: 110px; height: 34px; bottom: 18%; left: 12%; opacity: 0.45; }
.cloud-3::before { width: 48px; height: 48px; top: -20px; left: 16px; }
.cloud-3::after { width: 38px; height: 38px; top: -14px; left: 50px; }

/* App Shell — Locked strictly to the exact visible PWA viewport */
.app-shell {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1100px;
  height: var(--app-height, 100%);
  max-height: 100%;
  margin: 0 auto;
  overflow: hidden;
  padding: calc(10px + env(safe-area-inset-top, 0px)) calc(14px + env(safe-area-inset-right, 0px)) calc(14px + env(safe-area-inset-bottom, 0px)) calc(14px + env(safe-area-inset-left, 0px));
  gap: 8px;
}

/* Header */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex: 0 0 auto;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.app-title {
  margin: 0;
  font-size: clamp(1.15rem, 3.2vw, 1.65rem);
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.85);
}

.header-pills {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}

.stat-pill,
.icon-pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 40px;
  padding: 0 12px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--cream);
  border: 2.5px solid #E9D3AD;
  box-shadow: 0 3px 0 #D6BA8C;
}

.icon-pill-btn {
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}

.icon-pill-btn:hover {
  transform: translateY(-1px);
}

.icon-pill-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #D6BA8C;
}

.sticker-btn {
  background: #FFF4BF;
  border-color: #F2BC38;
  box-shadow: 0 3px 0 #D99B16;
}

.install-btn {
  width: 42px;
  padding: 0;
  font-size: 1.1rem;
  background: #E8FCEB;
  border-color: #7ED99A;
  box-shadow: 0 3px 0 #55BA76;
}

.install-btn[hidden] {
  display: none;
}

.mute-btn {
  width: 42px;
  padding: 0;
  font-size: 1.15rem;
}

/* Tier & Board Picker Bar */
.mode-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 7px;
  flex: 0 0 auto;
}

.tier-group {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 253, 245, 0.65);
  padding: 4px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.85);
}

.tier-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 38px;
  padding: 0 13px;
  border: none;
  border-radius: 999px;
  background: transparent;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink-soft);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, color 0.15s ease;
}

.tier-pill:hover {
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
}

.tier-pill.active {
  background: #FFD84D;
  color: var(--ink);
  box-shadow: 0 3px 0 #E0A116;
}

.shape-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 2.5px solid #B7E59F;
  background: #F4FFE9;
  font-family: inherit;
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 3px 0 #8FC972;
  transition: transform 0.12s ease;
}

.shape-btn:hover {
  transform: translateY(-1px);
  background: #FFFFFF;
}

.shape-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #8FC972;
}

.shape-cycle {
  font-size: 0.88rem;
  opacity: 0.75;
}

/* Main Playfield Stage */
.stage-wrap {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  background: rgba(255, 253, 245, 0.44);
  border: 3px solid rgba(255, 255, 255, 0.75);
  border-radius: 26px;
  box-shadow: inset 0 4px 18px rgba(74, 148, 196, 0.12), 0 8px 24px rgba(61, 39, 28, 0.08);
  overflow: hidden;
}

#board-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  cursor: pointer;
}

/* Floating Magic Shuffle Banner */
.magic-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  padding: 14px 26px;
  border-radius: 999px;
  background: linear-gradient(135deg, #FFE45C 0%, #FFB84D 100%);
  border: 4px solid #FFFFFF;
  box-shadow: 0 12px 30px rgba(61, 39, 28, 0.25);
  font-size: clamp(1.15rem, 3.5vw, 1.6rem);
  font-weight: 700;
  color: var(--ink);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 10;
  white-space: nowrap;
}

.magic-banner.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* Bottom Tactile Kid Action Bar */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: 0 0 auto;
  padding-bottom: 5px;
}

.kid-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 50px;
  padding: 0 18px;
  border-radius: 20px;
  border: 3px solid #FFFFFF;
  font-family: inherit;
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.15s ease;
}

.kid-btn:hover:not(:disabled) {
  transform: translateY(-2px);
}

.kid-btn:active:not(:disabled) {
  transform: translateY(3px);
}

.kid-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-hint {
  background: #FFE054;
  box-shadow: 0 5px 0 #DBA112;
}
.btn-hint:active:not(:disabled) { box-shadow: 0 2px 0 #DBA112; }

.btn-undo {
  background: #BAE8FF;
  box-shadow: 0 5px 0 #5BAEE0;
}
.btn-undo:active:not(:disabled) { box-shadow: 0 2px 0 #5BAEE0; }

.btn-shuffle {
  background: #E5D4FF;
  box-shadow: 0 5px 0 #9D76E8;
}
.btn-shuffle:active:not(:disabled) { box-shadow: 0 2px 0 #9D76E8; }

.btn-new {
  background: #C6F7C0;
  box-shadow: 0 5px 0 #62C265;
}
.btn-new:active:not(:disabled) { box-shadow: 0 2px 0 #62C265; }

/* Modals (Celebration & Sticker Book) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(45, 76, 114, 0.48);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 40;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.modal-backdrop.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

#celebration-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 41;
  pointer-events: none;
}

.modal-backdrop.open #celebration-canvas {
  pointer-events: auto;
}

.modal-card {
  position: relative;
  z-index: 42;
  width: 100%;
  max-width: 440px;
  max-height: 94%;
  overflow-y: auto;
  background: var(--cream);
  border: 5px solid #FFE066;
  border-radius: 32px;
  padding: 24px 22px 22px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(45, 32, 20, 0.3);
  transform: scale(0.88);
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

.modal-backdrop.open .modal-card {
  transform: scale(1);
  pointer-events: auto;
}

.win-badge {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 999px;
  background: #FFF1B3;
  color: #A86B00;
  font-size: 0.92rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.win-title {
  margin: 4px 0 8px;
  font-size: clamp(1.6rem, 5vw, 2.1rem);
  color: var(--ink);
}

.win-sub {
  margin: 0 0 14px;
  font-size: 1rem;
  color: var(--ink-soft);
}

.sticker-showcase {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #FFFDF5 0%, #FFF3C4 100%);
  border: 4px solid #F7C744;
  border-radius: 26px;
  padding: 12px 22px;
  margin: 4px auto 16px;
  box-shadow: 0 8px 20px rgba(240, 165, 0, 0.22);
  animation: stickerBob 2.2s ease-in-out infinite;
}

@keyframes stickerBob {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50% { transform: translateY(-6px) rotate(1.5deg); }
}

.sticker-showcase canvas {
  width: 108px;
  height: 108px;
  display: block;
}

.sticker-earned-name {
  margin-top: 6px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.win-tip {
  margin-top: 12px;
  font-size: 0.88rem;
  color: var(--ink-soft);
  opacity: 0.9;
}

/* Sticker Book Modal */
.stickerbook-card {
  max-width: 600px;
  max-height: 88%;
  display: flex;
  flex-direction: column;
  border-color: #9EE3FF;
}

.sb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.sb-title-wrap {
  text-align: left;
}

.sb-title {
  margin: 0;
  font-size: 1.45rem;
}

.sb-stats {
  font-size: 0.92rem;
  color: var(--ink-soft);
  font-weight: 600;
}

.close-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2.5px solid #E5D2B5;
  background: #FFF6E0;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 3px 0 #D6BC92;
}

.close-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #D6BC92;
}

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  gap: 10px;
  overflow-y: auto;
  padding: 4px 2px 8px;
}

.sticker-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 6px 7px;
  border-radius: 18px;
  background: #FFFDF8;
  border: 2.5px solid #F0DFC2;
  transition: transform 0.15s ease;
}

.sticker-slot.unlocked {
  cursor: pointer;
  border-color: #F7C744;
  box-shadow: 0 4px 0 #E5B12A;
}

.sticker-slot.unlocked:hover {
  transform: translateY(-2px) scale(1.03);
}

.sticker-slot.unlocked:active {
  transform: scale(0.95);
}

.sticker-slot.locked {
  background: #F4F0E8;
  border-style: dashed;
  border-color: #D9CBB6;
}

.sticker-slot canvas {
  width: 62px;
  height: 62px;
  display: block;
}

.sticker-slot-name {
  margin-top: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink);
  text-align: center;
  line-height: 1.15;
}

.sticker-slot.locked .sticker-slot-name {
  color: #9A8876;
}

/* Mobile Responsive Tweaks (390px and narrow screens) */
@media (max-width: 560px) {
  .app-shell {
    padding: calc(8px + env(safe-area-inset-top, 0px)) calc(8px + env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) calc(8px + env(safe-area-inset-left, 0px));
    gap: 6px;
  }

  .app-title {
    font-size: 1.08rem;
  }

  .stat-pill,
  .icon-pill-btn {
    height: 36px;
    padding: 0 9px;
    font-size: 0.86rem;
  }

  .install-btn,
  .mute-btn {
    width: 36px;
    padding: 0;
  }

  .tier-pill {
    height: 34px;
    padding: 0 10px;
    font-size: 0.84rem;
  }

  .shape-btn {
    height: 36px;
    padding: 0 11px;
    font-size: 0.84rem;
  }

  .action-bar {
    gap: 6px;
  }

  .kid-btn {
    min-height: 46px;
    padding: 0 11px;
    font-size: 0.88rem;
    gap: 4px;
    border-radius: 16px;
    flex: 1 1 0;
  }

  .stage-wrap {
    border-radius: 20px;
  }

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

/* Shorter Landscape Tablet & Split-Screen Responsive Tweaks */
@media (max-height: 760px) {
  .app-shell {
    padding: calc(6px + env(safe-area-inset-top, 0px)) calc(12px + env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) calc(12px + env(safe-area-inset-left, 0px));
    gap: 6px;
  }

  .stat-pill,
  .icon-pill-btn {
    height: 36px;
    font-size: 0.92rem;
  }

  .install-btn,
  .mute-btn {
    width: 38px;
  }

  .tier-pill {
    height: 34px;
    padding: 0 11px;
    font-size: 0.9rem;
  }

  .shape-btn {
    height: 36px;
    padding: 0 12px;
    font-size: 0.9rem;
  }

  .kid-btn {
    min-height: 44px;
    padding: 0 16px;
    font-size: 0.96rem;
    border-radius: 18px;
  }
}

@media (max-height: 540px) {
  .app-shell {
    padding: calc(4px + env(safe-area-inset-top, 0px)) calc(10px + env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) calc(10px + env(safe-area-inset-left, 0px));
    gap: 4px;
  }

  .kid-btn {
    min-height: 40px;
    padding: 0 12px;
    font-size: 0.9rem;
  }
}
