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

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── Base ──────────────────────────────────────────────────────────────── */
body {
  background: #fffdf7;
  font-family: 'Nunito', 'Segoe UI', Arial, sans-serif;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  padding: 24px 16px;
}

.container {
  width: 100%;
  max-width: 480px;
  position: relative;
}

/* ── Screens ───────────────────────────────────────────────────────────── */
.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
}

.hidden {
  display: none !important;
}

/* ── Start Screen ──────────────────────────────────────────────────────── */
.start-logo {
  font-size: 76px;
  margin-top: 12px;
  animation: float 3s ease-in-out infinite;
}

.game-title {
  font-size: 40px;
  font-weight: 900;
  color: #e94560;
  letter-spacing: -1px;
}

.game-subtitle {
  font-size: 15px;
  color: #b5546a;
  text-align: center;
  max-width: 330px;
}

.t-pink   { color: #e94560; }
.t-purple { color: #8b6fc4; }

/* ── How to Play ───────────────────────────────────────────────────────── */
.how-to {
  width: 100%;
  background: #fff0f3;
  border: 2px solid #ffd6e0;
  border-radius: 16px;
  padding: 18px 18px;
}

.how-to h3 {
  font-size: 17px;
  font-weight: 900;
  color: #e94560;
  margin-bottom: 8px;
  text-align: center;
}

.how-to-lead {
  font-size: 14px;
  color: #6b5560;
  text-align: center;
  line-height: 1.45;
  margin-bottom: 12px;
}

.rule-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 12px;
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
}

.rule-table th,
.rule-table td {
  padding: 6px 8px;
  font-size: 13px;
  text-align: center;
  border-bottom: 1px solid #ffe4ec;
}

.rule-table th {
  font-size: 12px;
  font-weight: 900;
  background: #ffe8ee;
  color: #6b5560;
}

.rule-table td {
  font-weight: 700;
  color: #6b5560;
}

.rule-table tr:last-child td { border-bottom: none; }

.rule-table .flip {
  color: #e94560;
  font-weight: 900;
}

.how-to ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.how-to li {
  display: flex;
  gap: 9px;
  font-size: 13.5px;
  line-height: 1.45;
  color: #6b5560;
}

.how-to li span { flex-shrink: 0; font-size: 15px; }
.how-to li b    { color: #e94560; }

.link-back {
  font-size: 14px;
  font-weight: 700;
  color: #a18cd1;
  text-decoration: none;
  padding: 4px;
}

.link-back:hover { color: #e94560; }

/* ── Section Title ─────────────────────────────────────────────────────── */
.section-title {
  font-size: 24px;
  font-weight: 900;
  color: #e94560;
  text-align: center;
}

/* ── Level Select ──────────────────────────────────────────────────────── */
.levels-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 9px;
  width: 100%;
}

.level-btn {
  width: 100%;
  min-height: 0;
  aspect-ratio: 1;
  padding: 0;
  font-size: 17px;
  font-weight: 900;
  border-radius: 12px;
  background: linear-gradient(135deg, #e94560, #ff8a5c);
  color: #fff;
}

.level-btn.level--done {
  background: linear-gradient(135deg, #6bcb77, #94dd9d);
}

.level-btn.level--locked {
  background: #f3e6ea;
  color: #c9b3bb;
  cursor: not-allowed;
}

.level-btn.level--locked:hover { filter: none; transform: none; }

/* ── Game Header ───────────────────────────────────────────────────────── */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.game-title-small {
  font-size: 17px;
  font-weight: 900;
  color: #e94560;
}

.scores { display: flex; gap: 8px; }

.score-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: linear-gradient(135deg, #e94560, #ff8a5c);
  border-radius: 8px;
  padding: 6px 14px;
  min-width: 60px;
}

.score-label {
  font-size: 10px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.85);
  letter-spacing: 0.5px;
}

.score-value {
  font-size: 20px;
  font-weight: 900;
  color: #fff;
  line-height: 1.2;
}

.level-name {
  width: 100%;
  text-align: center;
  font-size: 15px;
  font-weight: 900;
  color: #a18cd1;
  letter-spacing: 0.5px;
}

/* ── Board ─────────────────────────────────────────────────────────────── */
.board {
  position: relative;
  display: grid;
  width: 100%;
  background: #efe6f4;
  border: 3px solid #e4d4ee;
  border-radius: 14px;
  overflow: hidden;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  background: #fffdf7;
  border: 1px solid #f6eef2;
}

.cell--wall {
  background: #6b5560;
  border-color: #5c4852;
}

.cell--ice {
  background: #d6ecff;
  border-color: #bcdcf7;
}

.cell--ice::after {
  content: '';
  position: absolute;
  inset: 22%;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.75);
  transform: rotate(20deg);
}

.cell--button {
  background: #fff6d6;
  border-color: #ffe9a8;
}

.cell--button::after {
  content: '';
  position: absolute;
  width: 46%;
  height: 46%;
  border-radius: 50%;
  background: #ffd93d;
  box-shadow: 0 0 0 3px rgba(255, 217, 61, 0.35);
}

.cell--gate {
  background: #cbb6d8;
  border-color: #b79ec8;
  transition: background 0.2s, border-color 0.2s;
}

.cell--gate::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(45deg, rgba(255,255,255,0.5) 0 4px, transparent 4px 8px);
  transition: opacity 0.2s;
}

.cell--gate.gate--open {
  background: #f3ecf7;
  border-color: #e6dcee;
}

.cell--gate.gate--open::after { opacity: 0.18; }

.cell--door-p,
.cell--door-q {
  background: #fffdf7;
}

.cell--door-p::after,
.cell--door-q::after {
  content: '';
  position: absolute;
  width: 60%;
  height: 60%;
  border-radius: 50%;
  border: 3px dashed #e94560;
}

.cell--door-q::after { border-color: #a18cd1; }

.cell--door-p.door--filled::after,
.cell--door-q.door--filled::after {
  animation: door-glow 1s ease-in-out infinite;
}

/* ── Blobs ─────────────────────────────────────────────────────────────── */
.blob {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: left 0.14s ease-out, top 0.14s ease-out;
  z-index: 5;
  pointer-events: none;
}

.blob::after {
  content: '';
  width: 72%;
  height: 72%;
  border-radius: 50%;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.15);
}

.blob-pink::after   { background: #e94560; }
.blob-purple::after { background: #a18cd1; }

.blob.blob--bump { animation: blob-bump 0.22s ease; }

/* ── D-pad ─────────────────────────────────────────────────────────────── */
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 60px);
  grid-template-rows: repeat(2, 52px);
  gap: 7px;
  justify-content: center;
  margin-top: 2px;
}

.dpad-btn {
  width: 60px;
  min-height: 0;
  height: 52px;
  padding: 0;
  font-size: 20px;
  border-radius: 12px;
  background: #fff0f3;
  color: #e94560;
  border: 2px solid #ffd6e0;
}

.dpad-btn:hover { background: #ffe0e8; filter: none; }

.dpad-up    { grid-column: 2; grid-row: 1; }
.dpad-left  { grid-column: 1; grid-row: 2; }
.dpad-down  { grid-column: 2; grid-row: 2; }
.dpad-right { grid-column: 3; grid-row: 2; }

/* ── Controls ──────────────────────────────────────────────────────────── */
.game-controls {
  display: flex;
  gap: 8px;
  width: 100%;
}

.game-controls button {
  flex: 1;
  font-size: 14px;
  padding: 12px 8px;
}

/* ── Buttons ───────────────────────────────────────────────────────────── */
button {
  background: linear-gradient(135deg, #e94560, #ff8a5c);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px 24px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
  width: 100%;
  min-height: 48px;
}

button:hover  { filter: brightness(1.07); transform: translateY(-1px); }
button:active { transform: translateY(0); }

.btn-secondary {
  background: #fff0f3;
  color: #e94560;
  border: 2px solid #ffd6e0;
}

.btn-secondary:hover { background: #ffe0e8; filter: none; }

.btn-leave {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 14px 24px;
  background: #fff0f3;
  color: #e94560;
  border: 2px solid #ffd6e0;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 900;
  text-decoration: none;
  transition: background 0.15s;
}

.btn-leave:hover { background: #ffe0e8; }

/* ── Overlay ───────────────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(43, 24, 32, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 24px;
}

.overlay-box {
  background: #fff;
  border-radius: 20px;
  padding: 30px 26px;
  max-width: 340px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  animation: win-pop 0.35s ease;
}

.result-emoji { font-size: 54px; }

.overlay-box h2 {
  font-size: 23px;
  font-weight: 900;
  color: #e94560;
  text-align: center;
}

.overlay-box p {
  font-size: 15px;
  font-weight: 700;
  color: #6b5560;
  text-align: center;
}

.overlay-box button { margin-top: 4px; }

/* ── Finish Screen ─────────────────────────────────────────────────────── */
.finish-icon {
  font-size: 76px;
  margin-top: 24px;
  animation: float 3s ease-in-out infinite;
}

#finish-text {
  font-size: 16px;
  font-weight: 700;
  color: #6b5560;
  text-align: center;
  margin-bottom: 6px;
}

/* ── Keyframes ─────────────────────────────────────────────────────────── */
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-10px); }
}

@keyframes blob-bump {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(0.82); }
}

@keyframes door-glow {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

@keyframes win-pop {
  0%   { transform: scale(0.7); opacity: 0; }
  60%  { transform: scale(1.05); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 420px) {
  body { padding: 12px 10px; }
  .game-title { font-size: 30px; }
  .start-logo { font-size: 58px; }
  .game-title-small { font-size: 14px; }
  .score-value { font-size: 16px; }
  .score-box { padding: 5px 10px; min-width: 50px; }
  .levels-grid { gap: 7px; }
  .level-btn { font-size: 15px; border-radius: 10px; }
  .dpad { grid-template-columns: repeat(3, 54px); grid-template-rows: repeat(2, 48px); }
  .dpad-btn { width: 54px; height: 48px; font-size: 18px; }
  .game-controls button { font-size: 13px; padding: 11px 4px; }
}
