/* ===========================================================
   书娜的小游戏 — 糖果色设计系统（共享）
   =========================================================== */
:root {
  --cream: #FFF6F0;
  --pink: #FF8FB1;
  --pink-d: #FF6B97;
  --mint: #7BD3C8;
  --mint-d: #4FBDB0;
  --sky: #8AC6FF;
  --sky-d: #5FA8F0;
  --lemon: #FFD56B;
  --lemon-d: #F0B83B;
  --lav: #B6A8E0;
  --lav-d: #9683CC;
  --berry: #5B3A52;
  --berry-soft: #8A6478;
  --grass: #A8E6A1;
  --white: #ffffff;
  --shadow: 0 8px 22px rgba(91, 58, 82, 0.14);
  --shadow-sm: 0 4px 12px rgba(91, 58, 82, 0.10);
  --radius: 18px;
  --radius-lg: 26px;
  --font: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%;
  background: var(--cream); color: var(--berry);
  font-family: var(--font);
  overflow: hidden; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
body { touch-action: none; }
button { font-family: var(--font); }
a { color: inherit; text-decoration: none; }

/* ---------------- 通用按钮 ---------------- */
.candy-btn {
  border: 0; cursor: pointer; color: #fff; font-weight: 800; font-size: 17px;
  background: linear-gradient(135deg, var(--pink), var(--pink-d));
  padding: 14px 26px; border-radius: 16px;
  box-shadow: 0 5px 0 var(--pink-d), var(--shadow);
  transition: transform .06s ease, box-shadow .06s ease;
}
.candy-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--pink-d), var(--shadow-sm); }
.candy-btn.alt { background: linear-gradient(135deg, var(--mint), var(--mint-d)); box-shadow: 0 5px 0 var(--mint-d), var(--shadow); }
.candy-btn.alt:active { box-shadow: 0 1px 0 var(--mint-d), var(--shadow-sm); }
.candy-btn.ghost { background: #fff; color: var(--berry); box-shadow: 0 5px 0 #ead9e2, var(--shadow); }
.candy-btn.ghost:active { box-shadow: 0 1px 0 #ead9e2, var(--shadow-sm); }

/* ===========================================================
   门户首页
   =========================================================== */
.portal {
  position: fixed; inset: 0; overflow-y: auto; overflow-x: hidden;
  background:
    radial-gradient(circle at 12% 8%, rgba(255,143,177,.28), transparent 42%),
    radial-gradient(circle at 88% 4%, rgba(138,198,255,.28), transparent 40%),
    radial-gradient(circle at 50% 100%, rgba(123,211,200,.24), transparent 50%),
    var(--cream);
  touch-action: pan-y;
}
.portal-wrap { max-width: 880px; margin: 0 auto; padding: 26px 18px 48px; }
.portal-head { text-align: center; margin-bottom: 22px; position: relative; }
.portal-title { font-size: clamp(28px, 7vw, 40px); font-weight: 900; margin: 0; letter-spacing: 1px;
  background: linear-gradient(120deg, var(--pink-d), var(--lav-d) 50%, var(--sky-d));
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.portal-sub { margin: 6px 0 0; color: var(--berry-soft); font-size: 15px; }
.portal-deco { font-size: 40px; margin-bottom: 2px; }

.sound-toggle {
  position: absolute; top: -2px; right: 0; width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: #fff; box-shadow: var(--shadow-sm); font-size: 20px; cursor: pointer; color: var(--berry);
}
.sound-toggle.off { opacity: .55; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.card {
  position: relative; border: 0; cursor: pointer; border-radius: var(--radius-lg);
  padding: 22px 16px 18px; text-align: left; color: var(--berry);
  box-shadow: var(--shadow); overflow: hidden;
  transition: transform .1s ease;
  min-height: 132px; display: flex; flex-direction: column; justify-content: space-between;
}
.card:active { transform: scale(.97); }
.card .ico { font-size: 40px; line-height: 1; filter: drop-shadow(0 3px 4px rgba(0,0,0,.12)); }
.card .name { font-size: 19px; font-weight: 900; margin-top: 10px; }
.card .tag { font-size: 12.5px; opacity: .78; margin-top: 2px; }
.card .hi { position: absolute; top: 12px; right: 12px; font-size: 11px; font-weight: 800;
  background: rgba(255,255,255,.7); color: var(--berry); padding: 3px 9px; border-radius: 999px; }
.card .soon { position: absolute; top: 12px; right: 12px; font-size: 11px; font-weight: 800;
  background: rgba(91,58,82,.14); color: var(--berry); padding: 3px 9px; border-radius: 999px; }

.card-runngun { background: linear-gradient(140deg, #FFC6D7, #FFE0A8); }
.card-tetris { background: linear-gradient(140deg, #D6CCF2, #BFE0FF); }
.card-2048 { background: linear-gradient(140deg, #FFE9A8, #B7EBE0); }
.card-shooter { background: linear-gradient(140deg, #BFE0FF, #D6CCF2); }
.card-tank { background: linear-gradient(140deg, #FFC6D7, #FFE6A8); }
.card-platformer { background: linear-gradient(140deg, #C7F0C2, #BFE0FF); }

.portal-foot { text-align: center; color: var(--berry-soft); font-size: 12.5px; margin-top: 30px; }

/* ===========================================================
   游戏页通用外壳
   =========================================================== */
.game-page { position: fixed; inset: 0; overflow: hidden;
  background: linear-gradient(180deg, #FFF1F6, #FFF6F0); }
canvas.game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* 顶部 HUD */
.hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 15;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(255,255,255,.92); box-shadow: var(--shadow-sm); color: var(--berry); font-size: 18px;
}
.hud-btn:active { transform: scale(.93); }
.hud-chips { display: flex; gap: 8px; }
.chip {
  background: rgba(255,255,255,.92); border-radius: 999px; padding: 8px 13px; font-weight: 800; font-size: 14px;
  box-shadow: var(--shadow-sm); display: flex; align-items: center; gap: 5px; min-width: 56px; justify-content: center;
}
.chip small { color: var(--berry-soft); font-weight: 700; font-size: 11px; }

/* 覆盖层（开始/暂停/胜负） */
.overlay { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
  padding: 22px; background: rgba(91,58,82,.32); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  animation: fade .18s ease; }
.overlay.hidden { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.panel { background: var(--white); border-radius: var(--radius-lg); padding: 28px 24px 24px; max-width: 340px; width: 100%;
  text-align: center; box-shadow: var(--shadow); animation: pop .22s cubic-bezier(.2,1.3,.5,1); }
@keyframes pop { from { transform: scale(.82); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.panel .emoji { font-size: 52px; line-height: 1; }
.panel h1 { margin: 12px 0 4px; font-size: 26px; }
.panel p { margin: 0 0 20px; color: var(--berry-soft); font-size: 15px; }
.panel .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.panel .stat { background: var(--cream); border-radius: 14px; padding: 10px 14px; margin: 0 4px 16px; }
.panel .stat b { display: block; font-size: 24px; color: var(--pink-d); }
.panel .stat span { font-size: 12px; color: var(--berry-soft); }
.new-record { color: var(--lemon-d); font-weight: 900; font-size: 15px; margin-bottom: 12px;
  animation: bounce 1s ease infinite; }
@keyframes bounce { 0%,100%{transform:translateY(0);} 50%{transform:translateY(-4px);} }

/* ===========================================================
   虚拟手柄（controls.js 注入）
   =========================================================== */
.candy-dpad {
  position: fixed; left: calc(env(safe-area-inset-left) + 16px);
  bottom: calc(env(safe-area-inset-bottom) + 22px);
  width: 138px; height: 138px; border-radius: 50%;
  background: rgba(255,255,255,.42); box-shadow: var(--shadow);
  touch-action: none; z-index: 10; border: 2px solid rgba(255,255,255,.6);
}
.candy-knob {
  position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, var(--pink), var(--pink-d)); transform: translate(-50%, -50%);
  box-shadow: var(--shadow); transition: transform .03s linear;
}
.candy-arrow { position: absolute; color: rgba(91,58,82,.42); font-size: 13px; font-weight: 900; }
.candy-arrow.a-up { top: 8px; left: 50%; transform: translateX(-50%); }
.candy-arrow.a-down { bottom: 8px; left: 50%; transform: translateX(-50%); }
.candy-arrow.a-left { left: 10px; top: 50%; transform: translateY(-50%); }
.candy-arrow.a-right { right: 10px; top: 50%; transform: translateY(-50%); }

.candy-actions {
  position: fixed; right: calc(env(safe-area-inset-right) + 18px);
  bottom: calc(env(safe-area-inset-bottom) + 26px);
  display: flex; align-items: flex-end; gap: 14px; z-index: 10;
}
.candy-action {
  width: 76px; height: 76px; border-radius: 50%; border: 2px solid rgba(255,255,255,.7);
  background: linear-gradient(135deg, var(--sky), var(--sky-d)); color: #fff; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  box-shadow: var(--shadow); touch-action: none; padding: 0;
  transition: transform .05s ease, box-shadow .05s ease;
}
.candy-action.candy-action-big { width: 92px; height: 92px; }
.candy-action.pressed { transform: scale(.92); box-shadow: var(--shadow-sm); }
.candy-action-icon { font-size: 26px; line-height: 1; }
.candy-action.candy-action-big .candy-action-icon { font-size: 32px; }
.candy-action-label { font-size: 11px; font-weight: 800; opacity: .95; }

/* 横屏时把控件往上挪一点，避免被手势条遮挡 */
@media (orientation: landscape) and (max-height: 460px) {
  .candy-dpad, .candy-actions { bottom: calc(env(safe-area-inset-bottom) + 12px); }
  .candy-dpad { width: 116px; height: 116px; }
  .candy-action { width: 66px; height: 66px; }
  .candy-action.candy-action-big { width: 80px; height: 80px; }
}

/* ---------------- 2048 专属 ---------------- */
.g2048-page { position: fixed; inset: 0; overflow-y: auto; overscroll-behavior: none;
  background: radial-gradient(circle at 50% 0%, #FFEFC4, var(--cream)); touch-action: none; }
.g2048-wrap { max-width: 460px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 14px) 14px 30px; }
.g2048-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.g2048-bar .title { font-size: 30px; font-weight: 900; background: linear-gradient(120deg,var(--lemon-d),var(--pink-d));
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.g2048-scores { display: flex; gap: 8px; }
.g2048-scores .chip { background: #fff; }
.g2048-board {
  position: relative; width: 100%; aspect-ratio: 1 / 1; background: rgba(255,255,255,.55);
  border-radius: 18px; box-shadow: var(--shadow); padding: 10px; touch-action: none;
}
.g2048-grid { position: absolute; inset: 10px; display: grid; grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr); gap: 10px; }
.g2048-cell { background: rgba(255,255,255,.5); border-radius: 12px; }
.g2048-tiles { position: absolute; inset: 10px; }
.tile {
  position: absolute; display: flex; align-items: center; justify-content: center;
  border-radius: 12px; font-weight: 900; color: var(--berry);
  transition: left .12s ease, top .12s ease; box-shadow: var(--shadow-sm);
}
@keyframes tilePop { 0%{transform:scale(.2);} 60%{transform:scale(1.12);} 100%{transform:scale(1);} }
.tile.new { animation: tilePop .16s ease; }
.g2048-hint { text-align: center; color: var(--berry-soft); font-size: 13px; margin-top: 14px; }
