@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&display=swap');

:root {
  /* Penguin skin variables (updated dynamically by JS) */
  --p-body-light: #3b4b63;
  --p-body-mid: #1d283a;
  --p-body-dark: #0e1522;
  --p-belly-light: #ffffff;
  --p-belly-dark: #dbe8f4;
  --p-beak-light: #ffb703;
  --p-beak-dark: #fb8500;
  --p-accent: #ffd166;

  /* Arctic theme */
  --bg1: #e4f7ff;
  --bg2: #89cff0;
  --bg3: #4ea8de;
  --panel: rgba(246, 252, 255, 0.88);
  --ink: #173047;
  --accent: #0096c7;
  --accent-dark: #02678f;
  --warm: #ff8c24;
  --good: #2c9e52;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: 'Fredoka', 'Segoe UI', sans-serif;
  color: var(--ink);
  background: radial-gradient(ellipse at 50% 35%, var(--bg1) 0%, var(--bg2) 55%, var(--bg3) 100%);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

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

.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 280px 1fr 360px;
  height: 100vh;
  gap: 16px;
  padding: 16px;
}

.panel {
  background: var(--panel);
  border-radius: 20px;
  box-shadow: 0 8px 30px rgba(10, 55, 95, 0.18);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.7);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel h2 {
  font-size: 1.15rem;
  padding: 14px 18px 10px;
  border-bottom: 2px dashed rgba(23, 48, 71, 0.14);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.scroll {
  overflow-y: auto;
  flex: 1;
  padding: 12px;
}
.scroll::-webkit-scrollbar { width: 8px; }
.scroll::-webkit-scrollbar-thumb {
  background: rgba(23, 48, 71, 0.22);
  border-radius: 8px;
}

/* ---------- Left: Stats & Achievements ---------- */
.stat {
  display: flex;
  justify-content: space-between;
  padding: 6px 4px;
  font-size: .95rem;
  border-bottom: 1px solid rgba(23, 48, 71, .07);
}
.stat span:last-child { font-weight: 600; }

.section-title {
  font-weight: 700;
  margin: 14px 4px 6px;
  font-size: .9rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  opacity: .7;
}

.achievements {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.ach {
  aspect-ratio: 1;
  border-radius: 10px;
  background: rgba(23, 48, 71, .08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  filter: grayscale(1) opacity(.35);
  position: relative;
  cursor: help;
  transition: transform .12s;
}
.ach.got {
  filter: none;
  background: linear-gradient(135deg, #e0f7ff, #90e0ef);
  box-shadow: 0 2px 6px rgba(0, 120, 180, .3);
}
.ach.got:hover { transform: scale(1.08); }

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  border-top: 2px dashed rgba(23, 48, 71, .14);
}
.btn {
  flex: 1;
  font-family: inherit;
  font-size: .85rem;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 2px 0 rgba(23, 48, 71, .18);
  transition: transform .08s, filter .12s;
}
.btn:hover { filter: brightness(1.03); }
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: #ffd9d6; color: #a33; }
.btn.on { flex-basis: 100%; order: 5; background: #d6f5e3; color: #165e32; }

.auth-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 0;
  border-top: 2px dashed rgba(23, 48, 71, .14);
}
.auth-info {
  flex: 1;
  font-size: .8rem;
  opacity: .75;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.auth-row .btn { flex: 0 0 auto; padding: 8px 10px; }

.xfer-row { padding: 8px 12px 0; }
.xfer-row .btn { width: 100%; }
.xfer-row + .btn-row { border-top: none; }

/* ---------- Center: Penguin Stage ---------- */
.center {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.counter {
  text-align: center;
  z-index: 2;
  margin-bottom: 10px;
}
.counter .penguins {
  font-size: clamp(2rem, 5vw, 3.4rem);
  font-weight: 700;
  text-shadow: 0 3px 0 rgba(255, 255, 255, .75);
  line-height: 1.1;
}
.counter .pps { font-size: 1.05rem; opacity: .85; font-weight: 500; }
.counter .perclick { font-size: .9rem; opacity: .65; }

.buffs {
  display: flex;
  gap: 8px;
  min-height: 30px;
  margin-bottom: 4px;
  z-index: 2;
  flex-wrap: wrap;
  justify-content: center;
}
.buff {
  background: linear-gradient(135deg, #ffe066, #ff9f1c);
  color: #5e3100;
  font-weight: 700;
  font-size: .85rem;
  padding: 4px 12px;
  border-radius: 99px;
  box-shadow: 0 2px 10px rgba(255, 160, 0, .5);
  animation: pulse 1s infinite alternate;
}
@keyframes pulse { to { transform: scale(1.06); } }

.penguin-stage {
  position: relative;
  width: 340px;
  height: 370px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rays {
  position: absolute;
  width: 620px;
  height: 620px;
  border-radius: 50%;
  background: repeating-conic-gradient(rgba(255, 255, 255, .38) 0 10deg, transparent 10deg 20deg);
  mask-image: radial-gradient(circle, #000 20%, transparent 68%);
  -webkit-mask-image: radial-gradient(circle, #000 20%, transparent 68%);
  animation: spin 45s linear infinite;
  pointer-events: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Floating Ice Floe */
.ice-floe {
  position: absolute;
  bottom: 14px;
  width: 300px;
  height: 76px;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 25%, #ffffff 0%, #d4f1ff 52%, #72c4e8 100%);
  box-shadow:
    inset 0 -10px 16px rgba(10, 90, 140, .28),
    0 12px 24px rgba(10, 65, 110, .28),
    0 6px 0 #5eb2da;
}
.ice-shine {
  position: absolute;
  top: 12px;
  left: 38px;
  width: 110px;
  height: 18px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .85);
  transform: rotate(-5deg);
}

.penguin-wrap {
  position: relative;
  z-index: 2;
  margin-bottom: 32px;
  animation: waddle 3.2s ease-in-out infinite;
}
@keyframes waddle {
  0%, 100% { transform: rotate(-2.5deg) translateY(0); }
  50% { transform: rotate(2.5deg) translateY(-4px); }
}

.penguin {
  width: 235px;
  height: 274px;
  cursor: pointer;
  position: relative;
  transition: transform .1s ease, filter .2s;
  touch-action: manipulation;
  outline: none;
}
.penguin:hover { transform: scale(1.04); filter: brightness(1.04); }

.penguin-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.penguin .flipper-left { transform-origin: 58px 145px; transition: transform .1s ease; }
.penguin .flipper-right { transform-origin: 182px 145px; transition: transform .1s ease; }

.penguin.squish { animation: squish .15s ease; }
.penguin.squish .flipper-left { animation: flapLeft .18s ease; }
.penguin.squish .flipper-right { animation: flapRight .18s ease; }

@keyframes squish {
  0% { transform: scale(1.04); }
  50% { transform: scale(1.08, .88) translateY(8px); }
  100% { transform: scale(1.04); }
}
@keyframes flapLeft {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(26deg); }
}
@keyframes flapRight {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-26deg); }
}

.penguin.celebrate { animation: bellySpin .65s ease-in-out; }
@keyframes bellySpin {
  0% { transform: scale(1) rotate(0deg); }
  30% { transform: scale(1.12, .9) translateY(-18px) rotate(-14deg); }
  65% { transform: scale(1.05) translateY(-10px) rotate(14deg); }
  100% { transform: scale(1) rotate(0deg); }
}

/* Skin accessories visibility */
.acc-crests, .acc-crown, .acc-stars {
  opacity: 0;
  transition: opacity .25s ease;
}
body.skin-macaroni .acc-crests { opacity: 1; }
body.skin-royal .acc-crown { opacity: 1; }
body.skin-aurora .acc-stars { opacity: 1; }
body.skin-ice .penguin-svg { filter: drop-shadow(0 0 12px rgba(120, 230, 255, 0.75)); }
body.skin-golden .penguin-svg { filter: drop-shadow(0 0 14px rgba(255, 215, 0, 0.7)); }
body.skin-aurora .penguin-svg { filter: drop-shadow(0 0 18px rgba(155, 93, 229, 0.75)); }

.charge-sparkles text {
  opacity: 0;
  transition: opacity .2s ease;
}
.charge-sparkles text.show { opacity: .95; }

/* Belly slide progress bar */
.slide-bar {
  width: 240px;
  height: 14px;
  background: rgba(23, 48, 71, .16);
  border-radius: 99px;
  overflow: hidden;
  z-index: 2;
  margin-top: -8px;
}
.slide-bar div {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #48cae4, #0077b6);
  border-radius: 99px;
  transition: width .1s;
}
.slide-label { font-size: .85rem; opacity: .75; margin-top: 4px; z-index: 2; font-weight: 500; }
.skin-name { font-size: .8rem; opacity: .65; margin-top: 2px; z-index: 2; }

/* Floating text & snow/fish particles */
.float {
  position: fixed;
  pointer-events: none;
  font-weight: 700;
  font-size: 1.4rem;
  color: #fff;
  text-shadow: 0 2px 0 var(--accent-dark), 0 0 8px rgba(0, 40, 80, .28);
  animation: floatUp 1s ease-out forwards;
  z-index: 50;
  white-space: nowrap;
}
@keyframes floatUp {
  from { transform: translate(-50%, 0); opacity: 1; }
  to { transform: translate(-50%, -90px); opacity: 0; }
}

.flake-burst {
  position: fixed;
  width: 10px;
  height: 10px;
  pointer-events: none;
  z-index: 49;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(150, 230, 255, .9);
}

.friend-pop {
  position: absolute;
  font-size: 84px;
  z-index: 5;
  pointer-events: none;
  animation: friendPop 1.6s ease-out forwards;
}
@keyframes friendPop {
  0% { transform: translateY(40px) scale(.2); opacity: 0; }
  25% { transform: translateY(-42px) scale(1.2); opacity: 1; }
  60% { transform: translateY(-64px) scale(1) rotate(-10deg); opacity: 1; }
  100% { transform: translateY(-165px) scale(.8) rotate(10deg); opacity: 0; }
}

/* Golden Fish */
.golden-fish {
  position: fixed;
  width: 72px;
  height: 56px;
  z-index: 40;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.6rem;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 240, 150, 0.92) 0%, rgba(255, 195, 0, 0.72) 55%, rgba(255, 170, 0, 0) 75%);
  box-shadow: 0 0 26px 8px rgba(255, 215, 0, .75);
  animation: goldenIn .5s ease-out, goldenBob 1.15s ease-in-out infinite alternate .5s;
}
.golden-fish.fade { transition: opacity 1s; opacity: 0; }
@keyframes goldenIn { from { transform: scale(0) rotate(-45deg); } to { transform: scale(1); } }
@keyframes goldenBob {
  from { transform: translateY(0) rotate(-8deg); }
  to { transform: translateY(-12px) rotate(8deg); }
}

/* ---------- Right: Shop ---------- */
.qty { display: flex; gap: 4px; }
.qty button {
  font-family: inherit;
  font-weight: 600;
  font-size: .8rem;
  border: none;
  border-radius: 8px;
  padding: 4px 9px;
  cursor: pointer;
  background: rgba(23, 48, 71, .1);
  color: var(--ink);
}
.qty button.active { background: var(--accent); color: #fff; }

.upgrades {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 2px dashed rgba(23, 48, 71, .14);
  min-height: 62px;
  max-height: 150px;
  overflow-y: auto;
}
.upgrades .empty { font-size: .85rem; opacity: .5; align-self: center; }
.upg {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: linear-gradient(135deg, #fff, #d8f3ff);
  box-shadow: 0 3px 0 rgba(23, 48, 71, .22);
  border: 2px solid transparent;
  transition: transform .08s;
  position: relative;
}
.upg:hover { transform: translateY(-2px); }
.upg.afford { border-color: var(--good); }
.upg.locked { filter: grayscale(.8) opacity(.6); }

.building {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  margin-bottom: 8px;
  border-radius: 14px;
  cursor: pointer;
  background: #fff;
  box-shadow: 0 3px 0 rgba(23, 48, 71, .16);
  transition: transform .08s, opacity .2s;
}
.building:hover { transform: translateX(-3px); }
.building:active { transform: translateY(2px); box-shadow: none; }
.building.cant { opacity: .55; }
.building.hidden { display: none; }
.building.mystery .b-name,
.building.mystery .b-icon { filter: brightness(0) opacity(.4); }
.b-icon { font-size: 2.1rem; text-align: center; }
.b-name { font-weight: 600; font-size: 1.05rem; }
.b-cost { font-size: .88rem; color: var(--good); font-weight: 600; }
.building.cant .b-cost { color: #b33; }
.b-owned {
  font-size: 1.8rem;
  font-weight: 700;
  opacity: .35;
  min-width: 36px;
  text-align: right;
}

/* ---------- Tooltip ---------- */
.tooltip {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  max-width: 270px;
  background: #102a43;
  color: #edf7ff;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: .85rem;
  line-height: 1.35;
  box-shadow: 0 8px 24px rgba(0, 20, 45, .35);
  opacity: 0;
  transition: opacity .1s;
}
.tooltip.show { opacity: 1; }
.tooltip b { color: #72efdd; font-size: .95rem; }
.tooltip .tt-cost { color: #80ed99; font-weight: 600; }
.tooltip .tt-dim { opacity: .7; font-style: italic; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: #102a43;
  color: #edf7ff;
  padding: 10px 18px;
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0, 20, 45, .35);
  font-size: .95rem;
  text-align: center;
  animation: toastIn .3s ease-out, toastOut .4s ease-in 3.6s forwards;
}
.toast b { color: #72efdd; }
@keyframes toastIn { from { transform: translateY(30px); opacity: 0; } }
@keyframes toastOut { to { transform: translateY(20px); opacity: 0; } }

.mute {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 3;
  background: var(--panel);
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(10, 45, 80, .18);
}

/* ---------- Developer Panel ---------- */
.dev-panel {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  z-index: 2;
  width: min(340px, 90%);
}
.dev-panel input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: .95rem;
  padding: 8px 12px;
  border: 2px solid var(--accent);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
.dev-panel .btn { flex: 0 0 auto; padding: 8px 14px; }

/* ---------- Modal & Leaderboard ---------- */
.modal-back {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(10, 30, 50, .52);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  background: #f5fbff;
  border-radius: 18px;
  padding: 22px;
  width: min(380px, 100%);
  box-shadow: 0 16px 50px rgba(0, 20, 45, .42);
}
.modal h3 { margin-bottom: 8px; }
.modal p { font-size: .95rem; line-height: 1.4; margin-bottom: 12px; }
.modal input {
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
  padding: 9px 12px;
  border: 2px solid var(--accent);
  border-radius: 10px;
  margin-bottom: 12px;
}
.modal-btns { display: flex; gap: 10px; }
.modal-btns .btn { padding: 10px; font-size: .95rem; }

.lb-list { margin-bottom: 8px; font-size: .95rem; }
.lb-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 10px;
}
.lb-row:nth-child(odd) { background: rgba(23, 48, 71, .06); }
.lb-row.me { background: #caf0f8; font-weight: 600; }
.lb-row span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row span:last-child { font-weight: 600; }
.lb-note { font-size: .78rem; opacity: .65; margin-bottom: 12px; }

/* ---------- Responsive ---------- */
@media (max-width: 1050px) {
  body { overflow: auto; }
  .app { grid-template-columns: 1fr; height: auto; }
  .center { order: -1; padding: 10px 0 20px; }
  .panel { max-height: 70vh; }
  .penguin-stage { transform: scale(.86); }
}
