/* ==========================================================================
   TomatoFocus - Premium Style System (Glassmorphic Cyber-Neo-Brutalism)
   ========================================================================== */

/* 全域 CSS 變數定義 */
:root {
  /* 配色系統 (預設 Work 狀態配紅色) */
  --bg-dark: #070913;
  --panel-bg: rgba(13, 17, 33, 0.7);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text-primary: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  
  /* 預設 Work 專注模式配色：暖紅與亮橙 */
  --gradient-start: #ff416c;
  --gradient-end: #ff4b2b;
  --glow-color: rgba(255, 75, 43, 0.4);

  /* 模式專屬色設定（透過 JS 動態切換 data-theme） */
  --work-start: #ff416c;
  --work-end: #ff4b2b;
  --work-glow: rgba(255, 75, 43, 0.35);

  --short-start: #11998e;
  --short-end: #38ef7d;
  --short-glow: rgba(56, 239, 125, 0.35);

  --long-start: #00c6ff;
  --long-end: #0072ff;
  --long-glow: rgba(0, 114, 255, 0.35);

  /* 其他 UI 色彩 */
  --accent-purple: #8a2387;
  --danger-color: #ef4444;
  --success-color: #10b981;
  --font-sans: 'Inter', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  /* 圓環長度 */
  --ring-circumference: 848.23; /* 2 * PI * 135 */
}

/* 動態主題套用 */
body[data-theme="work"] {
  --gradient-start: var(--work-start);
  --gradient-end: var(--work-end);
  --glow-color: var(--work-glow);
}
body[data-theme="short"] {
  --gradient-start: var(--short-start);
  --gradient-end: var(--short-end);
  --glow-color: var(--short-glow);
}
body[data-theme="long"] {
  --gradient-start: var(--long-start);
  --gradient-end: var(--long-end);
  --glow-color: var(--long-glow);
}

/* 基礎重設與排版 */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-primary);
  font-family: var(--font-sans);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* 背景發光體裝飾 */
.bg-glow {
  position: fixed;
  width: 45vw;
  height: 45vw;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.12;
  z-index: -1;
  pointer-events: none;
  animation: floatGlow 18s ease-in-out infinite alternate;
}
.bg-glow-1 {
  background: radial-gradient(circle, var(--gradient-start) 0%, transparent 70%);
  top: -10%;
  left: -5%;
}
.bg-glow-2 {
  background: radial-gradient(circle, var(--accent-purple) 0%, transparent 70%);
  bottom: -10%;
  right: -5%;
  animation-delay: -6s;
}

@keyframes floatGlow {
  0% {
    transform: translate(0, 0) scale(1);
  }
  100% {
    transform: translate(8%, 8%) scale(1.15);
  }
}

/* 玻璃擬態卡片基礎樣式 */
.glass-card {
  background: var(--panel-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 28px;
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.4);
  transition: border-color 0.4s ease, box-shadow 0.4s ease;
}
.glass-card:hover {
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 20px rgba(255, 255, 255, 0.02);
}

/* 頁首樣式 */
.app-header {
  border-bottom: 1px solid var(--panel-border);
  background: rgba(7, 9, 19, 0.8);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color 0.2s ease, transform 0.2s ease;
}
.back-link:hover {
  color: var(--text-primary);
  transform: translateX(-3px);
}
.app-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-emoji {
  font-size: 26px;
  animation: pulseTomato 2s ease-in-out infinite;
}
@keyframes pulseTomato {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}
.app-logo h1 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: linear-gradient(to right, #ffffff, var(--text-muted));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.info-badge {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 6px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

/* 主版面配置 */
.app-main {
  max-width: 1200px;
  margin: 40px auto;
  padding: 0 24px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* 雙欄主格線系統 */
.grid-container {
  display: grid;
  grid-template-columns: minmax(360px, 1.7fr) minmax(300px, 1fr);
  gap: 28px;
}

/* ==========================================================================
   計時器主要區域 (Timer Core)
   ========================================================================== */
.timer-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

/* 模式選擇按鈕 */
.mode-selector {
  display: flex;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 6px;
  border-radius: 16px;
  gap: 4px;
  margin-bottom: 30px;
  width: 100%;
  max-width: 360px;
}
.mode-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 0;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.mode-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.03);
}
.mode-btn.active {
  color: var(--bg-dark);
  background: var(--text-primary);
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(255, 255, 255, 0.1);
}

/* 配合模式的 active 色彩變化 */
body[data-theme="work"] .mode-btn.active {
  background: linear-gradient(135deg, var(--work-start), var(--work-end));
  color: #fff;
  box-shadow: 0 8px 20px var(--work-glow);
}
body[data-theme="short"] .mode-btn.active {
  background: linear-gradient(135deg, var(--short-start), var(--short-end));
  color: #fff;
  box-shadow: 0 8px 20px var(--short-glow);
}
body[data-theme="long"] .mode-btn.active {
  background: linear-gradient(135deg, var(--long-start), var(--long-end));
  color: #fff;
  box-shadow: 0 8px 20px var(--long-glow);
}

/* 圓形計時器展示 */
.timer-display-container {
  position: relative;
  width: 320px;
  height: 320px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 30px;
}

.progress-ring {
  transform: rotate(-90deg); /* 順時鐘從 12 點開始 */
}
.progress-ring-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.025);
  stroke-width: 10px;
}
.progress-ring-fill {
  fill: none;
  stroke-width: 11px;
  stroke-linecap: round;
  stroke-dasharray: var(--ring-circumference);
  stroke-dashoffset: 0; /* JS 控制剩餘比例 */
  filter: drop-shadow(0 0 10px var(--glow-color));
  transition: stroke-dashoffset 0.3s linear, stroke 0.5s ease;
}

/* 計時器內部資訊文字 */
.timer-text-container {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 250px;
  height: 250px;
  pointer-events: none;
}
.active-task-display {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.05);
  padding: 4px 10px;
  border-radius: 99px;
  border: 1px solid rgba(255, 255, 255, 0.04);
  margin-bottom: 8px;
}
.timer-countdown {
  font-family: var(--font-mono);
  font-size: 58px;
  font-weight: 700;
  letter-spacing: -1px;
  color: var(--text-primary);
  line-height: 1;
  text-shadow: 0 0 25px var(--glow-color);
  transition: text-shadow 0.5s ease;
}
.timer-state {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 10px;
}

/* 正在倒數時的微呼吸特效 */
.timer-section.timer-running .timer-display-container {
  animation: timerBreathe 4s ease-in-out infinite;
}
@keyframes timerBreathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

/* 倒數控制按鈕 */
.timer-controls {
  display: flex;
  align-items: center;
  gap: 24px;
}
.ctrl-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}
.ctrl-btn:active {
  transform: scale(0.95);
}

.play-btn {
  width: 74px;
  height: 74px;
  background: var(--text-primary);
  color: var(--bg-dark);
  border: none;
  font-size: 24px;
  box-shadow: 0 10px 25px rgba(255, 255, 255, 0.1);
}
.play-btn:hover {
  background: #ffffff;
  transform: scale(1.1);
  box-shadow: 0 12px 30px var(--glow-color), 0 0 15px rgba(255, 255, 255, 0.2);
}
/* 主題套用在播放鍵上 */
body[data-theme="work"] .play-btn {
  background: linear-gradient(135deg, var(--work-start), var(--work-end));
  color: #fff;
  box-shadow: 0 10px 25px var(--work-glow);
}
body[data-theme="short"] .play-btn {
  background: linear-gradient(135deg, var(--short-start), var(--short-end));
  color: #fff;
  box-shadow: 0 10px 25px var(--short-glow);
}
body[data-theme="long"] .play-btn {
  background: linear-gradient(135deg, var(--long-start), var(--long-end));
  color: #fff;
  box-shadow: 0 10px 25px var(--long-glow);
}

/* ==========================================================================
   側邊欄佈局 (Sidebar)
   ========================================================================== */
.sidebar-container {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* 標題與說明 */
.section-title {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.title-icon {
  font-size: 18px;
}
.section-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* 環境背景音按鈕 */
.ambient-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}
.ambient-btn {
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  color: var(--text-primary);
  padding: 12px 16px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  overflow: hidden;
  transition: all 0.25s ease;
}
.ambient-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
}
.ambient-emoji {
  font-size: 16px;
}
/* 活動指示點 */
.btn-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  transition: all 0.3s ease;
}
.ambient-btn.active {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--gradient-start);
  box-shadow: 0 0 15px rgba(255, 255, 255, 0.02), inset 0 0 10px rgba(255, 255, 255, 0.05);
}
.ambient-btn.active .btn-indicator {
  background: var(--gradient-start);
  box-shadow: 0 0 8px var(--gradient-start);
}

/* 音量調整滑桿 */
.volume-slider-container {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  padding: 10px 14px;
  border-radius: 12px;
}
.volume-icon {
  font-size: 14px;
  color: var(--text-muted);
}
.ambient-volume {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.1);
  height: 5px;
  border-radius: 10px;
  outline: none;
  cursor: pointer;
}
.ambient-volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-primary);
  border: 2px solid var(--bg-dark);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
  transition: transform 0.15s ease;
}
.ambient-volume::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}
.volume-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  min-width: 32px;
  text-align: right;
}

/* ==========================================================================
   任務清單 (ToDo Focus List)
   ========================================================================== */
.todo-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.todo-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
  transition: all 0.3s ease;
}
.todo-input:focus {
  border-color: rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 0 15px rgba(255, 255, 255, 0.03);
}
.todo-submit {
  background: var(--text-primary);
  color: var(--bg-dark);
  border: none;
  border-radius: 12px;
  width: 44px;
  height: 44px;
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.2s ease;
}
.todo-submit:hover {
  background: #ffffff;
  transform: scale(1.05);
}

.todo-list {
  list-style: none;
  max-height: 180px;
  overflow-y: auto;
  padding-right: 4px;
}
/* 客製化滾動條 */
.todo-list::-webkit-scrollbar,
.settings-section::-webkit-scrollbar {
  width: 4px;
}
.todo-list::-webkit-scrollbar-track {
  background: transparent;
}
.todo-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
}

.todo-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  margin-bottom: 8px;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  animation: slideIn 0.3s ease forwards;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.todo-item:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
}
.todo-item.focusing {
  border-color: var(--gradient-start);
  background: rgba(255, 255, 255, 0.05);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.01);
}

.todo-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0; /* 防止子項溢出 */
}
.todo-checkbox {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.2s ease;
}
.todo-checkbox::after {
  content: '✓';
  color: var(--bg-dark);
  font-size: 11px;
  font-weight: 900;
  display: none;
}
.todo-item.completed .todo-checkbox {
  background: var(--text-muted);
  border-color: var(--text-muted);
}
.todo-item.completed .todo-checkbox::after {
  display: block;
}
.todo-text {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  flex: 1;
}
.todo-item.completed .todo-text {
  text-decoration: line-through;
  color: var(--text-dim);
}

.todo-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.todo-action-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  transition: all 0.2s ease;
}
.todo-action-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
}
.todo-action-btn.delete-btn:hover {
  color: var(--danger-color);
}
.todo-action-btn.focus-star {
  font-size: 14px;
}
.todo-item.focusing .todo-action-btn.focus-star {
  color: #f59e0b; /* 專注亮金黃色 */
}

/* ==========================================================================
   下方區域：設定與數據區 (Settings & Stats)
   ========================================================================== */
.bottom-container {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 28px;
}

/* 設定輸入網格 */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 22px;
}
.setting-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.setting-item label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}
.setting-item input,
.setting-item select {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border-radius: 12px;
  padding: 10px 14px;
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
  transition: all 0.25s ease;
}
.setting-item input:focus,
.setting-item select:focus {
  border-color: rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.05);
}

.settings-actions,
.stats-actions {
  display: flex;
  justify-content: flex-end;
  gap: 14px;
}

/* 按鈕樣式系統 */
.btn-primary {
  background: var(--text-primary);
  color: var(--bg-dark);
  border: none;
  padding: 10px 20px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.25s ease;
}
.btn-primary:hover {
  background: #ffffff;
  box-shadow: 0 4px 15px rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}
.btn-primary:active {
  transform: translateY(0);
}

.btn-text {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
}
.btn-text:hover {
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.02);
}

.btn-text-danger {
  background: transparent;
  border: 1px solid rgba(239, 68, 68, 0.15);
  color: rgba(239, 68, 68, 0.8);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
}
.btn-text-danger:hover {
  background: rgba(239, 68, 68, 0.06);
  border-color: rgba(239, 68, 68, 0.4);
  color: #ef4444;
}

/* 統計資訊網格 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 22px;
}
.stat-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 16px;
  padding: 18px;
  text-align: center;
}
.stat-num {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

/* 頁尾樣式 */
.app-footer {
  text-align: center;
  padding: 30px 24px;
  color: var(--text-dim);
  font-size: 12px;
  border-top: 1px solid var(--panel-border);
  background: rgba(7, 9, 19, 0.9);
  margin-top: 60px;
}

/* ==========================================================================
   響應式設計媒體查詢 (Responsive Design)
   ========================================================================== */
@media (max-width: 900px) {
  .app-main {
    margin: 20px auto;
    padding: 0 16px;
  }
  
  .grid-container {
    grid-template-columns: 1fr;
  }
  
  .bottom-container {
    grid-template-columns: 1fr;
  }
  
  .timer-display-container {
    width: 290px;
    height: 290px;
  }
  
  .progress-ring {
    width: 290px;
    height: 290px;
  }
  .progress-ring-bg,
  .progress-ring-fill {
    cx: 145px;
    cy: 145px;
    r: 120px;
  }
  
  :root {
    --ring-circumference: 753.98; /* 2 * PI * 120 */
  }
  
  .timer-countdown {
    font-size: 48px;
  }
  
  .timer-text-container {
    width: 210px;
    height: 210px;
  }
}

@media (max-width: 500px) {
  .header-container {
    padding: 12px 16px;
  }
  .app-logo h1 {
    font-size: 16px;
  }
  .settings-grid {
    grid-template-columns: 1fr;
  }
}
