/* 光线回路 · Mạch Ánh Sáng — 界面样式（竖屏优先，电脑上居中显示）。v002：GPT 背景图与引导机器人 */
:root {
  --bg-top: #2b1c6e;
  --bg-mid: #1c1350;
  --bg-bot: #0e0a2a;
  --ink: #f6f2ff;
  --ink-2: #cfc6f2;
  --muted: #9d93c9;
  --gold: #f3cf73;
  --gold-2: #e0a940;
  --cyan: #8fe3ff;
  --panel: rgba(30, 22, 78, 0.72);
  --panel-2: rgba(44, 34, 104, 0.8);
  --line: rgba(206, 196, 255, 0.16);
  --shadow: 0 18px 50px rgba(5, 2, 20, 0.55);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  color: var(--ink);
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(140, 90, 255, 0.35), transparent 55%),
    radial-gradient(ellipse at 90% 30%, rgba(80, 200, 255, 0.18), transparent 50%),
    radial-gradient(ellipse at 50% 110%, rgba(255, 120, 200, 0.18), transparent 55%),
    linear-gradient(180deg, var(--bg-top), var(--bg-mid) 55%, var(--bg-bot));
  background-attachment: fixed;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
/* 星空 */
body::before, body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none;
  background-image:
    radial-gradient(1.5px 1.5px at 20px 30px, #fff, transparent),
    radial-gradient(1px 1px at 120px 80px, #fff, transparent),
    radial-gradient(1.5px 1.5px at 200px 160px, #e8dcff, transparent),
    radial-gradient(1px 1px at 60px 200px, #fff, transparent),
    radial-gradient(1px 1px at 260px 40px, #cfe8ff, transparent);
  background-size: 300px 240px;
  opacity: 0.55;
}
body::after { background-size: 420px 330px; background-position: 90px 60px; animation: twinkle 5s ease-in-out infinite alternate; }
@keyframes twinkle { from { opacity: 0.15; } to { opacity: 0.6; } }

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: 0.4; cursor: default; }
[hidden] { display: none !important; }
svg.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: block; }

/* GPT 背景图（竖屏 / 横屏各一张），上面再压一层暗色，保证棋盘和文字清晰 */
.bgArt {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(16, 10, 50, 0.25), rgba(12, 8, 36, 0.5)), url(../assets/art/bg-portrait.jpg) center / cover no-repeat;
}
@media (orientation: landscape) {
  .bgArt { background-image: linear-gradient(180deg, rgba(16, 10, 50, 0.25), rgba(12, 8, 36, 0.5)), url(../assets/art/bg-landscape.jpg); }
}
body::before, body::after { z-index: 1; }
#app { position: fixed; inset: 0; max-width: 640px; margin: 0 auto; z-index: 2; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; padding: calc(10px + var(--safe-t)) 16px calc(10px + var(--safe-b)); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 11px 22px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink);
  font-weight: 800; font-size: 15px; letter-spacing: 0.2px;
  box-shadow: 0 8px 22px rgba(5, 2, 20, 0.35);
  transition: transform 0.15s, background-color 0.15s, border-color 0.15s;
}
.btn:hover { border-color: rgba(206, 196, 255, 0.35); }
.btn:active { transform: scale(0.97); }
.btn.primary {
  border: 0; color: #2a1606;
  background: linear-gradient(180deg, #ffe9a6, var(--gold) 45%, var(--gold-2));
  box-shadow: 0 10px 26px rgba(243, 186, 70, 0.32), inset 0 -3px 0 rgba(150, 90, 20, 0.35);
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; box-shadow: none; }
a.btn { text-decoration: none; }
.btn.lg { min-height: 54px; font-size: 17px; border-radius: 16px; }
.btn:focus-visible, .iconBtn:focus-visible, .tool:focus-visible, .lvCard:focus-visible, .langSwitch button:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
.iconBtn {
  width: 44px; height: 44px; flex: none; border-radius: 50%; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--panel);
}
.iconSpacer { width: 44px; flex: none; }
[data-act="sound"] .ico.off, [data-act="sound"].off .ico.on, [data-act="music"] .ico.off, [data-act="music"].off .ico.on { display: none; }
[data-act="sound"].off .ico.off, [data-act="music"].off .ico.off { display: block; }
.topBtns { display: flex; gap: 8px; }

/* ---------- 首页 ---------- */
.homeScreen { align-items: center; justify-content: space-between; text-align: center; }
.homeTop { width: 100%; display: flex; justify-content: space-between; align-items: center; }
.homeTop .topBtns { margin-left: auto; }
.langSwitch { display: inline-flex; padding: 4px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); }
.langSwitch button { border: 0; background: transparent; padding: 8px 14px; border-radius: 999px; font-weight: 700; font-size: 13px; color: var(--ink-2); }
.langSwitch button[aria-pressed="true"] { background: var(--gold); color: #2a1606; }
.homeHero { display: flex; flex-direction: column; align-items: center; }
.logoWrap {
  width: min(46vw, 190px); aspect-ratio: 1; border-radius: 29%; overflow: hidden;
  box-shadow: 0 0 0 2px rgba(255, 226, 150, 0.6), 0 0 60px rgba(160, 120, 255, 0.55), var(--shadow);
  animation: float 4.5s ease-in-out infinite;
}
.logoWrap img { width: 100%; height: 100%; object-fit: cover; display: block; transform: scale(1.015); }
@keyframes float { 50% { transform: translateY(-8px); } }
.homeHero h1 {
  margin: 26px 0 2px; font-size: clamp(32px, 9vw, 46px); font-weight: 900; letter-spacing: -0.5px; line-height: 1.15;
  background: linear-gradient(180deg, #fff, #ffe6a0 70%, #f0b95a); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 18px rgba(255, 200, 100, 0.35));
}
.subtitle { margin: 14px 0 0; color: var(--ink-2); font-size: 14.5px; }
.homeActions { width: min(340px, 100%); display: flex; flex-direction: column; gap: 12px; }
.homeProgress { margin: 4px 0 0; color: var(--gold); font-weight: 700; font-size: 14px; min-height: 20px; }

/* ---------- 顶栏 ---------- */
.hud { display: flex; align-items: center; gap: 10px; }
.hudTitle { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; text-align: center; }
.hudTitle small { color: var(--gold); font-weight: 800; font-size: 12px; letter-spacing: 1.2px; text-transform: uppercase; }
.hudTitle strong { font-size: 18px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.levelsScreen .hudTitle small { text-transform: none; letter-spacing: 0; }

/* ---------- 选关 ---------- */
.levelGrid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 16px 2px 8px; align-content: start; }
.lvCard {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; text-align: left;
  min-height: 108px; padding: 14px; border-radius: 18px; border: 1px solid var(--line);
  background: linear-gradient(160deg, rgba(70, 54, 150, 0.75), rgba(32, 24, 82, 0.85)); box-shadow: var(--shadow);
  transition: transform 0.15s, border-color 0.15s;
}
.lvCard:active { transform: scale(0.97); }
.lvCard:hover { border-color: rgba(255, 226, 150, 0.5); }
.lvCard.done { border-color: rgba(255, 226, 150, 0.35); }
.lvNum { font-size: 26px; font-weight: 900; color: var(--gold); line-height: 1; }
.lvName { font-weight: 800; font-size: 14.5px; line-height: 1.3; }
.lvStars { display: flex; gap: 2px; margin-top: auto; }
.lvCard.locked { opacity: 0.55; background: rgba(28, 20, 66, 0.8); }
.lvCard.locked .lvNum { color: var(--muted); }
svg.lock { position: absolute; right: 12px; top: 12px; width: 22px; height: 22px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg.star { width: 18px; height: 18px; fill: rgba(255, 255, 255, 0.14); stroke: rgba(255, 255, 255, 0.25); stroke-width: 1; stroke-linejoin: round; }
svg.star.on { fill: var(--gold); stroke: #fff2c4; filter: drop-shadow(0 0 6px rgba(255, 210, 110, 0.7)); }

/* ---------- 游戏 ---------- */
.gameScreen { padding-bottom: calc(8px + var(--safe-b)); }
.hudStats { display: flex; justify-content: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 13px; color: var(--ink-2); font-weight: 700; }
.pill b { color: var(--ink); font-size: 15px; }
.pill.gold { color: var(--gold); border-color: rgba(243, 207, 115, 0.35); }
.pill.crystal svg { width: 14px; height: 14px; fill: var(--cyan); }
.boardWrap { flex: 1; min-height: 0; display: grid; place-items: center; padding: 6px 0; }
#board { display: block; touch-action: manipulation; cursor: pointer; filter: drop-shadow(0 18px 40px rgba(5, 2, 20, 0.6)); }
.tools { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.tool {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 60px; border-radius: 16px; border: 1px solid var(--line); background: var(--panel);
  font-size: 12px; font-weight: 700; color: var(--ink-2); transition: transform 0.12s, background-color 0.15s;
}
.tool:active:not(:disabled) { transform: scale(0.95); background: var(--panel-2); }
.tool .ico { width: 22px; height: 22px; color: var(--ink); }
.tool[data-act="hint"] .ico { color: var(--gold); }
.tool.off .ico { color: var(--muted); }
.tool span { white-space: nowrap; }

/* ---------- 弹层 ---------- */
.overlay { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(8, 4, 26, 0.62); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; } }
.tipCard, .winCard {
  width: min(420px, 100%); border-radius: 22px; padding: 22px; text-align: center;
  background: linear-gradient(170deg, rgba(76, 58, 160, 0.97), rgba(36, 26, 92, 0.98));
  border: 1px solid rgba(255, 226, 150, 0.45); box-shadow: var(--shadow), 0 0 50px rgba(140, 100, 255, 0.35);
  animation: pop 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
@keyframes pop { from { transform: scale(0.85); opacity: 0; } }
.robot { width: 92px; height: 92px; margin: -46px auto 2px; display: block; object-fit: contain; filter: drop-shadow(0 10px 18px rgba(5, 2, 20, 0.5)); animation: float 3s ease-in-out infinite; }
.tipCard, .winCard { margin-top: 30px; }
.tipBody small, .winCard small { color: var(--gold); font-weight: 800; font-size: 12px; letter-spacing: 1px; }
.tipBody h2, .winCard h2 { margin: 4px 0 8px; font-size: 21px; font-weight: 900; }
.tipBody p, .winCard p { margin: 0 0 18px; color: var(--ink-2); line-height: 1.65; font-size: 15px; }
.tipCard .btn { min-width: 160px; }
.winOverlay { position: fixed; }
.winStars { display: flex; justify-content: center; gap: 10px; margin: 10px 0 4px; }
.winStars svg.star { width: 52px; height: 52px; }
.winStars svg.star:nth-child(2) { transform: translateY(-10px); }
.winStars svg.star.pop { animation: starPop 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.5); }
.winStars svg.star:nth-child(2).pop { animation-name: starPop2; }
@keyframes starPop { from { transform: scale(0.2) rotate(-40deg); } }
@keyframes starPop2 { from { transform: translateY(-10px) scale(0.2) rotate(-40deg); } }
.winBtns { display: flex; flex-direction: column; gap: 10px; }

/* ---------- 提示条 ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); z-index: 40; transform: translate(-50%, 20px);
  width: max-content; max-width: min(92vw, 460px); padding: 11px 18px; border-radius: 14px;
  background: rgba(20, 14, 52, 0.94); border: 1px solid rgba(143, 227, 255, 0.4); color: var(--ink);
  font-size: 14px; line-height: 1.5; text-align: center; white-space: pre-line;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 尺寸适配 ---------- */
@media (min-width: 560px) {
  .levelGrid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-height: 640px) {
  .homeHero h1 { margin-top: 14px; }
  .logoWrap { width: min(36vw, 130px); }
  .tool { min-height: 52px; }
  .hudStats { margin-top: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- 动效：背景画布 / 按钮悬停与点击 / 画面切换 ---------- */
#fx { position: fixed; inset: 0; z-index: 1; pointer-events: none; }
body::before, body::after { display: none; } /* 背景星点改由 #fx 画布绘制 */
.btn, .iconBtn, .tool, .lvCard, .langSwitch button { position: relative; overflow: hidden; -webkit-tap-highlight-color: transparent;
  transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.22s, background-color 0.2s, border-color 0.2s, filter 0.2s; }
@media (hover: hover) {
  .btn:hover:not(:disabled), .iconBtn:hover, .tool:hover:not(:disabled), .lvCard:hover:not(.locked), .langSwitch button:hover {
    transform: translateY(-2px);
    border-color: rgba(255, 214, 120, 0.6);
    box-shadow: 0 10px 26px rgba(5, 2, 20, 0.45), 0 0 18px rgba(255, 214, 120, 0.38);
  }
  .btn.primary:hover { box-shadow: 0 12px 30px rgba(243, 186, 70, 0.4), 0 0 22px rgba(255, 220, 140, 0.45); }
  .btn::after, .iconBtn::after, .tool::after, .lvCard::after {
    content: ""; position: absolute; inset: 0; pointer-events: none;
    background: linear-gradient(110deg, transparent 32%, rgba(255, 255, 255, 0.3) 50%, transparent 68%);
    transform: translateX(-130%);
  }
  .btn:hover:not(:disabled)::after, .iconBtn:hover::after, .tool:hover:not(:disabled)::after, .lvCard:hover:not(.locked)::after { animation: sheen 0.75s ease; }
  .tool:hover:not(:disabled) .ico { animation: icoBounce 0.5s ease; }
}
@keyframes sheen { to { transform: translateX(130%); } }
@keyframes icoBounce { 40% { transform: translateY(-3px) scale(1.12); } }
.btn:active:not(:disabled), .iconBtn:active, .tool:active:not(:disabled), .lvCard:active:not(.locked), .langSwitch button:active { transform: scale(0.94); transition-duration: 0.08s; }
/* 点击水波纹 */
.ripple { position: absolute; border-radius: 50%; pointer-events: none; transform: scale(0); z-index: 0;
  background: radial-gradient(circle, rgba(255,240,190,0.6), rgba(255,200,90,0.25) 45%, rgba(255,200,90,0) 70%); animation: ripple 0.6s ease-out forwards; }
@keyframes ripple { to { transform: scale(1); opacity: 0; } }
/* 画面切换、选关卡片依次出现、数字跳动 */
.screen:not([hidden]) { animation: screenIn 0.38s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes screenIn { from { opacity: 0; transform: translateY(14px); } }
.lvCard { animation: cardIn 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.25) both; }
@keyframes cardIn { from { opacity: 0; transform: translateY(16px) scale(0.92); } }
.pill b.bump { display: inline-block; animation: bump 0.35s ease; }
@keyframes bump { 40% { transform: scale(1.45); color: var(--gold); } }
.logoWrap { animation: float 4.5s ease-in-out infinite, logoGlow 3.2s ease-in-out infinite; }
@keyframes logoGlow { 50% { box-shadow: 0 0 0 2px rgba(255, 226, 150, 0.8), 0 0 80px rgba(255, 214, 120, 0.75), 0 18px 50px rgba(5, 2, 20, 0.55); } }
