/* ==========================================================================
   绘境小游戏合集 · 全局样式与多主题系统
   ========================================================================== */

:root,
[data-theme="tide"] {
  --bg: #f2f8f6;
  --bg-accent: radial-gradient(circle at 15% 10%, rgba(16, 185, 165, 0.14), transparent 42%),
               radial-gradient(circle at 85% 90%, rgba(56, 189, 248, 0.12), transparent 44%);
  --surface: rgba(255, 255, 255, 0.88);
  --surface-strong: #ffffff;
  --surface-muted: #e6f2ef;
  --border: rgba(15, 76, 68, 0.12);
  --border-strong: rgba(15, 76, 68, 0.24);
  --text: #102a27;
  --text-muted: #4b6b66;
  --accent: #0d9488;
  --accent-2: #0284c7;
  --accent-soft: rgba(13, 148, 136, 0.12);
  --accent-contrast: #ffffff;
  --star: #f59e0b;
  --danger: #e11d48;
  --shadow: 0 14px 34px rgba(15, 60, 54, 0.08);
  --shadow-sm: 0 4px 12px rgba(15, 60, 54, 0.06);
  --canvas-frame: #0f2523;
}

[data-theme="paper"] {
  --bg: #fbf4e9;
  --bg-accent: radial-gradient(circle at 18% 12%, rgba(234, 88, 12, 0.11), transparent 42%),
               radial-gradient(circle at 88% 85%, rgba(217, 119, 6, 0.1), transparent 44%);
  --surface: rgba(255, 252, 247, 0.9);
  --surface-strong: #fffdf9;
  --surface-muted: #f3e6d3;
  --border: rgba(120, 53, 15, 0.13);
  --border-strong: rgba(120, 53, 15, 0.26);
  --text: #2e1d12;
  --text-muted: #755946;
  --accent: #d94e34;
  --accent-2: #d97706;
  --accent-soft: rgba(217, 78, 52, 0.12);
  --accent-contrast: #ffffff;
  --star: #eab308;
  --danger: #be123c;
  --shadow: 0 14px 34px rgba(112, 54, 18, 0.09);
  --shadow-sm: 0 4px 12px rgba(112, 54, 18, 0.06);
  --canvas-frame: #2a1b13;
}

[data-theme="ribbon"] {
  --bg: #140d18;
  --bg-accent: radial-gradient(circle at 20% 10%, rgba(244, 114, 182, 0.16), transparent 42%),
               radial-gradient(circle at 85% 88%, rgba(168, 85, 247, 0.16), transparent 44%);
  --surface: rgba(31, 20, 38, 0.86);
  --surface-strong: #261830;
  --surface-muted: #332040;
  --border: rgba(244, 114, 182, 0.2);
  --border-strong: rgba(244, 114, 182, 0.4);
  --text: #fdf2f8;
  --text-muted: #cbb2cc;
  --accent: #f472b6;
  --accent-2: #c084fc;
  --accent-soft: rgba(244, 114, 182, 0.16);
  --accent-contrast: #1a0b1e;
  --star: #fde047;
  --danger: #fb7185;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.42);
  --shadow-sm: 0 6px 14px rgba(0, 0, 0, 0.3);
  --canvas-frame: #0c0710;
}

[data-theme="cyber"] {
  --bg: #08101f;
  --bg-accent: radial-gradient(circle at 15% 15%, rgba(0, 245, 212, 0.14), transparent 40%),
               radial-gradient(circle at 85% 85%, rgba(56, 189, 248, 0.16), transparent 42%);
  --surface: rgba(15, 27, 48, 0.86);
  --surface-strong: #13223d;
  --surface-muted: #1b2f52;
  --border: rgba(56, 189, 248, 0.22);
  --border-strong: rgba(0, 245, 212, 0.45);
  --text: #eff6ff;
  --text-muted: #93b4d8;
  --accent: #00e5c3;
  --accent-2: #38bdf8;
  --accent-soft: rgba(0, 229, 195, 0.15);
  --accent-contrast: #06131c;
  --star: #fde047;
  --danger: #fb7185;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.48);
  --shadow-sm: 0 6px 14px rgba(0, 0, 0, 0.32);
  --canvas-frame: #050a14;
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  background-color: var(--bg);
  background-image: var(--bg-accent);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.shell {
  max-width: 1060px;
  margin: 0 auto;
  padding: 16px 16px 48px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Boot */
.boot {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.boot-spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Masthead / Header */
.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-contrast);
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 6px 16px var(--accent-soft);
}

.brand-text {
  min-width: 0;
}
.brand-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.2;
}
.brand-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease;
  user-select: none;
}
.btn:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}
.btn:active {
  transform: translateY(0);
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-contrast);
  border-color: transparent;
  box-shadow: 0 6px 18px var(--accent-soft);
}
.btn-primary:hover {
  filter: brightness(1.06);
  border-color: transparent;
}
.btn-ghost {
  background: transparent;
}
.btn-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.btn-icon {
  padding: 8px 10px;
}

/* Theme switcher dots */
.theme-switcher {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 6px;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
}
.theme-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.theme-dot:hover { transform: scale(1.12); }
.theme-dot.is-active {
  border-color: var(--text);
  transform: scale(1.14);
}

/* Hero Banner on Home */
.hero-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px;
  border-radius: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.hero-stats {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}
.stat-pill {
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 104px;
}
.stat-label {
  font-size: 11px;
  color: var(--text-muted);
}
.stat-value {
  font-size: 20px;
  font-weight: 800;
  margin-top: 2px;
}

/* Game Grid */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(236px, 1fr));
  gap: 16px;
}

.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  cursor: pointer;
}
.game-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
  border-color: var(--accent);
}

.game-thumb {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: var(--canvas-frame);
}
.game-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 14%;
  display: block;
  transition: transform 0.35s ease;
}
.game-card:hover .game-thumb img {
  transform: scale(1.04);
}
.game-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(12, 18, 28, 0.72);
  backdrop-filter: blur(6px);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.game-stars-badge {
  position: absolute;
  bottom: 10px;
  right: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(12, 18, 28, 0.74);
  color: var(--star);
  font-size: 12px;
  font-weight: 700;
}

.game-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.game-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.game-title {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
}
.game-en {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.06em;
}
.game-desc {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
  flex: 1;
}
.progress-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-muted);
  overflow: hidden;
  margin-top: 6px;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.35s ease;
}

/* Play Workspace */
.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 440px) minmax(260px, 1fr);
  gap: 20px;
  align-items: start;
  justify-content: center;
}

@media (max-width: 820px) {
  .play-layout {
    grid-template-columns: 1fr;
  }
}

.stage-wrap {
  position: relative;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  aspect-ratio: 820 / 1200;
  border-radius: 22px;
  overflow: hidden;
  background: var(--canvas-frame);
  border: 2px solid var(--border-strong);
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
}

.stage-wrap canvas,
.stage-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.panel-card h3 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.hud-item {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
}
.hud-label {
  font-size: 11px;
  color: var(--text-muted);
}
.hud-val {
  font-size: 18px;
  font-weight: 800;
  margin-top: 2px;
}

.stage-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.stage-tab {
  flex: 1 1 110px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stage-tab.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.stage-tab-name {
  font-size: 13px;
  font-weight: 700;
}
.stage-tab-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.rules-text {
  margin: 0;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-muted);
}

/* Result Overlay inside Stage */
.stage-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 16, 26, 0.72);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: #ffffff;
  z-index: 20;
  animation: fadeIn 0.25s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: scale(1); } }

.overlay-stars {
  font-size: 34px;
  letter-spacing: 6px;
  color: var(--star);
  margin-bottom: 6px;
  text-shadow: 0 4px 18px rgba(245, 158, 11, 0.5);
}
.overlay-title {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 800;
}
.overlay-sub {
  margin: 0 0 18px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.85);
  max-width: 300px;
  line-height: 1.5;
}
.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

/* Memory Game DOM Grid Layer */
.memory-grid {
  position: absolute;
  inset: 0;
  display: grid;
  gap: 4px;
  padding: 6px;
}
.memory-tile {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  border: 1.5px solid rgba(255, 255, 255, 0.28);
  cursor: pointer;
  perspective: 600px;
  background: transparent;
  padding: 0;
  transition: transform 0.16s ease, border-color 0.2s ease;
}
.memory-tile:active { transform: scale(0.96); }
.memory-tile-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}
.memory-tile.is-flipped .memory-tile-inner,
.memory-tile.is-solved .memory-tile-inner {
  transform: rotateY(180deg);
}
.memory-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: grid;
  place-items: center;
}
.memory-front {
  background-repeat: no-repeat;
}
.memory-front-veil {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.38);
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.82);
  font-size: 22px;
  font-weight: 700;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
.memory-back {
  transform: rotateY(180deg);
  background-repeat: no-repeat;
}
.memory-symbol-pill {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(12, 18, 30, 0.78);
  border: 2px solid #ffffff;
  color: #ffffff;
  display: grid;
  place-items: center;
  font-size: 22px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.45);
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.memory-tile.is-solved {
  border-color: rgba(255, 255, 255, 0.12);
  cursor: default;
}
.memory-tile.is-solved .memory-symbol-pill {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.4);
  pointer-events: none;
}

/* Gallery & Before/After Comparator */
.gallery-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
}
.gallery-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease;
}
.gallery-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
}
.gallery-card.is-locked {
  opacity: 0.72;
}
.gallery-thumb {
  position: relative;
  aspect-ratio: 820 / 1000;
  background: var(--canvas-frame);
  overflow: hidden;
}
.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 12%;
  display: block;
}
.gallery-lock {
  position: absolute;
  inset: 0;
  background: rgba(12, 18, 28, 0.56);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
}
.gallery-meta {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Lightbox Before/After Slider */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(8, 12, 20, 0.84);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.lightbox-inner {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.lightbox-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #ffffff;
}
.compare-box {
  position: relative;
  width: 100%;
  aspect-ratio: 820 / 1200;
  max-height: 76dvh;
  margin: 0 auto;
  border-radius: 18px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: #000;
  user-select: none;
  touch-action: none;
}
.compare-box img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}
.compare-after-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.compare-divider {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  background: #ffffff;
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.65);
  pointer-events: none;
}
.compare-knob {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #ffffff;
  color: #111827;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.compare-tag {
  position: absolute;
  top: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.62);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  pointer-events: none;
}
.compare-tag.left { left: 12px; }
.compare-tag.right { right: 12px; }

/* Studio Configurator */
.studio-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
.studio-stage-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  align-items: center;
}
.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}
.field-input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface-strong);
  font-size: 13px;
}
.upload-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 12px;
  background: var(--surface-muted);
  border: 1px dashed var(--border-strong);
}
.upload-preview {
  width: 48px;
  height: 70px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--canvas-frame);
  flex-shrink: 0;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.92);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  z-index: 200;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.32);
  animation: fadeIn 0.2s ease;
}

.footer-note {
  margin-top: auto;
  padding-top: 12px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

.no-save img,
.no-save canvas {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}
