:root {
  --bg: #080d18;
  --panel: rgba(17, 24, 39, 0.9);
  --border: rgba(255, 255, 255, 0.12);
  --text: #f8fafc;
  --muted: #94a3b8;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at 50% 10%, #0f2942 0%, #080d18 75%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
  touch-action: manipulation;
}

.app-shell {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  gap: 8px;
}

/* Header */
.hud-bar {
  width: 100%;
  max-width: 580px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  font-size: 0.68rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 6px;
  background: linear-gradient(135deg, #10b981, #06b6d4);
  color: #fff;
}

.brand h1 {
  font-size: 1.1rem;
  font-weight: 800;
}

.theme-switch,
.hud-actions {
  display: flex;
  gap: 6px;
}

.theme-btn,
.icon-btn {
  min-height: 38px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.theme-btn.active {
  background: rgba(16, 185, 129, 0.25);
  border-color: #34d399;
}

/* Status Strip */
.status-strip {
  width: 100%;
  max-width: 580px;
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 8px;
}

.stat-pill {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  text-align: center;
}

.stat-pill span {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
}

.stat-pill strong {
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}

.score-pill {
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}

.score-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
}

.combo-badge {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.25);
  border: 1px solid #fbbf24;
  color: #fde68a;
  font-size: 0.72rem;
  font-weight: 800;
}

.combo-badge.hidden {
  display: none;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #10b981, #38bdf8);
  transition: width 0.25s ease-out;
}

/* Board */
.board-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-wrap {
  position: relative;
  width: min(92vw, 520px, 68dvh);
  aspect-ratio: 1;
}

.board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: clamp(3px, 0.9vw, 6px);
  padding: clamp(6px, 1.4vw, 10px);
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 20px 44px rgba(0, 0, 0, 0.5);
  touch-action: none;
}

.board.shake {
  animation: boardShake 0.28s ease-out;
}

@keyframes boardShake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-4px, 3px); }
  45% { transform: translate(4px, -3px); }
  70% { transform: translate(-2px, -2px); }
}

.fx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 12;
  border-radius: 18px;
}

.tile {
  position: relative;
  border-radius: 10px;
  border: 2px solid transparent;
  display: grid;
  place-items: center;
  font-size: clamp(1.25rem, 4.4vw, 2.1rem);
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.14s ease, opacity 0.18s ease;
  touch-action: none;
}

.tile.selected {
  border-color: #ffffff;
  transform: scale(1.08);
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.45);
  z-index: 2;
}

.tile.hint {
  animation: hintPulse 0.7s ease-in-out infinite alternate;
}

@keyframes hintPulse {
  from { transform: scale(1); box-shadow: 0 0 0 rgba(250, 204, 21, 0); }
  to { transform: scale(1.08); box-shadow: 0 0 14px rgba(250, 204, 21, 0.75); }
}

.tile.matched {
  transform: scale(0.25);
  opacity: 0;
}

.tile.drop-in {
  animation: dropIn 0.22s cubic-bezier(0.34, 1.4, 0.64, 1);
}

@keyframes dropIn {
  from { transform: translateY(-28%); opacity: 0.4; }
  to { transform: translateY(0); opacity: 1; }
}

.tile-badge {
  position: absolute;
  bottom: 1px;
  right: 2px;
  font-size: 0.72rem;
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.8));
}

.tile.bomb {
  background: radial-gradient(circle, #6366f1 0%, #312e81 100%) !important;
  border-color: #a5b4fc;
  box-shadow: 0 0 12px rgba(129, 140, 248, 0.6);
}

/* Toast */
.toast {
  position: absolute;
  top: 12px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid #38bdf8;
  color: #e0f2fe;
  font-size: 0.85rem;
  font-weight: 700;
  pointer-events: none;
  z-index: 15;
}

.toast.hidden {
  display: none;
}

/* Overlay */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 13, 24, 0.82);
  backdrop-filter: blur(6px);
  z-index: 20;
  padding: 16px;
}

.overlay.hidden {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 340px;
  background: #111827;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 20px;
  padding: 24px 20px;
  text-align: center;
}

.modal-emoji {
  font-size: 3rem;
  margin-bottom: 8px;
}

.modal-card h2 {
  font-size: 1.4rem;
  margin-bottom: 8px;
}

.modal-desc {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 18px;
  line-height: 1.5;
}

.primary-btn {
  width: 100%;
  min-height: 46px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #10b981, #06b6d4);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.footer-tip {
  font-size: 0.76rem;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 480px) {
  .brand h1 { font-size: 0.98rem; }
  .footer-tip { font-size: 0.7rem; }
}
