* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #222 0, #111 40%, #000 100%);
  color: #f5f5f5;
  min-height: 100vh;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 230px;
  background: linear-gradient(180deg, #191919 0%, #101010 100%);
  border-right: 1px solid #333;
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  gap: 10px;
}
.sidebar-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.sidebar-title {
  font-size: 16px;
  font-weight: 600;
}
.sidebar-sub {
  font-size: 11px;
  color: #aaa;
  margin-top: 2px;
}
.mobile-menu-toggle {
  display: none;
  border-radius: 8px;
  border: 1px solid #555;
  background: #181818;
  color: #eee;
  font-size: 14px;
  padding: 4px 8px;
  cursor: pointer;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}
.nav-btn {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: #ddd;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
}
.nav-btn span.icon { font-size: 16px; }
.nav-btn:hover { background: rgba(255,255,255,0.04); }
.nav-btn.active {
  background: linear-gradient(90deg, #f3d36f 0%, #cc8a33 60%, #7b4b15 100%);
  color: #1a1a1a;
  border-color: #f9e7af;
  transform: translateX(1px);
}

.external-link-box {
  margin-top: 4px;
  padding: 7px 7px;
  border-radius: 8px;
  border: 1px solid #333;
  background: radial-gradient(circle at 0 0, #333 0, #181818 55%, #101010 100%);
  font-size: 12px;
  color: #ddd;
}
.external-link-title {
  font-size: 11px;
  color: #aaa;
  margin-bottom: 3px;
}
.external-link-btn {
  display: inline-block;
  margin-top: 3px;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid #f5d36f;
  background: linear-gradient(90deg, #f3d36f 0%, #cc8a33 60%, #7b4b15 100%);
  color: #181818;
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.external-link-btn:hover { filter: brightness(1.05); }

.sidebar-footer {
  margin-top: auto;
  font-size: 11px;
  color: #666;
}

/* Main area */
.main-area {
  flex: 1;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
}
.header-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.header h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 1px;
}
.header-sub {
  font-size: 13px;
  color: #ccc;
}

.settings-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid #666;
  background: #181818;
  color: #f5f5f5;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 8px rgba(0,0,0,0.6);
}
.settings-btn:hover {
  border-color: #f5d36f;
  color: #f5d36f;
}

.settings-panel {
  position: absolute;
  right: 20px;
  top: 58px;
  background: #111;
  border-radius: 10px;
  border: 1px solid #444;
  padding: 10px 12px;
  font-size: 12px;
  min-width: 200px;
  box-shadow: 0 10px 20px rgba(0,0,0,0.7);
  display: none;
  z-index: 1100;
}
.settings-panel.show { display: block; }
.settings-title {
  font-weight: 600;
  margin-bottom: 6px;
}
.settings-item {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.settings-note {
  font-size: 11px;
  color: #888;
  margin-top: 3px;
}

.page {
  display: none;
  flex: 1;
  margin-top: 10px;
}
.page.active { display: flex; }

/* Page: 演奏器 */
.page-play { flex-direction: column; align-items: center; gap: 12px; }

.drum-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.drum-caption {
  font-size: 13px;
  color: #ddd;
  text-align: center;
  line-height: 1.5;
}

.kbd {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid #666;
  background: #222;
  font-family: monospace;
  font-size: 12px;
  margin: 0 2px;
}

.help-panel {
  font-size: 13px;
  color: #ddd;
  text-align: center;
  line-height: 1.6;
  max-width: 520px;
}

/* 🎙 錄音面板 */
.record-panel {
  margin-top: 4px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #333;
  background: rgba(0,0,0,0.4);
  font-size: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  max-width: 520px;
}
.record-btn {
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid #666;
  background: #222;
  color: #eee;
  font-size: 12px;
  cursor: pointer;
}
.record-btn.primary {
  border-color: #f77;
  background: radial-gradient(circle at 30% 30%, #ff6b6b 0, #b22222 80%);
  color: #fff;
}
.record-status {
  font-size: 11px;
  color: #f0e6b2;
  margin-left: auto;
  min-width: 120px;
  text-align: right;
}

/* ===== 聽寫練習：模式按鈕 ===== */
.ear-mode-btn {
  padding: 0.35rem 0.9rem;
  margin-right: 0.5rem;
  border-radius: 999px;
  border: 1px solid #666;
  background: #222;
  color: #eee;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.ear-mode-btn.active {
  background: linear-gradient(135deg, #f6c06a, #f08a35);
  color: #000;
  border-color: transparent;
}

/* ===== 聽寫練習：半透明黃圈效果 ===== */
/* 基底：只負責定位 + 動畫，具體大小/樣式另外分級 */
/* 初階：實心黃圈，要很明顯 */
/* ===== 聽寫練習：半透明提示圓圈 ===== */
/* 基底：負責定位，動畫時間交給各等級自己決定 */
.ear-circle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

/* 初階：顏色比較濃、停留比較久（約 1 秒） */
.ear-circle-beginner {
  border: 3px solid rgba(255, 255, 0, 1.2);
  background: radial-gradient(
    circle,
    rgba(255, 255, 0, 1.2) 0%,
    rgba(255, 255, 0, 0.15) 80%,
    rgba(255, 255, 0, 0.0) 95%
  );
  animation: ear-hit-fade 1.2s ease-out forwards;
}

/* 中階：透明度降低一點、但還是看得出一個圓，停留中等（約 0.8 秒） */
.ear-circle-intermediate {
  border: 2px solid rgba(255, 255, 0, 0.8);
  background: radial-gradient(
    circle,
    rgba(255, 255, 0, 0.8) 0%,
    rgba(255, 255, 0, 0.15) 60%,
    rgba(255, 255, 0, 0.0) 85%
  );
  animation: ear-hit-fade 0.80s ease-out forwards;
}

@keyframes ear-hit-fade {
  from {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  to {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.3);
  }
}



/* Page: 聽寫練習 */
.page-ear { flex-direction: column; align-items: center; gap: 16px; }
.ear-controls {
  max-width: 640px;
  width: 100%;
  background: rgba(0,0,0,0.35);
  border-radius: 12px;
  border: 1px solid #333;
  padding: 10px 12px;
  font-size: 13px;
}
.ear-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.ear-label {
  font-size: 13px;
  color: #ddd;
  margin-right: 4px;
}
.ear-level-btn {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid #666;
  background: #222;
  color: #eee;
  font-size: 12px;
  cursor: pointer;
}
.ear-level-btn.active {
  border-color: #f5d36f;
  background: linear-gradient(90deg, #f3d36f 0%, #cc8a33 60%, #7b4b15 100%);
  color: #181818;
}
.ear-main-btn {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #666;
  background: #222;
  color: #eee;
  font-size: 13px;
  cursor: pointer;
}
.ear-main-btn.primary {
  border-color: #f5d36f;
  background: linear-gradient(90deg, #f3d36f 0%, #cc8a33 60%, #7b4b15 100%);
  color: #181818;
}
.ear-main-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.ear-status {
  font-size: 13px;
  color: #f0e6b2;
  margin-top: 2px;
}
.ear-answer {
  font-size: 13px;
  color: #ddd;
  margin-top: 4px;
  line-height: 1.6;
}
.ear-answer span {
  font-weight: 500;
  color: #f3d36f;
}
.ear-input-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}
.ear-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}
.ear-digit-btn {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid #666;
  background: #222;
  color: #eee;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ear-digit-btn:hover { border-color: #f5d36f; }
.ear-hint {
  font-size: 11px;
  color: #aaa;
  text-align: center;
}

/* Placeholder pages */
.placeholder {
  font-size: 14px;
  color: #ccc;
  line-height: 1.7;
  max-width: 520px;
  margin-top: 20px;
}
.placeholder-title {
  font-size: 16px;
  margin-bottom: 6px;
  font-weight: 600;
}
.placeholder-tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid #666;
  margin-bottom: 8px;
  color: #aaa;
}

.footer {
  font-size: 11px;
  color: #666;
  margin-top: auto;
  margin-bottom: 6px;
  text-align: right;
}
/* ===== 聽寫練習：提示速度滑桿 ===== */
.ear-speed-row {
  align-items: center;
  gap: 6px;
}

.ear-speed-text {
  font-size: 11px;
  color: #aaa;
}

.ear-speed-range {
  flex: 1;
  max-width: 260px;
}

/* 右下角浮動預覽按鈕 */
.fab-preview {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #f3d36f 0%, #cc8a33 60%, #7b4b15 100%);
  color: #181818;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  text-decoration: none;
  box-shadow: 0 0 14px rgba(0,0,0,0.8);
  border: 1px solid #f9e7af;
  z-index: 1300;
}
.fab-preview:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

/* Debug 面板 */
.debug-panel {
  position: fixed;
  left: 8px;
  bottom: 8px;
  width: 270px;
  max-height: 40vh;
  background: #111;
  border-radius: 8px;
  border: 1px solid #444;
  font-size: 11px;
  color: #eee;
  display: none;
  flex-direction: column;
  z-index: 1200;
}
.debug-panel.show { display: flex; }
.debug-header {
  padding: 4px 6px;
  border-bottom: 1px solid #333;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}
.debug-body {
  padding: 4px 6px;
  overflow-y: auto;
  font-family: monospace;
  white-space: pre-wrap;
  line-height: 1.4;
}
.debug-clear-btn {
  border-radius: 6px;
  border: 1px solid #666;
  background:#222;
  color:#eee;
  font-size:10px;
  padding:2px 6px;
  cursor:pointer;
}

/* RWD */
@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid #333;
    padding: 10px 12px;
  }
  .mobile-menu-toggle { display:inline-block; }
  .sidebar-sub { display:none; }
  .sidebar-nav { display:none; margin-top:8px; }
  .sidebar-nav.open { display:flex; flex-direction:column; gap:8px; }
  .main-area { padding: 12px; }
  .help-panel { font-size:12px; padding:0 4px; }
}
@media (max-width: 600px) {
  .drum-container {
    width: min(420px, 84vw);
    height: min(420px, 84vw);
  }
}
