/* ===== 小鲸鱼吃白饭 · 样式 ===== */

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;                 /* 禁止页面滚动 */
  overscroll-behavior: none;
  touch-action: none;               /* 禁止触摸手势（滚动、缩放） */
  background: #041435;
  color: #fff;
  -webkit-user-select: none;
  user-select: none;                /* 禁止长按选中 */
  -webkit-touch-callout: none;      /* 禁止 iOS 长按菜单 */
  -webkit-tap-highlight-color: transparent;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, "Helvetica Neue", sans-serif;
}

#game {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ===== 顶部信息栏 ===== */
.hud {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 12px 0;
  pointer-events: none;             /* 不挡住下面的触摸操作 */
}

.hud-box {
  background: rgba(8, 30, 80, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.hud-score,
.hud-best {
  display: flex;
  flex-direction: column;
  min-width: 88px;
  padding: 7px 12px;
}

.hud-best {
  align-items: flex-end;
}

.hud-lives {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  margin-top: 2px;
}

.label {
  font-size: 11px;
  letter-spacing: 0.08em;
  opacity: 0.75;
}

.value {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 8px rgba(0, 20, 60, 0.4);
}

/* 小爱心（纯 CSS 绘制） */
.heart {
  position: relative;
  width: 16px;
  height: 16px;
  margin: 4px 7px;
  background: #ff5d7a;
  transform: rotate(-45deg);
  box-shadow: 0 0 10px rgba(255, 93, 122, 0.6);
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

.heart::before,
.heart::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: inherit;
}

.heart::before {
  left: -8px;
  top: 0;
}

.heart::after {
  left: 0;
  top: -8px;
}

.heart.lost {
  background: rgba(255, 255, 255, 0.22);
  box-shadow: none;
}

/* ===== 遮罩与卡片 ===== */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(3, 16, 46, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;             /* 隐藏时不拦截点击 */
  transition: opacity 0.35s ease;
}

.overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.card {
  width: min(88vw, 340px);
  padding: 28px 24px 26px;
  border-radius: 24px;
  text-align: center;
  background: linear-gradient(160deg, rgba(77, 107, 254, 0.38), rgba(10, 35, 95, 0.62));
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.38);
  transform: translateY(14px) scale(0.97);
  transition: transform 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.overlay.show .card {
  transform: none;
}

h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

h2 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.sub {
  font-size: 14px;
  line-height: 1.6;
  opacity: 0.88;
  margin-bottom: 16px;
}

.tips {
  list-style: none;
  text-align: left;
  font-size: 13px;
  line-height: 1.9;
  margin: 0 auto 22px;
  padding-left: 4px;
  opacity: 0.92;
}

.tips li::before {
  content: "· ";
  color: #9fc0ff;
  font-weight: 700;
}

.new-record {
  display: inline-block;
  margin-bottom: 12px;
  padding: 4px 14px;
  border-radius: 999px;
  background: #ffd166;
  color: #4a2c00;
  font-size: 13px;
  font-weight: 700;
}

.new-record[hidden] {
  display: none;
}

.result {
  display: flex;
  justify-content: space-around;
  margin: 14px 0 24px;
}

.result strong {
  display: block;
  margin-top: 4px;
  font-size: 36px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 10px rgba(0, 20, 60, 0.35);
}

/* ===== 按钮 ===== */
.btn {
  display: inline-block;
  min-width: 184px;
  padding: 14px 28px;
  border: 0;
  border-radius: 999px;
  font-size: 17px;
  font-weight: 700;
  font-family: inherit;
  color: #0f3fb8;
  background: linear-gradient(180deg, #ffffff, #dbe6ff);
  box-shadow: 0 8px 0 #9db6f0, 0 14px 26px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.btn:active {
  transform: translateY(5px);
  box-shadow: 0 3px 0 #9db6f0, 0 6px 12px rgba(0, 0, 0, 0.3);
}

.btn:focus-visible {
  outline: 3px solid #9fc0ff;
  outline-offset: 4px;
}

/* 小屏手机适当收紧 */
@media (max-width: 360px) {
  h1 { font-size: 24px; }
  .value { font-size: 20px; }
  .hud-score, .hud-best { min-width: 72px; }
}

/* 横屏提示：游戏为竖屏设计，横屏时仍可玩但画面会缩小 */
@media (orientation: landscape) and (max-height: 500px) {
  .card { padding: 18px 20px; }
  .tips { display: none; }
  .sub { margin-bottom: 12px; }
}

/* ===== 本地排行榜 ===== */
:root {
  --accent: #9fd0ff;              /* 强调色：与本项目蓝白风格一致 */
}

/* 全局隐藏属性：确保 hidden 一定生效 */
[hidden] {
  display: none !important;
}

.btn-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* 次级按钮：半透明玻璃感，用于「排行榜」入口 */
.btn.ghost {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.5), 0 6px 16px rgba(0, 0, 0, 0.25);
}

.btn.ghost:active {
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.5), 0 2px 8px rgba(0, 0, 0, 0.25);
}

/* 小号按钮（排行榜底部操作） */
.btn.small {
  min-width: 0;
  padding: 10px 20px;
  font-size: 14px;
}

.btn.danger {
  color: #fff;
  background: linear-gradient(180deg, #ff9fb0, #ff4d6d);
  box-shadow: 0 6px 0 #b8243f, 0 10px 18px rgba(0, 0, 0, 0.3);
}

.btn.danger:active {
  box-shadow: 0 2px 0 #b8243f, 0 4px 10px rgba(0, 0, 0, 0.3);
}

.history-rank {
  margin: -4px 0 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
}

.rank-screen {
  z-index: 20;                    /* 盖在开始 / 结束界面之上 */
}

.rank-card {
  width: min(92vw, 360px);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 22px 18px 18px;
}

.rank-card h2 {
  margin-bottom: 4px;
}

.rank-note {
  font-size: 12px;
  opacity: 0.7;
  margin-bottom: 14px;
}

.rank-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 14px;
  max-height: min(48vh, 400px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;            /* 允许列表内部上下滑动 */
  padding-right: 2px;
}

.rank-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  text-align: left;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.rank-no {
  flex: 0 0 26px;
  height: 26px;
  line-height: 26px;
  border-radius: 50%;
  text-align: center;
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: rgba(255, 255, 255, 0.14);
}

.rank-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.rank-main strong {
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.rank-meta {
  margin-top: 2px;
  font-size: 11px;
  opacity: 0.72;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 前三名：金 / 银 / 铜 */
.rank-item.medal-1 {
  background: linear-gradient(90deg, rgba(255, 215, 106, 0.3), rgba(255, 255, 255, 0.06));
  border-color: rgba(255, 215, 106, 0.6);
}
.rank-item.medal-1 .rank-no { background: #ffd76a; color: #4a3200; }

.rank-item.medal-2 {
  background: linear-gradient(90deg, rgba(217, 226, 239, 0.28), rgba(255, 255, 255, 0.06));
  border-color: rgba(217, 226, 239, 0.55);
}
.rank-item.medal-2 .rank-no { background: #d9e2ef; color: #26324a; }

.rank-item.medal-3 {
  background: linear-gradient(90deg, rgba(224, 160, 112, 0.3), rgba(255, 255, 255, 0.06));
  border-color: rgba(224, 160, 112, 0.6);
}
.rank-item.medal-3 .rank-no { background: #e0a070; color: #3d2208; }

/* 本局高亮 */
.rank-item.current {
  box-shadow: 0 0 0 2px var(--accent), 0 0 16px rgba(159, 208, 255, 0.5);
}

.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  vertical-align: middle;
  background: var(--accent);
  color: #10204a;
}

.rank-empty {
  padding: 26px 0;
  font-size: 14px;
  opacity: 0.8;
}

.rank-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
}

.clear-confirm {
  margin-bottom: 14px;
  padding: 12px;
  border-radius: 14px;
  font-size: 13px;
  background: rgba(255, 90, 120, 0.16);
  border: 1px solid rgba(255, 140, 160, 0.45);
}

.clear-confirm p {
  margin-bottom: 10px;
  line-height: 1.5;
}
