/* 打奶蛙 · 样式
 * 配色/卡片/按钮遵循「奶蛙小游戏系列」统一规范。 */

:root {
  --ink: #4a3325;
  --ink-soft: #8a7566;
  --cream: #fff7ec;
  --brand: #ff6b6b;
  --brand-dark: #e14b4b;
  --card: rgba(255, 255, 255, .74);
  --shadow: 0 18px 50px rgba(126, 84, 44, .18);
  --gold: #e79a1f;
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }
html { overscroll-behavior: none; }

body {
  background-color: #fff9f1;
  background-image:
    radial-gradient(1200px 700px at 8% -12%, #ffe9bd 0%, transparent 60%),
    radial-gradient(900px 600px at 104% -6%, #d5f0ff 0%, transparent 55%),
    radial-gradient(1000px 780px at 50% 118%, #ffdbe6 0%, transparent 62%);
  background-repeat: no-repeat;
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; }
img { -webkit-user-drag: none; user-drag: none; pointer-events: none; }
[hidden] { display: none !important; }

/* ================= 页面骨架 ================= */

.page {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding:
    max(14px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(6px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
}

.app {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "stage panel";
  gap: 22px;
  align-items: stretch;
}

.stage-wrap {
  grid-area: stage;
  position: relative;
  min-width: 0;
  min-height: 0;
}

/* 舞台的像素尺寸由 game.js 根据可用空间算出来（保持合适的宽高比），这里只管样式 */
.stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border-radius: 24px;
  background: #fff3df;
  box-shadow: 0 26px 64px rgba(122, 80, 40, .3);
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.stage canvas {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

body.playing .stage canvas { cursor: none; }

.foot {
  flex: 0 0 auto;
  text-align: center;
  font-size: 11px;
  line-height: 1.4;
  color: var(--ink-soft);
  opacity: .85;
  padding: 2px 0;
}

/* ================= 舞台顶部：倒计时 ================= */

.hud {
  position: absolute;
  left: 16px;
  right: 16px;
  top: 12px;
  height: 28px;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
  z-index: 2;
}

.hud-time {
  flex: 0 0 auto;
  min-width: 2.1em;
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
  color: #fff;
  text-shadow: 0 2px 0 rgba(48, 110, 52, .5), 0 0 10px rgba(48, 110, 52, .35);
  font-variant-numeric: tabular-nums;
  transition: color .2s;
}

.timebar {
  flex: 1 1 auto;
  height: 13px;
  border-radius: 99px;
  background: rgba(255, 255, 255, .55);
  box-shadow: inset 0 1px 3px rgba(48, 110, 52, .3), 0 1px 0 rgba(255, 255, 255, .5);
  overflow: hidden;
}

.timebar i {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #ffd45a, #ff9a4d 55%, #ff6b6b);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .08), inset 0 2px 0 rgba(255, 255, 255, .35);
  transition: width .15s linear;
}

.hud.danger .hud-time { color: #ff5a5a; text-shadow: 0 2px 0 rgba(255, 255, 255, .85); animation: hud-beat 1s ease-in-out infinite; }
.hud.danger .timebar i { background: linear-gradient(90deg, #ff9a4d, #ff4d4d); }

@keyframes hud-beat { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.18); } }

.combo-chip {
  flex: 0 0 auto;
  min-width: 92px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  padding: 3px 10px 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, .86);
  box-shadow: 0 4px 12px rgba(48, 110, 52, .22);
  font-weight: 900;
  color: var(--brand-dark);
  opacity: 0;
  transform: scale(.7);
  transition: opacity .15s, transform .2s cubic-bezier(.3, 1.7, .5, 1);
  white-space: nowrap;
}
.combo-chip.show { opacity: 1; transform: scale(1); }
.combo-chip b { font-size: 20px; line-height: 1; font-variant-numeric: tabular-nums; }
.combo-chip span { font-size: 12px; }
.combo-chip em {
  font-style: normal;
  font-size: 12px;
  color: #fff;
  padding: 1px 7px;
  border-radius: 99px;
  background: linear-gradient(135deg, #ff8a5b, #e14b4b);
}
.combo-chip.m3 em { background: linear-gradient(135deg, #ff6b9d, #d63384); }
.combo-chip.m4 em { background: linear-gradient(135deg, #b13bff, #ff4d6d); }

.hud-plus {
  position: absolute;
  left: 0;
  top: 22px;
  font-size: 16px;
  font-weight: 900;
  color: #ffd23f;
  text-shadow: 0 2px 0 rgba(150, 90, 0, .55), 0 0 8px rgba(255, 210, 63, .8);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}

/* ================= 浮层（开始 / 暂停 / 结束） ================= */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  text-align: center;
  background: radial-gradient(ellipse at 50% 42%, rgba(255, 247, 236, .9), rgba(255, 236, 214, .8));
  opacity: 1;
  transition: opacity .22s ease;
  cursor: pointer;
}
.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .18s ease, visibility 0s .18s;
}

.ov-card {
  position: relative;
  width: min(100%, 360px);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  animation: card-in .45s cubic-bezier(.3, 1.5, .5, 1) both;
}
.overlay.hidden .ov-card { animation: none; }

@keyframes card-in { from { opacity: 0; transform: translateY(18px) scale(.9); } to { opacity: 1; transform: none; } }

.ov-title {
  font-size: clamp(34px, 11vw, 46px);
  font-weight: 900;
  letter-spacing: .04em;
  line-height: 1.15;
  background: linear-gradient(100deg, #ff7a59, #ff4d6d 55%, #b13bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 0 rgba(255, 255, 255, .9));
}
.ov-title.small { font-size: clamp(28px, 9vw, 36px); }

.ov-sub { margin: 0; font-size: 14px; color: var(--ink-soft); }
.ov-hint { margin: 0; font-size: 12px; color: var(--ink-soft); }

.ov-scores { display: flex; gap: 10px; width: 100%; justify-content: center; }
.ov-box {
  flex: 1 1 0;
  max-width: 150px;
  padding: 8px 10px 10px;
  border-radius: 16px;
  background: rgba(255, 255, 255, .82);
  box-shadow: 0 6px 16px rgba(126, 84, 44, .12);
}
.ov-box .lbl { display: block; font-size: 11px; letter-spacing: .12em; color: var(--ink-soft); }
.ov-box b { display: block; margin-top: 2px; font-size: 34px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.ov-box b.gold { color: var(--gold); }

.ov-new {
  padding: 4px 16px 5px;
  border-radius: 99px;
  font-size: 15px;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(135deg, #ffb347, #ff6b6b 60%, #b13bff);
  box-shadow: 0 6px 16px rgba(225, 75, 75, .3);
  animation: new-pop .6s cubic-bezier(.3, 1.8, .5, 1) .25s both;
}
.ov-new::before { content: "🎉 "; }
.ov-new::after { content: " 🎉"; }

@keyframes new-pop { from { opacity: 0; transform: scale(.3) rotate(-8deg); } to { opacity: 1; transform: scale(1) rotate(-2deg); } }

.ov-rank { margin: 0; font-size: 14px; font-weight: 700; color: var(--ink); }
.ov-stats { margin: 0; font-size: 12px; color: var(--ink-soft); }

.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti i {
  position: absolute;
  top: -16px;
  width: 8px;
  height: 13px;
  border-radius: 2px;
  opacity: .95;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  to { transform: translate3d(var(--dx, 0px), var(--fall, 700px), 0) rotate(var(--rot, 540deg)); }
}

/* ================= 侧栏 ================= */

.panel {
  grid-area: panel;
  align-self: center;
  max-height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  border-radius: 24px;
  background: var(--card);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, .7);
  box-shadow: var(--shadow);
}

.brand h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.2;
  font-weight: 900;
  letter-spacing: .02em;
  background: linear-gradient(100deg, #ff7a59, #ff4d6d 55%, #b13bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
}
.brand .sub { margin: 4px 0 0; font-size: 13px; line-height: 1.5; color: var(--ink-soft); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.stat {
  position: relative;
  padding: 10px 14px 11px;
  border-radius: 16px;
  background: rgba(255, 255, 255, .82);
  box-shadow: 0 4px 12px rgba(126, 84, 44, .08);
  min-width: 0;
}
.stat .k { display: block; font-size: 11px; letter-spacing: .12em; color: var(--ink-soft); white-space: nowrap; }
.stat .v { display: inline-block; margin-top: 2px; font-size: 26px; line-height: 1.15; font-weight: 800; font-variant-numeric: tabular-nums; transform-origin: left center; }
.stat .v.best { color: var(--gold); }
.stat .v.low { color: var(--brand-dark); }
.stat .mult {
  margin-left: 6px;
  font-style: normal;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
  padding: 1px 7px;
  border-radius: 99px;
  background: linear-gradient(135deg, #ffb27a, #ff8a5b);
  vertical-align: 4px;
  opacity: .55;
}
.stat .mult.on { opacity: 1; background: linear-gradient(135deg, #ff8a5b, #e14b4b); }

/* 图鉴 */
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.legend li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 6px 6px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .6);
  text-align: left;
}
.legend b { display: block; font-size: 13px; line-height: 1.25; }
.legend small { display: block; font-size: 12px; line-height: 1.3; color: var(--ink-soft); }

.thumb {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .6);
}
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.thumb .gimg {
  display: block;
  width: 100%;
  height: 100%;
  background: url("../assets/nai/nai11-god.webp") 50% 46% / 235% auto no-repeat;
}
.t-normal { background: linear-gradient(135deg, #e6f7d6, #b9e8a0); }
.t-sumo   { background: linear-gradient(135deg, #ffe2b8, #ffb25b); }
.t-god    { background: linear-gradient(135deg, #fff4b0, #ffd23f); }
.t-angel  { background: linear-gradient(135deg, #ffd9e2, #ff9bb0); }

.legend.mini {
  width: 100%;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.legend.mini li { padding: 4px 8px 4px 4px; gap: 7px; }
.legend.mini .thumb { width: 34px; height: 34px; border-radius: 10px; }
.legend.mini b { font-size: 12px; white-space: nowrap; }
.legend.mini small { font-size: 11px; white-space: nowrap; }

/* 按钮 */
.btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.btn {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 44px;
  min-height: 44px;                 /* 触控目标至少 44x44 css px */
  padding: 10px 8px;
  border: 1px solid rgba(138, 117, 102, .22);
  border-radius: 14px;
  background: rgba(255, 255, 255, .86);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(138, 117, 102, .18);
  transition: transform .14s cubic-bezier(.3, 1.6, .5, 1), box-shadow .15s, background .15s;
  -webkit-user-select: none;
  user-select: none;
}
@media (hover: hover) { .btn:hover { transform: translateY(-1px); background: #fff; } }   /* 触屏没有悬停，免得点完按钮粘着浮起 */
.btn:active { transform: translateY(2px) scale(.97); box-shadow: 0 1px 0 rgba(138, 117, 102, .18); }
.btn:focus-visible { outline: 3px solid rgba(255, 107, 107, .45); outline-offset: 2px; }

.btn.primary {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, #ff8a5b, #ff6b6b, #e14b4b);
  text-shadow: 0 1px 0 rgba(150, 30, 30, .35);
  box-shadow: 0 8px 18px rgba(225, 75, 75, .32), 0 3px 0 #c63a3a;
}
@media (hover: hover) { .btn.primary:hover { background: linear-gradient(135deg, #ff9a6d, #ff7b7b, #ea5757); } }
.btn.primary:active { box-shadow: 0 3px 8px rgba(225, 75, 75, .3), 0 1px 0 #c63a3a; }

.btn.big { font-size: 19px; padding: 12px 30px; border-radius: 18px; }

@keyframes btn-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }
.btn.pulse { animation: btn-pulse 1.3s ease-in-out infinite; }

.tip { margin: 0; font-size: 12px; line-height: 1.8; color: var(--ink-soft); }
.foot2 { display: none; margin: 0; text-align: center; font-size: 10px; line-height: 1.4; color: var(--ink-soft); opacity: .85; }
kbd {
  display: inline-block;
  min-width: 1.45em;
  padding: 0 .3em;
  margin: 0 1px;
  border-radius: 5px;
  border: 1px solid rgba(138, 117, 102, .35);
  border-bottom-width: 2px;
  background: rgba(255, 255, 255, .85);
  font: 700 11px/1.5 var(--font);
  text-align: center;
  color: var(--ink);
}

/* ================= 矮屏幕的桌面：压缩侧栏 ================= */

@media (min-width: 720px) and (max-height: 820px) {
  .panel { gap: 10px; padding: 16px; }
  .legend { gap: 6px; }
  .legend li { padding: 4px 8px 4px 4px; }
  .thumb { width: 34px; height: 34px; }
  .stat { padding: 8px 12px 9px; }
  .stat .v { font-size: 24px; }
  .tip { font-size: 11px; line-height: 1.7; }
}
@media (min-width: 720px) and (max-height: 700px) {
  .tip { display: none; }
}
@media (min-width: 720px) and (max-height: 600px) {
  .panel .legend { display: none; }
}

/* ================= 窄屏（< 720px）：上下排列，侧栏精简 ================= */

@media (max-width: 719.98px), (max-width: 900px) and (orientation: portrait) {
  .page {
    gap: 4px;
    padding:
      max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(4px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "panel" "stage";
    gap: 8px;
  }
  .panel {
    align-self: stretch;
    max-height: none;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "brand btns" "stats stats";
    align-items: center;
    gap: 8px 8px;
    padding: 8px 10px 10px;
    border-radius: 24px;
  }
  .brand { grid-area: brand; min-width: 0; }
  .brand h1 { font-size: 21px; white-space: nowrap; }
  .brand .sub, .panel .legend, .tip { display: none; }
  .btns { grid-area: btns; display: flex; gap: 8px; }
  .btn { padding: 0 12px; font-size: 13px; border-radius: 14px; box-shadow: 0 2px 0 rgba(138, 117, 102, .18); }
  .btn.primary { box-shadow: 0 4px 10px rgba(225, 75, 75, .3), 0 2px 0 #c63a3a; }
  .stats { grid-area: stats; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .stat { padding: 5px 8px 6px; border-radius: 12px; }
  .stat .k { font-size: 10px; letter-spacing: .06em; }
  .stat .v { font-size: 20px; margin-top: 0; }
  .stat .mult { margin-left: 3px; padding: 0 5px; font-size: 10px; vertical-align: 2px; }
  .hud { left: 12px; right: 12px; top: 10px; }
  .hud-time { font-size: 20px; }
  .combo-chip { min-width: 84px; }
  .legend.mini { gap: 5px; }
  .ov-hint { display: none; }
}

@media (max-width: 349.98px) {
  .brand h1 { font-size: 18px; }
  .btn { padding: 0; }
  .btn .txt { display: none; }
  .btns { gap: 6px; }
}

/* ================= 手机横屏等"矮而宽"的窗口：回到左右布局 ================= */

@media (orientation: landscape) and (max-height: 520px) {
  .page { padding: max(4px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); gap: 0; }
  .app {
    grid-template-columns: minmax(0, 1fr) 208px;
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "stage panel";
    gap: 10px;
  }
  .panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-self: center;
    padding: 8px 10px 8px;
    border-radius: 24px;
  }
  .brand .sub, .panel .legend, .tip { display: none; }
  .brand h1 { font-size: 20px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 6px; }
  .btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .btn { padding: 0; font-size: 13px; }
  .btn .txt { display: none; }
  .foot { display: none; }
  .foot2 { display: block; }
  .ov-title { font-size: 30px; }
  .ov-card { gap: 6px; }
  .legend.mini { display: none; }
  .ov-box b { font-size: 26px; }
}

@media (prefers-reduced-motion: reduce) {
  .btn.pulse, .hud.danger .hud-time { animation: none; }
  .confetti { display: none; }
}
