:root {
  --primary: #4C97FF;       /* Scratch 動作藍 */
  --primary-dark: #3373CC;
  --secondary: #FFAB19;     /* Scratch 控制橙 */
  --secondary-dark: #CF8B17;
  --purple: #9966FF;        /* 外觀紫 */
  --green: #59C059;         /* 運算綠 */
  --yellow: #FFBF00;        /* 事件黃 */
  --cyan: #5CB1D6;          /* 偵測青 */
  --red: #FF6680;           /* 警示紅 */
  --variable: #FF8C1A;      /* 變數橘 */
  --bg-main: #F2F7FF;
  --bg-card: #FFFFFF;
  --text-main: #2C3E50;
  --text-muted: #6C7A89;
  --border-color: #E2E8F0;
  --radius: 16px;
  --radius-sm: 8px;
  --shadow: 0 8px 24px rgba(76, 151, 255, 0.12);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Fredoka', 'Noto Sans TC', system-ui, -apple-system, sans-serif;
  user-select: none;
}

body {
  background: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* 頂部導覽列 */
.navbar {
  background: #FFFFFF;
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 2rem;
  background: #FFE9D1;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--secondary);
}

.logo-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: #2D3748;
}

.logo-tag {
  background: var(--primary);
  color: white;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: bold;
}

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

.sound-toggle-btn, .help-btn {
  background: #EDF2F7;
  border: none;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.sound-toggle-btn:hover, .help-btn:hover {
  background: #E2E8F0;
  transform: translateY(-1px);
}

/* 四大單元切換選單標籤 */
.unit-tabs-container {
  max-width: 1200px;
  margin: 20px auto 10px;
  padding: 0 20px;
  width: 100%;
}

.unit-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.tab-btn {
  background: white;
  border: 3px solid transparent;
  border-radius: var(--radius);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: var(--shadow-sm);
}

.tab-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.08);
}

.tab-btn.active {
  transform: translateY(-4px);
  box-shadow: 0 10px 24px rgba(76, 151, 255, 0.25);
}

.tab-btn[data-unit="director"].active {
  border-color: var(--purple);
  background: #FAF5FF;
}
.tab-btn[data-unit="whack"].active {
  border-color: var(--variable);
  background: #FFF8EE;
}
.tab-btn[data-unit="dino"].active {
  border-color: var(--green);
  background: #F0FFF4;
}
.tab-btn[data-unit="maze"].active {
  border-color: var(--primary);
  background: #EBF8FF;
}

.tab-icon {
  font-size: 1.8rem;
}

.tab-title {
  font-size: 1.05rem;
  font-weight: 800;
}

.tab-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* 主容器 */
.main-content {
  max-width: 1200px;
  margin: 10px auto 40px;
  padding: 0 20px;
  width: 100%;
  flex: 1;
}

.unit-view {
  display: none;
  animation: fadeIn 0.35s ease;
}

.unit-view.active {
  display: block;
}

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

/* 單元標頭介紹卡片 */
.unit-header-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
  border-left: 8px solid var(--primary);
}

.unit-header-card.purple { border-color: var(--purple); }
.unit-header-card.orange { border-color: var(--variable); }
.unit-header-card.green { border-color: var(--green); }
.unit-header-card.blue { border-color: var(--primary); }

.unit-header-info h2 {
  font-size: 1.4rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
}

.unit-header-info p {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 6px;
  font-weight: 500;
}

.learning-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  background: #EDF2F7;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 20px;
  color: #4A5568;
}

/* 雙欄工作區 (左：互動實驗舞台 / 右：Scratch 積木組裝與控制) */
.stage-workspace-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 20px;
}

@media (max-width: 900px) {
  .stage-workspace-grid {
    grid-template-columns: 1fr;
  }
  .unit-tabs {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* 卡片通用樣式 */
.glass-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px dashed #EDF2F7;
  padding-bottom: 10px;
}

/* 舞台區域 */
.stage-container {
  position: relative;
  background: #F7FAFC;
  border-radius: var(--radius-sm);
  border: 2px solid #CBD5E0;
  overflow: hidden;
  height: 380px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 控制列 (播放、暫停、重設) */
.stage-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.btn-green-flag {
  background: #46B946;
  color: white;
  border: none;
  font-size: 1rem;
  font-weight: 800;
  padding: 10px 20px;
  border-radius: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(70, 185, 70, 0.3);
  transition: all 0.2s;
}

.btn-green-flag:hover {
  background: #3DA33D;
  transform: scale(1.04);
}

.btn-red-stop {
  background: #FF5A5A;
  color: white;
  border: none;
  font-size: 1rem;
  font-weight: 800;
  padding: 10px 18px;
  border-radius: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(255, 90, 90, 0.3);
  transition: all 0.2s;
}

.btn-red-stop:hover {
  background: #E54B4B;
  transform: scale(1.04);
}

.btn-secondary {
  background: #E2E8F0;
  color: #2D3748;
  border: none;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: #CBD5E0;
}

/* 互動控制項：滑桿群組 */
.control-group {
  background: #F8FAFC;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid #E2E8F0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  font-weight: 700;
  color: #4A5568;
}

.control-value-badge {
  background: var(--primary);
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.85rem;
}

.control-value-badge.orange { background: var(--variable); }
.control-value-badge.green { background: var(--green); }
.control-value-badge.purple { background: var(--purple); }

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
  height: 8px;
  border-radius: 4px;
}

/* 互動控制項：切換按鈕組 (Segmented Control) */
.switch-buttons-group {
  display: flex;
  background: #EDF2F7;
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}

.switch-btn {
  flex: 1;
  background: transparent;
  border: none;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  color: #4A5568;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.switch-btn.active {
  background: white;
  color: var(--primary);
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

/* Scratch 積木專用樣式 */
.scratch-blocks-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.scratch-block {
  border-radius: 6px;
  padding: 10px 14px;
  color: white;
  font-size: 0.95rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.18);
  cursor: grab;
  position: relative;
  transition: transform 0.15s;
}

.scratch-block:active {
  cursor: grabbing;
}

.scratch-block.motion { background: #4C97FF; }
.scratch-block.looks { background: #9966FF; }
.scratch-block.events { background: #FFBF00; color: #333; }
.scratch-block.control { background: #FFAB19; }
.scratch-block.sensing { background: #5CB1D6; }
.scratch-block.variables { background: #FF8C1A; }

/* 拖拉槽位與目標區 */
.dropzone-area {
  min-height: 160px;
  border: 3px dashed #CBD5E0;
  border-radius: var(--radius-sm);
  background: #FAFAFA;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: all 0.2s;
}

.dropzone-area.drag-over {
  border-color: var(--green);
  background: #F0FFF4;
}

.dropzone-placeholder {
  color: #A0AEC0;
  font-size: 0.9rem;
  text-align: center;
  margin: auto;
  font-weight: 600;
}

/* =======================================================
   單元 1：我是小導演
   ======================================================= */
.director-stage {
  width: 100%;
  height: 100%;
  position: relative;
  background-size: cover;
  background-position: center;
  transition: background-image 0.4s ease;
  overflow: hidden;
}

.bg-classroom { background: linear-gradient(to bottom, #A1C4FD, #C2E9FB); }
.bg-space { background: radial-gradient(circle, #2B1055, #0B0014); }
.bg-forest { background: linear-gradient(to bottom, #84FAB0, #8FD3F4); }

.actor-cat {
  position: absolute;
  bottom: 50px;
  left: 60px;
  width: 120px;
  height: 120px;
  transition: transform 0.2s ease, left 0.5s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.actor-svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 8px 12px rgba(0,0,0,0.15));
}

.speech-bubble {
  position: absolute;
  top: -65px;
  left: 50%;
  transform: translateX(-50%);
  background: white;
  border: 3px solid #4A5568;
  border-radius: 16px;
  padding: 8px 16px;
  font-weight: 800;
  font-size: 0.95rem;
  color: #2D3748;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 10px 10px 0;
  border-style: solid;
  border-color: #4A5568 transparent;
  display: block;
  width: 0;
}

.speech-bubble.show {
  opacity: 1;
}

.broadcast-signal {
  position: absolute;
  top: 15px;
  right: 15px;
  background: rgba(255, 191, 0, 0.9);
  color: #333;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 800;
  opacity: 0;
  transition: opacity 0.3s;
}

.broadcast-signal.show {
  opacity: 1;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* =======================================================
   單元 2：打地鼠
   ======================================================= */
.whack-stats-bar {
  display: flex;
  justify-content: space-around;
  background: #FFF5EB;
  border: 2px solid var(--variable);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.1rem;
  font-weight: 800;
}

.whack-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  width: 100%;
  height: 100%;
  padding: 20px;
  background: #8BC34A;
  background-image: radial-gradient(#7CB342 20%, transparent 20%);
  background-size: 20px 20px;
}

.whack-hole {
  background: #5D4037;
  border-radius: 50%;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 10px 10px rgba(0,0,0,0.5);
  cursor: pointer;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.mole {
  width: 75%;
  height: 85%;
  position: absolute;
  bottom: -100%;
  transition: bottom 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  cursor: pointer;
}

.mole.up {
  bottom: 0;
}

.mole.whacked {
  transform: scale(0.8) rotate(-15deg);
  opacity: 0.7;
}

/* =======================================================
   單元 3：跳跳龍
   ======================================================= */
.dino-dashboard {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  background: #F0FFF4;
  border: 2px solid var(--green);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  margin-bottom: 12px;
}

.dino-stat-chip {
  font-size: 0.95rem;
  font-weight: 800;
  color: #22543D;
}

#dinoCanvas {
  width: 100%;
  height: 100%;
  background: #EBF8FF;
  display: block;
}

/* =======================================================
   單元 4：走迷宮
   ======================================================= */
#mazeCanvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #1A202C;
}

.maze-dpad {
  display: grid;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(3, 48px);
  gap: 6px;
  margin: 10px auto;
  justify-content: center;
}

.dpad-btn {
  background: #EDF2F7;
  border: 2px solid #CBD5E0;
  border-radius: 10px;
  font-size: 1.2rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s;
}

.dpad-btn:active {
  background: var(--primary);
  color: white;
}

.dpad-up { grid-column: 2; grid-row: 1; }
.dpad-left { grid-column: 1; grid-row: 2; }
.dpad-down { grid-column: 2; grid-row: 2; }
.dpad-right { grid-column: 3; grid-row: 2; }

/* 底部與提示窗 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-card {
  background: white;
  border-radius: var(--radius);
  padding: 30px;
  max-width: 500px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0,0,0,0.25);
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.footer {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
  border-top: 1px solid var(--border-color);
  background: white;
  margin-top: auto;
}
