:root {
  --ink: #1E293B;
  --ink-soft: #475569;
  --sky: #0EA5E9;
  --sky-dark: #0369A1;
  --accent: #FF8C42;
  --accent-dark: #D96820;
  --mint: #10B981;
  --font-kid: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", "Hiragino Sans", system-ui, -apple-system, sans-serif;
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family: var(--font-kid);
  color: var(--ink);
  background: #0F172A;
  overscroll-behavior: none;
}

#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 60;
}

#maze-app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  gap: 8px;
}

/* ========== 上方控制列 ========== */
.maze-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hub-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  text-decoration: none;
  height: 44px;
  padding: 0 14px;
  border-radius: 14px;
  background: #FFFFFF;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 900;
  border: 2px solid #CBD5E1;
  box-shadow: 0 4px 0 #94A3B8;
}

.hub-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #94A3B8;
}

.level-tabs {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.14);
  padding: 4px;
  border-radius: 16px;
  gap: 4px;
}

.lvl-tab {
  border: none;
  background: transparent;
  color: #E2E8F0;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 900;
  padding: 8px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.lvl-tab.active {
  background: #38BDF8;
  color: #0F172A;
  box-shadow: 0 3px 0 #0284C7;
}

.action-pill {
  height: 44px;
  padding: 0 14px;
  border-radius: 14px;
  border: 2px solid #FDE68A;
  background: #FFFBEB;
  color: #92400E;
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 4px 0 #D97706;
}

.action-pill.active {
  background: #FCD34D;
  color: #78350F;
}

.action-pill:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #D97706;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 2px solid #CBD5E1;
  background: #FFFFFF;
  font-size: 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 0 #94A3B8;
  padding: 0;
}

.icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #94A3B8;
}

/* ========== 狀態提示條 ========== */
.status-bar {
  flex-shrink: 0;
  text-align: center;
  padding: 8px 14px;
  border-radius: 14px;
  background: rgba(30, 41, 59, 0.95);
  border: 2px solid #334155;
  color: #F8FAFC;
  font-size: clamp(0.92rem, 2.5vw, 1.12rem);
  font-weight: 800;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.status-bar.playing {
  background: rgba(14, 116, 144, 0.9);
  border-color: #38BDF8;
  color: #FFFFFF;
}

.status-bar.danger {
  background: rgba(185, 28, 28, 0.92);
  border-color: #FCA5A5;
  color: #FFFFFF;
}

.status-bar.win {
  background: rgba(4, 120, 87, 0.95);
  border-color: #6EE7B7;
  color: #FFFFFF;
}

/* ========== 主畫布區域 ========== */
.stage-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  border-radius: 22px;
  overflow: hidden;
  border: 3px solid #334155;
  background: #0B1224;
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.45);
}

#maze-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#maze-canvas.dragging {
  cursor: grabbing;
}

/* ========== 失敗 / 過關彈窗 ========== */
.overlay-modal {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: rgba(15, 23, 42, 0.68);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.overlay-modal.hidden {
  display: none;
}

.modal-box {
  width: 100%;
  max-width: 420px;
  background: #FFFFFF;
  border-radius: 28px;
  padding: 26px 22px;
  text-align: center;
  box-shadow: 0 20px 44px rgba(0, 0, 0, 0.35);
  animation: popIn 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.fail-box {
  border: 5px solid #FCA5A5;
}

.win-box {
  border: 5px solid #FDE047;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.86) translateY(16px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-emoji {
  font-size: 3.1rem;
  line-height: 1.1;
  margin-bottom: 8px;
}

.modal-title {
  margin: 0 0 8px;
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--ink);
}

.modal-desc {
  margin: 0 0 18px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink-soft);
  line-height: 1.5;
}

.rest-reminder {
  background: #ECFDF5;
  border: 2px solid #A7F3D0;
  color: #065F46;
  font-size: 0.95rem;
  font-weight: 800;
  padding: 10px 12px;
  border-radius: 14px;
  margin-bottom: 16px;
}

.rest-reminder.hidden {
  display: none;
}

.modal-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-primary,
.btn-secondary {
  width: 100%;
  border-radius: 999px;
  font-family: inherit;
  font-weight: 900;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-primary {
  border: none;
  padding: 14px 24px;
  font-size: 1.25rem;
  color: #FFFFFF;
  background: linear-gradient(180deg, #FFA94D 0%, var(--accent) 100%);
  box-shadow: 0 6px 0 var(--accent-dark);
}

.btn-primary:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 var(--accent-dark);
}

.btn-secondary {
  border: 3px solid #CBD5E1;
  padding: 11px 22px;
  font-size: 1.1rem;
  color: var(--ink);
  background: #FFFFFF;
  box-shadow: 0 5px 0 #CBD5E1;
}

.btn-secondary:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #CBD5E1;
}

@media (max-width: 640px) {
  .lvl-tab {
    font-size: 0.85rem;
    padding: 7px 9px;
  }

  .hub-btn,
  .action-pill {
    height: 40px;
    padding: 0 11px;
    font-size: 0.9rem;
  }

  .icon-btn {
    width: 40px;
    height: 40px;
    font-size: 1.15rem;
  }
}
