/* Kawaii Sort — Light Pastel Glassmorphic Theme */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-0: #f0f2f8;
  --bg-1: #e8ecf4;
  --bg-2: #dfe4ef;
  --panel: rgba(255,255,255,0.65);
  --panel-2: rgba(255,255,255,0.85);
  --glass: rgba(255,255,255,0.45);
  --glass-border: rgba(255,255,255,0.7);
  --accent: #ff6b8a;
  --accent-2: #ff8a5c;
  --accent-grad: linear-gradient(135deg, #ff6b8a 0%, #ff8a5c 100%);
  --accent-glow: rgba(255,107,138,0.35);
  --cyan: #7de8d8;
  --cyan-glow: rgba(125,232,216,0.4);
  --text: #2d2d3f;
  --text-dim: #6b6b82;
  --text-mute: #9e9eb5;
  --danger: #ff5b7a;
  --ok: #6dd5a0;
  --shadow-soft: 0 8px 32px rgba(100,100,140,0.12);
  --shadow-medium: 0 12px 40px rgba(100,100,140,0.18);
}

html, body {
  height: 100%;
  font-family: "Nunito", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

body {
  background:
    radial-gradient(ellipse at 20% 15%, rgba(255,182,217,0.3) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 75%, rgba(125,232,216,0.25) 0%, transparent 55%),
    radial-gradient(ellipse at 50% 50%, rgba(200,190,255,0.2) 0%, transparent 70%),
    linear-gradient(180deg, #f5f0fa 0%, #e8f4f8 50%, #f0f2f8 100%);
  background-attachment: fixed;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* ============ Screen 基础 ============ */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  animation: screenIn 0.35s cubic-bezier(.2,.9,.3,1);
}
.screen.active { display: flex; }

@keyframes screenIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* 通用屏幕头 — Glassmorphic */
.screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  border-bottom: 1px solid rgba(255,255,255,0.6);
  background: rgba(255,255,255,0.5);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.screen-header h2 {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: 1px;
}
.screen-header > span { width: 44px; }

/* ============ 按钮 — Glassmorphic Toolkit ============ */
.btn-primary {
  font-family: inherit;
  font-weight: 800;
  font-size: 16px;
  padding: 14px 32px;
  border: none;
  color: #fff;
  background: linear-gradient(135deg, #ff6b8a 0%, #ff8a5c 50%, #ffaa44 100%);
  border-radius: 999px;
  cursor: pointer;
  box-shadow:
    0 4px 0 rgba(200,60,80,0.35),
    0 8px 24px rgba(255,107,138,0.35);
  transition: transform .1s ease, box-shadow .1s ease;
  letter-spacing: 1px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.btn-primary:hover  { filter: brightness(1.05); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(200,60,80,0.35), 0 4px 12px rgba(255,107,138,0.25); }
.btn-primary.big    { font-size: 22px; padding: 18px 52px; }
.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  filter: grayscale(0.3);
}

.btn-secondary {
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  padding: 12px 24px;
  border: 2px solid var(--accent);
  background: rgba(255,255,255,0.6);
  backdrop-filter: blur(10px);
  color: var(--accent);
  border-radius: 999px;
  cursor: pointer;
  transition: all .15s;
}
.btn-secondary:hover { background: rgba(255,107,138,0.1); }

.icon-btn {
  font-family: inherit;
  font-size: 18px;
  color: var(--text);
  background: rgba(255,255,255,0.5);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.7);
  width: 44px; height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all .12s;
  box-shadow: 0 2px 8px rgba(100,100,140,0.1);
}
.icon-btn:hover { background: rgba(255,255,255,0.75); box-shadow: 0 4px 12px rgba(100,100,140,0.15); }
.icon-btn:active { transform: scale(0.94); }

/* ============ Lobby ============ */
#screenLobby .lobby-inner {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  padding: 24px 20px 32px;
}
.lobby-logo { text-align: center; }
.lobby-logo h1 {
  font-size: 52px;
  font-weight: 900;
  letter-spacing: 4px;
  background: linear-gradient(135deg, #ff6b8a 0%, #ff8a5c 50%, #ffaa44 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 rgba(200,60,80,0.2));
}
.lobby-logo .subtitle {
  font-size: 15px;
  color: var(--text-dim);
  letter-spacing: 2px;
  margin-top: 6px;
  font-weight: 600;
}

.lobby-preview {
  background: rgba(255,255,255,0.45);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.7);
  border-radius: 28px;
  padding: 20px;
  box-shadow:
    0 20px 60px rgba(100,100,140,0.12),
    inset 0 1px 0 rgba(255,255,255,0.8);
}
#lobbyCanvas {
  display: block;
  border-radius: 18px;
}

.top-right {
  position: absolute;
  top: 20px; right: 20px;
}
.coin-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.6);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.7);
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--text);
  font-weight: 800;
  font-size: 15px;
  box-shadow: 0 4px 14px rgba(100,100,140,0.1);
}
.coin-pill.small { padding: 6px 10px; font-size: 13px; }
.coin-icon { font-size: 16px; }

.bottom-nav {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.nav-item {
  font-family: inherit;
  width: 84px;
  padding: 12px 8px;
  background: rgba(255,255,255,0.55);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,0.7);
  border-radius: 20px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all .12s;
  box-shadow: 0 4px 16px rgba(100,100,140,0.08);
}
.nav-item:hover  { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(100,100,140,0.15); background: rgba(255,255,255,0.75); }
.nav-item:active { transform: translateY(0); }
.nav-icon { font-size: 26px; }
.nav-label { font-size: 12px; color: var(--text-dim); font-weight: 700; }

/* ============ Level Select ============ */
.level-grid {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px 48px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 18px;
  align-content: start;
}
.level-card {
  position: relative;
  aspect-ratio: 3/4;
  background: rgba(255,255,255,0.55);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,0.7);
  border-radius: 22px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all .15s;
  user-select: none;
  box-shadow: 0 6px 20px rgba(100,100,140,0.1);
}
.level-card.locked {
  opacity: 0.5;
  cursor: not-allowed;
  border-style: dashed;
  border-color: rgba(150,150,180,0.3);
}
.level-card:not(.locked):hover {
  transform: translateY(-4px);
  box-shadow: 0 14px 36px rgba(255,107,138,0.18);
  border-color: var(--accent);
}
.level-card .num {
  font-size: 36px;
  font-weight: 900;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.level-card .name {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
  padding: 0 6px;
  text-align: center;
  font-weight: 600;
}
.level-card.locked .num { color: var(--text-mute); background: none; -webkit-background-clip: unset; }
.level-card .lock-icon {
  position: absolute;
  bottom: 10px;
  right: 10px;
  font-size: 18px;
  opacity: 0.7;
}
.level-card .star-row {
  position: absolute;
  top: 10px;
  left: 0; right: 0;
  text-align: center;
  font-size: 12px;
  color: #ffb347;
  letter-spacing: 2px;
}

/* ============ Game 页 ============ */
.game-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  background: rgba(255,255,255,0.5);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(255,255,255,0.6);
  z-index: 3;
}
.hud-left  { display: flex; align-items: center; gap: 12px; }
.hud-right { display: flex; align-items: center; gap: 8px; }
.level-label { display: flex; flex-direction: column; line-height: 1.1; }
.level-num   { font-size: 18px; font-weight: 800; color: var(--text); letter-spacing: 2px; }
.level-sub   { font-size: 12px; color: var(--text-dim); margin-top: 2px; font-weight: 600; }
.moves-pill {
  background: rgba(255,255,255,0.5);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.6);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 600;
}
.moves-pill b { color: var(--accent); font-size: 15px; margin-left: 4px; }
.score-pill b { color: #a78bfa; }
.timer-pill b { color: var(--cyan); }

/* Combo popup */
.combo-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 42px;
  font-weight: 900;
  background: linear-gradient(135deg, #ff6b8a, #ffaa44);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  pointer-events: none;
  z-index: 100;
  opacity: 0;
  transition: none;
  text-shadow: none;
  filter: drop-shadow(0 2px 8px rgba(255,107,138,0.4));
}
.combo-popup.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  animation: comboPop 0.8s cubic-bezier(.2,1.4,.4,1) forwards;
}
.combo-popup.hidden { display: none; }

@keyframes comboPop {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.3); }
  20%  { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
  50%  { opacity: 1; transform: translate(-50%, -55%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(0.8); }
}

/* Win stats row */
.win-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 18px;
  font-size: 15px;
  color: var(--text-dim);
  font-weight: 600;
}
.win-stat b { color: var(--accent); font-size: 17px; }
.win-stat-sep { color: var(--text-mute); }

/* Hint highlight pulse */
@keyframes hintPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,107,138,0); }
  50% { box-shadow: 0 0 20px 6px rgba(255,107,138,0.5); }
}

.game-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
}
#game {
  max-width: 100%;
  max-height: 100%;
  border-radius: 24px;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255,182,217,0.15), transparent 55%),
    radial-gradient(ellipse at 70% 80%, rgba(125,232,216,0.12), transparent 55%),
    linear-gradient(180deg, #f5f0fa 0%, #edf5f8 50%, #f0f2f8 100%);
  box-shadow: 0 20px 60px rgba(100,100,140,0.15), inset 0 1px 0 rgba(255,255,255,0.8);
  cursor: pointer;
}

/* ============ Shop ============ */
.shop-tabs {
  display: flex;
  gap: 8px;
  padding: 14px 22px 0;
}
.shop-tab {
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 10px 16px;
  background: rgba(255,255,255,0.4);
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.6);
  border-radius: 999px;
  cursor: pointer;
  transition: all .12s;
  backdrop-filter: blur(8px);
}
.shop-tab:hover  { color: var(--text); background: rgba(255,255,255,0.6); }
.shop-tab.active { background: var(--accent-grad); color: #fff; border-color: transparent; }

.shop-grid {
  flex: 1;
  overflow-y: auto;
  padding: 22px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 14px;
  align-content: start;
}
.shop-card {
  aspect-ratio: 1/1;
  background: rgba(255,255,255,0.5);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.7);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all .12s;
  font-size: 40px;
  color: var(--text-mute);
  box-shadow: 0 4px 16px rgba(100,100,140,0.08);
}
.shop-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(100,100,140,0.15); }
.shop-card .price { font-size: 12px; color: var(--accent); font-weight: 700; margin-top: 4px; }

/* ============ Theme Picker ============ */
.shop-grid.theme-mode {
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}
.theme-card {
  background: rgba(255,255,255,0.55);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,0.7);
  border-radius: 22px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: pointer;
  transition: all .18s;
  position: relative;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(100,100,140,0.08);
}
.theme-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(100,100,140,0.15);
}
.theme-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255,107,138,0.25), 0 10px 28px rgba(100,100,140,0.15);
}
.theme-card .theme-preview {
  width: 100%;
  height: auto;
  border-radius: 14px;
  display: block;
  background: linear-gradient(135deg, #f5f0fa, #edf5f8);
}
.theme-card .theme-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.theme-card .theme-name {
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
}
.theme-card .theme-tagline {
  font-size: 12px;
  color: var(--text-mute);
}
.theme-card .theme-status {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  text-align: right;
}
.theme-card:not(.active) .theme-status { color: var(--text-mute); }

.shop-footer {
  padding: 14px 22px 22px;
  text-align: center;
}

/* ============ Settings / Language ============ */
.settings-list, .lang-list {
  list-style: none;
  padding: 10px 18px 28px;
  overflow-y: auto;
  flex: 1;
}
.settings-list li, .lang-list li {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  margin-bottom: 10px;
  background: rgba(255,255,255,0.55);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.7);
  border-radius: 16px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  transition: all .12s;
  box-shadow: 0 2px 10px rgba(100,100,140,0.06);
}
.settings-list li:hover, .lang-list li:hover {
  background: rgba(255,255,255,0.75);
  transform: translateX(3px);
}
.settings-list li .icon { font-size: 20px; }
.settings-list li .chev {
  margin-left: auto;
  color: var(--text-mute);
  font-size: 20px;
}
.lang-list li.active {
  background: rgba(255,107,138,0.1);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}

/* ============ Overlay (胜利 / 提示) ============ */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(240, 240, 250, 0.7);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: fadeIn 0.3s ease;
}
.overlay.hidden { display: none; }

.overlay-box {
  background: rgba(255,255,255,0.8);
  backdrop-filter: blur(24px);
  border: 1px solid rgba(255,255,255,0.9);
  border-radius: 32px;
  padding: 40px 52px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(100,100,140,0.2), inset 0 1px 0 rgba(255,255,255,0.95);
  max-width: 92%;
  animation: popIn .45s cubic-bezier(.2,1.4,.4,1);
}
.overlay-box h1 {
  font-size: 42px;
  font-weight: 900;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 6px;
  letter-spacing: 1px;
}
.overlay-box h2 {
  font-size: 24px;
  color: var(--text);
  margin-bottom: 12px;
  font-weight: 800;
}
.overlay-box .sub {
  font-size: 15px;
  color: var(--text-dim);
  margin-bottom: 22px;
  font-weight: 600;
}
.overlay-box .row {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.overlay-box .win-stars {
  font-size: 42px;
  letter-spacing: 6px;
  margin-bottom: 10px;
}
.overlay-box .toast-icon {
  font-size: 48px;
  margin-bottom: 10px;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
  0%   { transform: scale(0.6) translateY(14px); opacity: 0; }
  100% { transform: scale(1)   translateY(0);    opacity: 1; }
}

/* ============ Orientation Overlay ============ */
.overlay-box.orient {
  max-width: 360px;
}
.orient-icon {
  color: var(--text);
  margin-bottom: 12px;
}
.orient-icon svg {
  display: inline-block;
}

/* ============ Safe area insets (notch phones) ============ */
@supports (padding: env(safe-area-inset-top)) {
  .screen-header, .game-hud {
    padding-top: calc(16px + env(safe-area-inset-top));
    padding-left: calc(22px + env(safe-area-inset-left));
    padding-right: calc(22px + env(safe-area-inset-right));
  }
  .bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
  }
  .game-main {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    padding-left: calc(16px + env(safe-area-inset-left));
    padding-right: calc(16px + env(safe-area-inset-right));
  }
}

/* ============ 小屏适配 ============ */
@media (max-width: 640px) {
  .lobby-logo h1 { font-size: 40px; letter-spacing: 3px; }
  .level-grid, .shop-grid { grid-template-columns: repeat(auto-fill, minmax(98px, 1fr)); gap: 12px; padding: 16px; }
  .overlay-box { padding: 28px 30px; }
  .overlay-box h1 { font-size: 32px; }
  .btn-primary.big { font-size: 18px; padding: 14px 36px; }
  .hud-left .level-sub { display: none; }
}

/* ============ 极小屏适配 (iPhone SE etc.) ============ */
@media (max-width: 380px) {
  .lobby-logo h1 { font-size: 32px; }
  .lobby-preview { padding: 12px; }
  .bottom-nav { gap: 8px; }
  .nav-item { width: 72px; padding: 10px 6px; border-radius: 16px; }
  .nav-icon { font-size: 22px; }
  .nav-label { font-size: 11px; }
  .overlay-box { padding: 22px 20px; border-radius: 24px; }
  .overlay-box h1 { font-size: 26px; }
  .overlay-box h2 { font-size: 20px; }
}

/* ============ 横屏手机适配 ============ */
@media (max-height: 500px) and (orientation: landscape) {
  #screenLobby .lobby-inner {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 12px;
  }
  .lobby-logo { order: 1; }
  .lobby-logo h1 { font-size: 28px; }
  .lobby-logo .subtitle { font-size: 11px; margin-top: 2px; }
  .lobby-preview { order: 2; padding: 10px; }
  #lobbyCanvas { max-height: 200px; }
  #screenLobby .btn-primary.big { order: 3; font-size: 16px; padding: 12px 32px; }
  .bottom-nav { order: 4; gap: 8px; }
  .nav-item { width: 66px; padding: 8px 4px; border-radius: 14px; }
  .nav-icon { font-size: 20px; }
  .nav-label { font-size: 10px; }
  .game-hud { padding: 8px 14px; }
  .game-main { padding: 8px; }
}
