:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --accent: #3d9eff;
  --accent-dim: #2563a8;
  --text: #e8eef5;
  --muted: #8b9cb3;
  --danger: #e74c5c;
  --success: #2ecc71;
  --border: #2a3a4f;
}

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

html, body {
  height: 100%;
}

body {
  font-family: "Segoe UI", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.top-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.2rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.top-bar h1 { font-size: 1.25rem; font-weight: 600; }
.subtitle { color: var(--muted); font-size: 0.85rem; font-weight: 400; }
.author-credit {
  margin-left: 0.75rem;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  font-style: italic;
}

.mode-tabs { display: flex; gap: 0.4rem; }
.tab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.4rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}
.tab.active, .tab:hover {
  background: var(--accent-dim);
  color: var(--text);
  border-color: var(--accent);
}

.app-layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sidebar h2 { font-size: 1rem; margin-bottom: 0.25rem; }

.reset-view-btn {
  margin-bottom: 0;
  flex-shrink: 0;
  font-size: 0.78rem;
  padding: 0.45rem 0.5rem;
  white-space: nowrap;
  line-height: 1.2;
}

.sidebar-top-btn {
  margin-top: -0.35rem;
  flex-shrink: 0;
  font-size: 0.78rem;
  padding: 0.45rem 0.5rem;
}

.game-panel {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 14;
  width: min(280px, calc(100% - 1.5rem));
  margin: 0;
  background: rgba(26, 35, 50, 0.92);
  border: 1px solid var(--border);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
}

.game-panel h3 {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.game-panel .primary-btn {
  margin-top: 0.35rem;
}

.query-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  right: auto;
  transform: translate(-50%, -50%);
  z-index: 14;
  width: min(320px, calc(100% - 2rem));
  margin: 0;
  background: rgba(26, 35, 50, 0.92);
  border: 1px solid var(--border);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
  padding: 1rem;
  border-radius: 10px;
}

.query-panel h3 {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.query-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.45rem;
}

.query-field input {
  width: 100%;
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(15, 20, 25, 0.85);
  color: var(--text);
  font-size: 0.9rem;
}

.query-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(61, 158, 255, 0.25);
}

.query-panel .primary-btn {
  margin-top: 0.15rem;
}

.query-hint {
  margin-top: 0.45rem;
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--muted);
}

.query-reopen-btn {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 15;
  padding: 0.5rem 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  background: rgba(37, 99, 168, 0.92);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
  pointer-events: auto;
  transition: background 0.2s ease, transform 0.2s ease;
}

.query-reopen-btn:hover {
  background: rgba(61, 158, 255, 0.95);
  transform: translateY(-1px);
}

.query-reopen-btn.hidden {
  display: none;
}

.query-formula-banner {
  position: absolute;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 14;
  max-width: calc(100% - 9rem);
  padding: 0.45rem 1.1rem;
  border-radius: 999px;
  background: rgba(26, 35, 50, 0.88);
  border: 1px solid rgba(61, 158, 255, 0.55);
  color: #fff;
  font-size: clamp(0.95rem, 2.2vw, 1.15rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
  pointer-events: none;
}

.query-formula-banner.hidden {
  display: none;
}

.game-build-hint {
  position: absolute;
  bottom: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 14;
  padding: 0.42rem 1.15rem;
  border-radius: 999px;
  background: rgba(26, 35, 50, 0.88);
  border: 1px solid rgba(255, 193, 61, 0.55);
  color: #ffd93d;
  font-size: clamp(0.88rem, 2vw, 1.02rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-align: center;
  white-space: nowrap;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
  pointer-events: none;
}

.game-build-hint.hidden {
  display: none;
}

.element-palette-wrap.hidden {
  display: none;
}
.sidebar h3 { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.4rem; }

.sidebar label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.sidebar input[type="range"] { width: 100%; accent-color: var(--accent); }
.checkbox-row { flex-direction: row !important; align-items: center; gap: 0.5rem !important; }

.primary-btn, .danger-btn {
  width: 100%;
  padding: 0.55rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}
.primary-btn { background: var(--accent); color: #fff; }
.primary-btn:hover { background: #5ab0ff; }
.danger-btn { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.danger-btn:hover { background: rgba(231, 76, 92, 0.15); }

.info-panel {
  background: rgba(0,0,0,0.25);
  border-radius: 8px;
  padding: 0.75rem;
  font-size: 0.78rem;
  line-height: 1.5;
}
.info-panel.hidden { display: none; }
#coulomb-readout { color: #a8d4ff; white-space: pre-wrap; font-family: Consolas, monospace; }

.viewport-wrap {
  position: relative;
  min-height: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

.atom-edge-indicators {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 12;
  overflow: hidden;
}

.atom-edge-indicator {
  position: absolute;
  transform: translate(-50%, -50%);
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.atom-edge-indicator.hidden {
  display: none;
}

.atom-edge-arrow {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  width: 7px;
  height: 14px;
  background: linear-gradient(180deg, #a8d8ff 0%, var(--accent) 60%, #2563a8 100%);
  clip-path: polygon(50% 0%, 88% 100%, 12% 100%);
  filter: drop-shadow(0 0 4px rgba(61, 158, 255, 0.85));
  transform: translate(calc(-50% + var(--arrow-ox, 0px)), calc(-50% + var(--arrow-oy, 0px)))
    rotate(var(--arrow-rot, 0deg));
  transform-origin: 50% 96%;
}

.atom-edge-label {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: rgba(37, 99, 168, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.45);
  padding: 1px 6px;
  border-radius: 4px;
  line-height: 1.2;
  white-space: nowrap;
  transform: translate(calc(-50% + var(--label-ox, 0px)), calc(-50% + var(--label-oy, 0px)));
}

.atom-label-layer {
  position: absolute;
  inset: 0;
  overflow: visible;
  pointer-events: none;
  transform: translateZ(0);
}

.atom-label {
  color: #d8dee8;
  font-size: 13px;
  font-weight: 500;
  font-family: "Segoe UI", "Microsoft JhengHei", sans-serif;
  white-space: nowrap;
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.95), 0 1px 2px rgba(0, 0, 0, 0.9);
  pointer-events: none;
  user-select: none;
  transform: translate(-2px, -50%) translateZ(0);
  backface-visibility: hidden;
  will-change: transform, opacity;
  transition: opacity 0.12s ease;
}
#viewport {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}
#viewport:active { cursor: grabbing; }

.element-palette-wrap {
  --palette-font-scale: 1;
  flex-shrink: 0;
  background: var(--panel);
  border-top: 2px solid var(--accent);
  z-index: 50;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.45);
  max-height: 42vh;
  display: flex;
  flex-direction: column;
  margin-top: 0.85rem;
  padding-bottom: 0.65rem;
}

.palette-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.45rem 1rem 0;
  flex-wrap: wrap;
}

.palette-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
  flex-shrink: 0;
  margin: 0;
}

.palette-drag-hint {
  font-weight: 800;
  color: var(--text);
}

.palette-font-control {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.palette-font-control span {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.palette-font-control output {
  min-width: 2.7rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.palette-font-control input[type="range"] {
  width: 120px;
}

.element-palette {
  display: grid;
  grid-template-columns: repeat(var(--pt-cols, 18), minmax(44px, 1fr));
  grid-template-rows: repeat(var(--pt-rows, 9), minmax(40px, auto));
  gap: 2px;
  padding: 0.5rem 0.75rem 0.75rem;
  overflow: auto;
  flex: 1;
  min-height: 220px;
  scrollbar-width: thin;
  scrollbar-color: var(--accent-dim) transparent;
}

.element-palette::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.element-palette::-webkit-scrollbar-thumb {
  background: var(--accent-dim);
  border-radius: 3px;
}

.element-chip {
  padding: 0;
  border-radius: 3px;
  width: 100%;
  height: 100%;
  min-height: 40px;
  min-width: 0;
  cursor: grab;
  border: 1px solid rgba(0, 0, 0, 0.12);
  transition:
    transform 0.25s cubic-bezier(0.34, 1.35, 0.64, 1),
    box-shadow 0.25s ease;
  transform-origin: center center;
  user-select: none;
  overflow: hidden;
  container-type: size;
  position: relative;
  z-index: 1;
}
.element-chip:hover {
  transform: scale(1.12);
  box-shadow: 0 0 0 2px var(--accent);
  z-index: 3;
}

.element-chip.series-trigger {
  cursor: pointer;
  border: 2px dashed rgba(255, 255, 255, 0.5);
}

.element-chip.series-trigger:hover {
  transform: scale(1.06);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.65), 0 0 12px rgba(61, 158, 255, 0.45);
}

@keyframes series-remind-lanthanide {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(61, 158, 255, 0); }
  35% { transform: scale(1.14); box-shadow: 0 0 0 3px rgba(61, 158, 255, 0.95), 0 0 18px rgba(137, 207, 240, 0.75); }
  70% { transform: scale(1.08); box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85); }
}

@keyframes series-remind-actinide {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
  35% { transform: scale(1.14); box-shadow: 0 0 0 3px rgba(46, 204, 113, 0.95), 0 0 18px rgba(152, 216, 170, 0.75); }
  70% { transform: scale(1.08); box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85); }
}

.element-chip.series-remind-lanthanide {
  animation: series-remind-lanthanide 0.55s ease-in-out 3;
  z-index: 5;
}

.element-chip.series-remind-actinide {
  animation: series-remind-actinide 0.55s ease-in-out 3;
  z-index: 5;
}

.chip-inner {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  grid-template-areas:
    "num sym"
    "zh zh";
  align-items: center;
  width: 100%;
  height: 100%;
  padding: 1px 2px 2px;
  box-sizing: border-box;
  gap: 1px 0;
}

.chip-inner.series-trigger-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  gap: 0;
}

/* 文字以容器高度（cqh）縮放，避免大螢幕上格子變大但字仍固定極小 */
.series-trigger-inner .series-label {
  font-size: clamp(
    calc(8px * var(--palette-font-scale)),
    calc(28cqh * var(--palette-font-scale)),
    calc(18px * var(--palette-font-scale))
  );
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  letter-spacing: 0.04em;
}

.element-chip .num {
  grid-area: num;
  justify-self: start;
  font-size: clamp(
    calc(5px * var(--palette-font-scale)),
    calc(18cqh * var(--palette-font-scale)),
    calc(13px * var(--palette-font-scale))
  );
  line-height: 1;
  opacity: 0.85;
  font-variant-numeric: tabular-nums;
}

.element-chip .sym {
  grid-area: sym;
  justify-self: end;
  font-weight: 700;
  font-size: clamp(
    calc(8px * var(--palette-font-scale)),
    calc(32cqh * var(--palette-font-scale)),
    calc(22px * var(--palette-font-scale))
  );
  line-height: 1;
}

.element-chip .name-zh {
  grid-area: zh;
  font-size: clamp(
    calc(6px * var(--palette-font-scale)),
    calc(24cqh * var(--palette-font-scale)),
    calc(16px * var(--palette-font-scale))
  );
  line-height: 1.05;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 格子偏小：只保留序數、符號 */
@container (max-height: 34px) {
  .element-chip .name-zh { display: none; }
  .chip-inner {
    grid-template-areas: "num sym";
    grid-template-rows: 1fr;
    align-content: center;
  }
}

@media (max-width: 720px) {
  .palette-header {
    align-items: flex-start;
    gap: 0.45rem;
  }

  .palette-font-control {
    width: 100%;
    justify-content: space-between;
  }

  .palette-font-control input[type="range"] {
    flex: 1;
    max-width: 180px;
  }
}

.atom-selected { outline: 3px solid #ffeb3b !important; }

.toast {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(46, 204, 113, 0.95);
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  z-index: 20;
  max-width: 90%;
  text-align: center;
}
.toast.hidden { display: none; }

.toast.victory-toast {
  z-index: 25;
  padding: 1rem 2rem;
  font-size: 1.05rem;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.65);
  box-shadow:
    0 0 24px rgba(255, 215, 64, 0.75),
    0 0 48px rgba(46, 204, 113, 0.45),
    0 8px 32px rgba(0, 0, 0, 0.35);
  background: linear-gradient(135deg, rgba(46, 204, 113, 0.98), rgba(39, 174, 96, 0.98));
  animation: victory-toast-pop 0.65s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes victory-toast-pop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.4) rotate(-4deg); }
  70% { transform: translateX(-50%) scale(1.08) rotate(1deg); }
  100% { opacity: 1; transform: translateX(-50%) scale(1) rotate(0deg); }
}

.viewport-wrap.victory-shake {
  animation: victory-shake 0.55s ease-out;
}

@keyframes victory-shake {
  0%, 100% { transform: translate(0, 0); }
  15% { transform: translate(-4px, 2px); }
  30% { transform: translate(4px, -3px); }
  45% { transform: translate(-3px, -2px); }
  60% { transform: translate(3px, 3px); }
  75% { transform: translate(-2px, 1px); }
}

.victory-fx {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 18;
  overflow: hidden;
}
.victory-fx.hidden { display: none; }

.victory-flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 45%, rgba(255, 255, 220, 0.85) 0%, rgba(255, 215, 64, 0.35) 35%, transparent 70%);
  animation: victory-flash 0.9s ease-out forwards;
}

@keyframes victory-flash {
  0% { opacity: 0; transform: scale(0.6); }
  20% { opacity: 1; transform: scale(1.05); }
  100% { opacity: 0; transform: scale(1.4); }
}

.victory-rays {
  position: absolute;
  left: 50%;
  top: 42%;
  width: 140vmax;
  height: 140vmax;
  transform: translate(-50%, -50%);
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    rgba(255, 215, 64, 0.12) 15deg,
    transparent 30deg,
    transparent 45deg,
    rgba(255, 107, 214, 0.1) 60deg,
    transparent 75deg,
    transparent 90deg,
    rgba(77, 150, 255, 0.12) 105deg,
    transparent 120deg,
    transparent 135deg,
    rgba(107, 203, 119, 0.1) 150deg,
    transparent 165deg,
    transparent 180deg,
    rgba(255, 107, 107, 0.12) 195deg,
    transparent 210deg,
    transparent 225deg,
    rgba(255, 215, 64, 0.1) 240deg,
    transparent 255deg,
    transparent 270deg,
    rgba(165, 94, 234, 0.12) 285deg,
    transparent 300deg,
    transparent 315deg,
    rgba(0, 210, 211, 0.1) 330deg,
    transparent 345deg,
    transparent 360deg
  );
  animation: victory-rays-in 0.4s ease-out forwards, victory-rays-spin 3s linear 0.2s infinite;
}

@keyframes victory-rays-in {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.3); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes victory-rays-spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

.victory-banner {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  text-align: center;
  animation: victory-banner-in 0.75s cubic-bezier(0.34, 1.45, 0.64, 1) 0.15s both;
}

@keyframes victory-banner-in {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.2); filter: blur(8px); }
  60% { transform: translate(-50%, -50%) scale(1.12); filter: blur(0); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.victory-sub {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.35em;
  color: #ffd93d;
  text-shadow: 0 0 12px rgba(255, 217, 61, 0.9);
}

.victory-title {
  font-size: clamp(1.8rem, 5vw, 3rem);
  font-weight: 900;
  background: linear-gradient(90deg, #fff 0%, #ffd93d 35%, #ff6bd6 65%, #4d96ff 100%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: victory-title-shine 1.8s linear infinite;
  filter: drop-shadow(0 0 16px rgba(255, 215, 64, 0.8)) drop-shadow(0 2px 8px rgba(0, 0, 0, 0.5));
}

@keyframes victory-title-shine {
  to { background-position: 200% center; }
}

.victory-formula {
  font-size: 1.35rem;
  font-weight: 700;
  color: #fff;
  padding: 0.25rem 1.2rem;
  border-radius: 999px;
  background: rgba(61, 158, 255, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 0 20px rgba(61, 158, 255, 0.6);
}

.grand-finale-fx {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 20;
  overflow: hidden;
}

.grand-finale-fx.hidden { display: none; }

.grand-finale-banner {
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  text-align: center;
  padding: 1.2rem 2rem;
  animation: grand-finale-in 1s cubic-bezier(0.34, 1.45, 0.64, 1) 0.15s both;
}

@keyframes grand-finale-in {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.15) rotate(-8deg); filter: blur(10px); }
  55% { transform: translate(-50%, -50%) scale(1.14) rotate(2deg); filter: blur(0); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0deg); }
}

.grand-finale-en {
  font-size: clamp(2rem, 7vw, 4rem);
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.04em;
  background: linear-gradient(90deg, #fff 0%, #ffd93d 30%, #ff6bd6 55%, #4d96ff 80%, #fff 100%);
  background-size: 220% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: victory-title-shine 1.4s linear infinite;
  filter: drop-shadow(0 0 22px rgba(255, 215, 64, 0.95)) drop-shadow(0 3px 10px rgba(0, 0, 0, 0.55));
}

.grand-finale-zh {
  font-size: clamp(1.35rem, 4.2vw, 2.25rem);
  font-weight: 800;
  color: #fff;
  padding: 0.45rem 1.4rem;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(255, 107, 214, 0.55), rgba(61, 158, 255, 0.55));
  border: 2px solid rgba(255, 255, 255, 0.65);
  box-shadow:
    0 0 28px rgba(255, 107, 214, 0.55),
    0 0 40px rgba(61, 158, 255, 0.35);
  animation: grand-finale-zh-pulse 1.6s ease-in-out infinite;
}

@keyframes grand-finale-zh-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 28px rgba(255, 107, 214, 0.55), 0 0 40px rgba(61, 158, 255, 0.35); }
  50% { transform: scale(1.05); box-shadow: 0 0 36px rgba(255, 215, 64, 0.75), 0 0 48px rgba(61, 158, 255, 0.5); }
}

.level-banner {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 22;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.level-banner.hidden { display: none; }

.level-banner-track {
  width: 100%;
  display: flex;
  justify-content: center;
}

.level-banner-inner {
  display: flex;
  align-items: baseline;
  gap: 0.2em;
  padding: 0.7rem 4rem;
  min-width: min(420px, 88vw);
  justify-content: center;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(37, 99, 168, 0.75) 12%,
    rgba(61, 158, 255, 0.95) 50%,
    rgba(37, 99, 168, 0.75) 88%,
    transparent 100%
  );
  border-top: 2px solid rgba(255, 255, 255, 0.55);
  border-bottom: 2px solid rgba(255, 255, 255, 0.55);
  box-shadow:
    0 0 48px rgba(61, 158, 255, 0.55),
    0 8px 32px rgba(0, 0, 0, 0.35);
  transform: translateX(-115%) scale(0.92);
  opacity: 0;
}

.level-banner-in .level-banner-inner {
  animation: level-banner-enter 0.7s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.level-banner-out .level-banner-inner {
  animation: level-banner-exit 0.55s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

@keyframes level-banner-enter {
  0% { transform: translateX(-115%) scale(0.88); opacity: 0; }
  65% { transform: translateX(3%) scale(1.03); opacity: 1; }
  100% { transform: translateX(0) scale(1); opacity: 1; }
}

@keyframes level-banner-exit {
  0% { transform: translateX(0) scale(1); opacity: 1; }
  100% { transform: translateX(115%) scale(0.88); opacity: 0; }
}

.level-banner-prefix {
  font-size: clamp(1.4rem, 3.5vw, 2rem);
  font-weight: 800;
  color: rgba(255, 255, 255, 0.88);
  letter-spacing: 0.08em;
  text-shadow: 0 0 12px rgba(255, 255, 255, 0.45);
}

.level-banner-num {
  font-size: clamp(2.6rem, 7vw, 4rem);
  font-weight: 900;
  line-height: 1;
  color: #fff;
  text-shadow:
    0 0 24px rgba(255, 255, 255, 0.85),
    0 2px 8px rgba(0, 0, 0, 0.45);
}

.fireworks {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 19;
  overflow: hidden;
}
.fireworks.hidden { display: none; }

.fw-particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: fw-burst var(--dur, 0.9s) ease-out forwards;
}

@keyframes fw-burst {
  0% { opacity: 1; transform: translate(0, 0) scale(1.2); }
  100% { opacity: 0; transform: translate(var(--tx), var(--ty)) scale(0); }
}

.fw-confetti {
  position: absolute;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  opacity: 0.95;
  animation: fw-confetti-fall var(--fall-dur, 2.8s) ease-in var(--fall-delay, 0s) forwards;
}

@keyframes fw-confetti-fall {
  0% { opacity: 1; transform: translateY(0) translateX(0) rotate(0deg); }
  100% {
    opacity: 0;
    transform: translateY(110vh) translateX(var(--sway, 0px)) rotate(var(--spin, 360deg));
  }
}

.fw-spark {
  position: absolute;
  width: 20px;
  height: 20px;
  font-size: 18px;
  line-height: 1;
  opacity: 0;
  animation: fw-spark-pop 1.1s ease-out var(--spark-delay, 0s) forwards;
}

.fw-spark::before {
  content: '✦';
  color: inherit;
  text-shadow: 0 0 10px currentColor;
}

@keyframes fw-spark-pop {
  0% { opacity: 0; transform: scale(0) rotate(0deg); }
  30% { opacity: 1; transform: scale(1.4) rotate(45deg); }
  100% { opacity: 0; transform: scale(0.2) rotate(180deg); }
}

.fw-ring {
  position: absolute;
  left: 50%;
  top: 42%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border: 3px solid rgba(255, 215, 64, 0.85);
  border-radius: 50%;
  box-shadow: 0 0 20px rgba(255, 215, 64, 0.6), inset 0 0 12px rgba(255, 255, 255, 0.3);
  animation: fw-ring-expand 1.4s ease-out var(--ring-delay, 0s) forwards;
}

@keyframes fw-ring-expand {
  0% { opacity: 0.95; transform: scale(0.2); }
  100% { opacity: 0; transform: scale(18); }
}

.particle {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  animation: burst 1.2s ease-out forwards;
}

@keyframes burst {
  0% { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--tx), var(--ty)) scale(0); }
}

hr { border: none; border-top: 1px solid var(--border); }

@media (max-width: 768px) {
  .app-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 200px; border-right: none; border-bottom: 1px solid var(--border); }
}
