:root {
  --theme: #FF8A3D;
  --theme-deep: #E86A1C;
  --theme-soft: #FFB27A;
  --theme-glow: rgba(255, 138, 61, 0.55);
  --ink: #FFF6EC;
  --ink-dim: #C9B6D8;
  --ink-mute: #9A87B8;
  --card: #2A1B45;
  --card-2: #35235A;
  --slot: #241640;
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.22);
  --tile-face: linear-gradient(168deg, #FFFDF8 0%, #FCEEDC 52%, #F3DFC4 100%);
  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 14px;
  --shadow-card: 0 14px 30px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #150C28;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Segoe UI", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px calc(env(safe-area-inset-bottom, 0px) + 14px);
  background:
    radial-gradient(120% 70% at 50% -10%, #4A2A6E 0%, rgba(74, 42, 110, 0) 62%),
    radial-gradient(90% 60% at 100% 100%, #3A1F5C 0%, rgba(58, 31, 92, 0) 60%),
    linear-gradient(180deg, #1E1136 0%, #150C28 55%, #100A20 100%);
  overflow: hidden;
}

/* ---------- 背景装饰 ---------- */
.bg-sky {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(60% 34% at 50% 8%, rgba(255, 138, 61, 0.16), rgba(255, 138, 61, 0) 70%),
    radial-gradient(50% 30% at 12% 78%, rgba(126, 87, 255, 0.16), rgba(126, 87, 255, 0) 70%);
}

.bg-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(46px);
  pointer-events: none;
  opacity: 0.5;
}
.bg-glow-a {
  width: 260px; height: 260px;
  top: -90px; left: -70px;
  background: radial-gradient(circle, var(--theme-glow), rgba(255, 138, 61, 0));
  animation: glowDrift 9s ease-in-out infinite alternate;
}
.bg-glow-b {
  width: 300px; height: 300px;
  bottom: -120px; right: -100px;
  background: radial-gradient(circle, rgba(126, 87, 255, 0.5), rgba(126, 87, 255, 0));
  animation: glowDrift 11s ease-in-out infinite alternate-reverse;
}
@keyframes glowDrift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(14px, 18px, 0) scale(1.12); }
}

.bg-stars {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.bg-stars span {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.6);
  animation: twinkle 3.4s ease-in-out infinite;
}
@keyframes twinkle {
  0%, 100% { opacity: 0.18; transform: scale(0.8); }
  50% { opacity: 0.85; transform: scale(1.15); }
}

/* ---------- HUD ---------- */
.hud {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex: 0 0 auto;
}

.hud-score {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 18px 7px 8px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.05));
  border: 1px solid var(--line-strong);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.hud-score-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--theme-soft), var(--theme-deep));
  box-shadow: 0 6px 14px rgba(255, 138, 61, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  color: #fff;
}
.hud-score-icon .mp-icon { width: 19px; height: 19px; }
.hud-score-body { display: flex; flex-direction: column; line-height: 1.05; }
.hud-label {
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--ink-mute);
  font-weight: 600;
}
.hud-value {
  font-size: 21px;
  font-weight: 800;
  color: #fff;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 10px var(--theme-glow);
  transition: transform 0.18s ease;
  transform-origin: left center;
}
.hud-value.pop { transform: scale(1.24); }

.hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-left-count {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.04));
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
}
.hud-left-count .mp-icon { width: 17px; height: 17px; color: var(--theme-soft); }

.hud-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.05));
  color: #fff;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transition: transform 0.14s ease, background 0.14s ease;
}
.hud-btn .mp-icon { width: 20px; height: 20px; }
.hud-btn:active { transform: scale(0.9); background: rgba(255, 138, 61, 0.35); }

/* ---------- Board ---------- */
.board-wrap {
  position: relative;
  z-index: 3;
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 12px;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.board {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-lg);
  background:
    radial-gradient(80% 60% at 50% 0%, rgba(255, 138, 61, 0.14), rgba(255, 138, 61, 0) 70%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(255, 255, 255, 0.11);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.13), 0 18px 40px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}
.board-plate {
  position: absolute;
  inset: 10px;
  border-radius: 20px;
  border: 1px dashed rgba(255, 255, 255, 0.09);
  pointer-events: none;
}
.board-inner {
  position: absolute;
  inset: 0;
}

.tile {
  position: absolute;
  display: grid;
  place-items: center;
  border-radius: var(--radius-md);
  background: var(--tile-face);
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.34), inset 0 -3px 0 rgba(0, 0, 0, 0.07);
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, opacity 0.2s ease, filter 0.2s ease;
  will-change: transform;
  transform-origin: center center;
}
.tile .emoji {
  font-size: 1em;
  line-height: 1;
  display: block;
  transform: translateY(1px);
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.16));
}
.tile.locked {
  cursor: default;
  filter: saturate(0.7) brightness(0.8);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}
.tile.locked::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(30, 17, 54, 0.34), rgba(30, 17, 54, 0.52));
  pointer-events: none;
}
.tile.free:hover { transform: translateY(-3px) scale(1.06); box-shadow: 0 14px 24px rgba(0, 0, 0, 0.4); }
.tile.free:active { transform: scale(0.94); }
.tile.gone { opacity: 0; transform: scale(0.4) rotate(8deg); pointer-events: none; }

/* ---------- Fly layer ---------- */
.fly-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 40;
}
.fly-tile {
  position: absolute;
  display: grid;
  place-items: center;
  border-radius: var(--radius-md);
  background: var(--tile-face);
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.42);
  transition: transform 0.34s cubic-bezier(0.34, 1.3, 0.5, 1), opacity 0.34s ease;
  will-change: transform;
}
.fly-tile .emoji { font-size: 1em; line-height: 1; display: block; }

/* ---------- Tray ---------- */
.tray-wrap {
  position: relative;
  z-index: 6;
  flex: 0 0 auto;
  margin-top: 12px;
  padding: 10px 12px 12px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.11), rgba(255, 255, 255, 0.03));
  border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.tray-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 0 4px 8px;
}
.tray-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--theme-soft);
}
.tray-tip {
  font-size: 11px;
  color: var(--ink-mute);
}

.tray {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.slot {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, rgba(20, 11, 38, 0.85), rgba(36, 22, 64, 0.85));
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.45);
  display: grid;
  place-items: center;
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.slot .slot-emoji {
  font-size: 1em;
  line-height: 1;
  display: block;
  animation: slotIn 0.26s cubic-bezier(0.34, 1.4, 0.5, 1) both;
}
.slot.filled {
  background: var(--tile-face);
  border-color: rgba(255, 255, 255, 0.9);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.34);
}
.slot.danger {
  border-color: rgba(255, 92, 92, 0.9);
  box-shadow: 0 0 0 2px rgba(255, 92, 92, 0.35), inset 0 2px 6px rgba(0, 0, 0, 0.4);
}
.slot.clearing .slot-emoji { animation: slotOut 0.3s ease forwards; }

@keyframes slotIn {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes slotOut {
  0% { transform: scale(1); opacity: 1; }
  45% { transform: scale(1.28); opacity: 1; }
  100% { transform: scale(0.2); opacity: 0; }
}

/* ---------- Toast ---------- */
.toast-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 60;
}
.float-score {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 20px;
  font-weight: 800;
  color: #FFD36E;
  text-shadow: 0 2px 10px var(--theme-glow), 0 0 2px rgba(0, 0, 0, 0.6);
  animation: floatUp 0.9s ease-out forwards;
  white-space: nowrap;
}
@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  25% { opacity: 1; transform: translate(-50%, -70%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(1); }
}

/* ---------- Overlay ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(12, 6, 24, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fadeIn 0.24s ease both;
}
.overlay[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.dialog {
  width: 100%;
  max-width: 320px;
  padding: 26px 22px 22px;
  border-radius: var(--radius-lg);
  text-align: center;
  background: linear-gradient(180deg, #3A2560 0%, #241640 100%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 26px 60px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  animation: dialogIn 0.34s cubic-bezier(0.34, 1.35, 0.5, 1) both;
}
@keyframes dialogIn {
  from { opacity: 0; transform: translateY(18px) scale(0.9); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.dialog-badge {
  width: 62px;
  height: 62px;
  margin: -52px auto 12px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--theme-soft), var(--theme-deep));
  box-shadow: 0 10px 24px rgba(255, 138, 61, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  color: #fff;
}
.dialog-badge .mp-icon { width: 30px; height: 30px; }
.dialog-badge.lose {
  background: linear-gradient(180deg, #8E7BB8, #5B4382);
  box-shadow: 0 10px 24px rgba(91, 67, 130, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.dialog-title {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #fff;
  text-shadow: 0 2px 12px rgba(255, 138, 61, 0.45);
}
.dialog-text {
  margin: 0 0 16px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-dim);
}
.dialog-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}
.stat {
  padding: 10px 8px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-label {
  font-size: 11px;
  color: var(--ink-mute);
  letter-spacing: 0.08em;
}
.stat-value {
  font-size: 20px;
  font-weight: 800;
  color: #FFD36E;
  font-variant-numeric: tabular-nums;
}
.dialog-btn {
  width: 100%;
  min-height: 48px;
  border: none;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(180deg, var(--theme-soft), var(--theme-deep));
  box-shadow: 0 10px 22px rgba(255, 138, 61, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}
.dialog-btn:active {
  transform: scale(0.96);
  box-shadow: 0 6px 14px rgba(255, 138, 61, 0.4);
}

/* ---------- 右下角「重新开始」浮动按钮 ---------- */
.restart-fab {
  position: absolute;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 96px);
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.06));
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: transform 0.14s ease, background 0.14s ease;
}
.restart-fab .mp-icon { width: 17px; height: 17px; color: var(--theme-soft); }
.restart-fab:active {
  transform: scale(0.94);
  background: rgba(255, 138, 61, 0.4);
}

/* ---------- 成品图氛围层：把生成图作为背景纹理融入深色舞台 ---------- */
.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: url("images/gen/gptimg_1795345783_look.png");
  background-size: cover;
  background-position: center top;
  opacity: 0.22;
  mix-blend-mode: soft-light;
  filter: saturate(1.15) contrast(1.05);
  z-index: 0;
}

/* 堆放区顶部柔光，让卡片浮起 */
.board::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(70% 40% at 50% 0%, rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0) 70%);
}

/* 卡片更立体的成品感 */
.tile {
  border-radius: 20px;
  box-shadow:
    0 10px 18px rgba(0, 0, 0, 0.36),
    0 2px 0 rgba(255, 255, 255, 0.9) inset,
    0 -4px 0 rgba(214, 178, 138, 0.55) inset;
}
.tile.free::before {
  content: "";
  position: absolute;
  inset: 3px 3px auto 3px;
  height: 38%;
  border-radius: 16px 16px 40% 40%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0));
  pointer-events: none;
  opacity: 0.75;
}

/* 槽位底纹 */
.slot::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(60% 60% at 50% 30%, rgba(255, 138, 61, 0.10), rgba(255, 138, 61, 0) 70%);
  pointer-events: none;
}
.slot.filled::before { display: none; }

/* ---------- 小屏适配与细节打磨 ---------- */
@media (max-height: 700px) {
  .stage { padding-top: calc(env(safe-area-inset-top, 0px) + 8px); }
  .board-wrap { margin-top: 8px; }
  .tray-wrap { margin-top: 8px; padding: 8px 10px 10px; }
  .tray-head { padding-bottom: 6px; }
  .hud-value { font-size: 19px; }
  .hud-btn { width: 38px; height: 38px; }
  .restart-fab { bottom: calc(env(safe-area-inset-bottom, 0px) + 84px); }
}

@media (max-height: 600px) {
  .tray-head { display: none; }
  .tray-wrap { padding: 8px; }
  .hud-score { padding: 5px 14px 5px 6px; }
  .hud-score-icon { width: 28px; height: 28px; }
}

/* 宽屏（平板/桌面预览）时限制游戏区宽度，保持竖屏手感 */
@media (min-width: 560px) {
  .stage {
    max-width: 460px;
    margin: 0 auto;
  }
  body { background: #0E0819; }
}

/* 无障碍：减少动画 */
@media (prefers-reduced-motion: reduce) {
  .bg-glow-a, .bg-glow-b, .bg-stars span { animation: none; }
  .fly-tile { transition-duration: 0.12s; }
}
