:root {
  /* 颜色都在 themes.js 里，按主题套上 */
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(120% 80% at 50% 0%, var(--bg1), var(--bg2)) fixed;
  background-color: var(--bg2);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
[hidden] { display: none !important; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---------- 菜单 ---------- */
#menu { overflow-y: auto; }
.menu-inner { width: 100%; max-width: 760px; margin: 0 auto; padding: max(18px, env(safe-area-inset-top)) 16px 40px; }
.menu-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 800; letter-spacing: .5px; }
.brand img { border-radius: 10px; }
.menu-actions { display: flex; gap: 8px; }
.chip {
  padding: 6px 12px; border-radius: 999px; background: var(--panel); border: 1px solid var(--panel-line);
  font-size: 13px; color: var(--muted); min-width: 44px;
}
.chip:hover { color: var(--text); }
.tagline { color: var(--muted); margin: 14px 0 22px; }
h2 { font-size: 15px; font-weight: 700; color: var(--muted); margin: 0 0 12px; letter-spacing: .5px; }

.levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.lv {
  position: relative; text-align: left; padding: 14px 14px 12px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--panel-line);
  transition: transform .15s, background .15s;
}
.lv:not(:disabled):hover { transform: translateY(-2px); background: var(--panel-hover); }
.lv:disabled { opacity: .45; cursor: not-allowed; }
.lv .lv-num { font-size: 22px; font-weight: 800; }
.lv .lv-info { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.lv .lv-stars { display: block; margin-top: 8px; letter-spacing: 2px; color: var(--star-off); font-size: 15px; }
.lv .lv-stars .on { color: var(--accent); }
.lv .lv-best { position: absolute; right: 12px; top: 14px; font-size: 12px; color: var(--muted); }
.lv .lock { position: absolute; right: 12px; top: 12px; width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; }
.lv.current { border-color: var(--current-line); }

.rules { margin: 28px 0 0; padding: 16px 16px 16px 34px; border-radius: var(--radius); background: var(--panel); color: var(--muted); font-size: 13px; }
.rules li + li { margin-top: 6px; }

/* ---------- HUD ---------- */
.hud { display: flex; align-items: center; gap: 10px; padding: max(10px, env(safe-area-inset-top)) 12px 8px; }
.ico { width: 40px; height: 40px; border-radius: 12px; background: var(--panel); border: 1px solid var(--panel-line); display: grid; place-items: center; flex: none; }
.ico svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.hud-mid { flex: 1; min-width: 0; }
.hud-row { display: flex; align-items: center; gap: 8px; font-size: 14px; white-space: nowrap; }
.hud-score { margin-left: auto; color: var(--muted); }
.hud-score b { color: var(--text); font-size: 16px; font-variant-numeric: tabular-nums; }
.gravity-tag { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--tag-bg); color: var(--accent); overflow: hidden; text-overflow: ellipsis; }
.timebar { position: relative; height: 14px; margin-top: 6px; border-radius: 999px; background: var(--track); overflow: hidden; }
.timebar i { position: absolute; inset: 0 auto 0 0; width: 100%; border-radius: inherit; background: var(--time-ok); transition: width .25s linear; }
.timebar.warn i { background: var(--time-warn); }
.timebar.danger i { background: var(--time-danger); animation: blink 1s infinite; }
.timebar span { position: absolute; right: 8px; top: 0; font-size: 11px; line-height: 14px; font-weight: 700; color: var(--time-text); text-shadow: 0 1px 2px rgba(0,0,0,.5); font-variant-numeric: tabular-nums; }
@keyframes blink { 50% { opacity: .55; } }

/* ---------- 棋盘 ---------- */
#stage { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; padding: 4px 8px; }
#board { position: relative; }
#board::before {
  content: ""; position: absolute; inset: var(--pad, 0); border-radius: 12px;
  background: var(--board-bg); box-shadow: inset 0 0 0 1px var(--board-line);
}
#lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; overflow: visible; }

.tile {
  position: absolute; left: 0; top: 0; padding: 2px;
  transition: transform .22s cubic-bezier(.3, .7, .4, 1);
  cursor: pointer;
}
.tile .face {
  position: relative; width: 100%; height: 100%; border-radius: var(--tile-radius);
  background: linear-gradient(180deg, hsl(var(--h) var(--tile-top-s) var(--tile-top-l)), hsl(var(--h) var(--tile-bottom-s) var(--tile-bottom-l)));
  box-shadow: 0 var(--depth, 4px) 0 hsl(var(--h) var(--tile-edge-s) var(--tile-edge-l)), 0 calc(var(--depth, 4px) + 2px) 6px var(--tile-shadow);
  display: grid; place-items: center;
  transform: translateY(calc(var(--depth, 4px) * -1));
  transition: transform .12s, box-shadow .12s;
}
.tile .face span { font-size: var(--fs, 28px); line-height: 1; font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; pointer-events: none; }
.tile:hover .face { filter: brightness(1.04); }
.tile.sel .face {
  transform: translateY(calc(var(--depth, 4px) * -1 - 3px)) scale(1.06);
  box-shadow: 0 0 0 3px var(--accent), 0 calc(var(--depth, 4px) + 3px) 0 hsl(var(--h) var(--tile-edge-s) var(--tile-edge-l)), 0 8px 14px var(--tile-shadow);
  z-index: 3;
}
.tile.hint .face { animation: hint 0.8s ease-in-out infinite; }
@keyframes hint { 50% { box-shadow: 0 0 0 4px var(--green), 0 0 18px var(--green); } }
.tile.bad .face { animation: shake .3s; }
@keyframes shake { 25% { translate: -4px 0; } 75% { translate: 4px 0; } }
.tile.gone { pointer-events: none; z-index: 4; }
.tile.enter { transition: none; }
.tile.enter .face { animation: enter .35s cubic-bezier(.3, 1.4, .5, 1) backwards; animation-delay: var(--delay, 0s); }
@keyframes enter { from { scale: 0; opacity: 0; } }

.combo {
  position: absolute; left: 50%; top: 18%; translate: -50% 0; z-index: 10;
  font-size: 28px; font-weight: 900; color: var(--accent); text-shadow: var(--combo-shadow);
  pointer-events: none; opacity: 0;
}
.combo.show { animation: combo .9s ease-out; }
@keyframes combo { 0% { opacity: 0; transform: scale(.5); } 20% { opacity: 1; transform: scale(1.1); } 70% { opacity: 1; transform: scale(1) translateY(-6px); } 100% { opacity: 0; transform: translateY(-24px); } }

.toast {
  position: absolute; left: 50%; bottom: 14px; translate: -50% 0; z-index: 10;
  padding: 8px 16px; border-radius: 999px; background: var(--toast-bg); font-size: 14px; white-space: nowrap;
  opacity: 0; transition: opacity .25s; pointer-events: none;
}
.toast.show { opacity: 1; }

/* ---------- 底部工具 ---------- */
.tools { display: flex; justify-content: center; gap: 12px; padding: 8px 12px max(12px, env(safe-area-inset-bottom)); }
.tool {
  position: relative; display: flex; align-items: center; gap: 6px;
  padding: 10px 18px; border-radius: 999px; background: var(--panel); border: 1px solid var(--panel-line); font-weight: 600;
}
.tool svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tool em { font-style: normal; font-size: 12px; min-width: 20px; height: 20px; line-height: 20px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); text-align: center; padding: 0 5px; }
.tool:disabled { opacity: .4; cursor: not-allowed; }
.tool:not(:disabled):active { transform: scale(.96); }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: var(--scrim); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.card { width: 100%; max-width: 340px; padding: 24px 20px 20px; border-radius: 20px; background: var(--card); border: 1px solid var(--panel-line); text-align: center; box-shadow: var(--card-shadow); animation: cardin .25s ease-out; }
@keyframes cardin { from { transform: scale(.9); opacity: 0; } }
.card h3 { margin: 0 0 6px; font-size: 24px; }
.card p { margin: 0 0 18px; color: var(--muted); white-space: pre-line; }
.stars { font-size: 40px; letter-spacing: 6px; color: var(--star-off); margin-bottom: 4px; }
.stars span { display: inline-block; }
.stars .on { color: var(--accent); animation: star .4s cubic-bezier(.3, 1.6, .5, 1) backwards; }
.stars .on:nth-child(2) { animation-delay: .15s; }
.stars .on:nth-child(3) { animation-delay: .3s; }
@keyframes star { from { transform: scale(0) rotate(-40deg); } }
.card-btns { display: flex; flex-direction: column; gap: 10px; }
.btn { padding: 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--panel-line); font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn:active { transform: scale(.98); }

/* ---------- 消除效果（连线样式 + 图块消失方式 + 粒子）---------- */
.fx-lines polyline {
  fill: none; stroke: var(--line); stroke-linecap: round; stroke-linejoin: round;
  animation: linefade .38s ease-out forwards;
}
.fx-lines .ln-glow { filter: drop-shadow(0 0 6px var(--line-glow)); }
.fx-lines .ln-dots { filter: drop-shadow(0 0 3px var(--line-glow)); animation: linefade .45s ease-out forwards, march .45s linear infinite; }
.fx-lines .ln-thin { filter: drop-shadow(0 0 4px var(--line-glow)); stroke-dasharray: var(--len) var(--len); animation: draw .16s ease-out backwards, linefade .5s ease-out forwards; }
@keyframes linefade { 0%, 60% { opacity: 1; } 100% { opacity: 0; } }
@keyframes march { to { stroke-dashoffset: calc(var(--gap) * -1); } }
@keyframes draw { from { stroke-dashoffset: var(--len); } }

.tile.gone { pointer-events: none; z-index: 4; }
.tile.v-pop .face { animation: pop .3s ease-in forwards; }
.tile.v-shrink .face { animation: shrink .32s ease-in forwards; }
.tile.v-squish .face { animation: squish .42s ease-in-out forwards; }
.tile.v-float .face { animation: floataway .5s ease-out forwards; }
@keyframes pop { 30% { scale: 1.15; } 100% { scale: 0; opacity: 0; } }
@keyframes shrink { 0% { filter: brightness(1.4); } 100% { scale: 0; rotate: 120deg; opacity: 0; filter: brightness(2); } }
@keyframes squish { 30% { scale: 1.25 .75; } 55% { scale: .85 1.15; } 75% { scale: 1.1 .9; opacity: 1; } 100% { scale: 0; opacity: 0; } }
@keyframes floataway { 100% { translate: 0 -70%; opacity: 0; filter: blur(3px); scale: .9; } }

.pt { position: absolute; left: 0; top: 0; z-index: 6; pointer-events: none; line-height: 1; }
.pt-star { color: var(--c); font-size: var(--sz); translate: -50% -50%; animation: star-fly .6s ease-out forwards; text-shadow: 0 0 6px var(--c); }
@keyframes star-fly { 0% { transform: translate(0, 0) scale(.3); opacity: 1; } 60% { opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) scale(1) rotate(90deg); opacity: 0; } }
.pt-paper { width: var(--sz); height: calc(var(--sz) * .55); margin: calc(var(--sz) * -.27) 0 0 calc(var(--sz) * -.5); background: var(--c); border-radius: 2px; animation: paper .8s cubic-bezier(.2, .6, .4, 1) forwards; }
@keyframes paper {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  45% { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 1; }
  100% { transform: translate(calc(var(--dx) * 1.25), calc(var(--dy) + var(--fall))) rotate(calc(var(--rot) * 2.5)); opacity: 0; }
}

/* ---------- 菜单：主题 + 消除效果 ---------- */
.menu-section { margin-top: 28px; }
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.theme-card {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--radius);
  background: linear-gradient(135deg, var(--bg1), var(--bg2)); color: var(--text); text-align: left;
  border: 2px solid var(--panel-line); transition: transform .15s;
}
.theme-card:hover { transform: translateY(-2px); }
.theme-card.on { border-color: var(--accent); }
.theme-card .minis { display: flex; gap: 4px; flex: none; }
.theme-card .mini { width: 30px; height: 30px; padding: 0; position: relative; }
.theme-card .mini .face { --depth: 3px; font-size: 18px; }
.theme-card .mini .face span { font-size: 18px; }
.theme-card b { display: block; font-size: 15px; }
.theme-card small { display: block; font-size: 12px; color: var(--muted); }
.theme-card .check { position: absolute; right: 10px; top: 8px; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 12px; display: grid; place-items: center; font-weight: 800; }

.fx-row { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
.fx-chips { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; min-width: 220px; }
.fx-chips .chip { font-size: 14px; padding: 7px 14px; }
.fx-chips .chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.fx-demo { position: relative; width: 168px; height: 96px; flex: none; margin: 0 auto; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--panel-line); cursor: pointer; overflow: visible; }
.fx-demo .stage { position: absolute; left: 4px; top: 8px; width: 160px; height: 80px; --fs: 24px; --depth: 3px; }
.fx-demo .tile { cursor: inherit; }
.fx-demo .fx-lines { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 5; }
