/* === 全域變數與重設 === */
:root {
  --bg-color: #030308;
  --text-main: #f8fafc;
  --text-muted: #64748b;
  --accent-cyan: #38bdf8;
  --accent-purple: #a855f7;
  --accent-glow: rgba(56, 189, 248, 0.4);
  --dim-text: rgba(255, 255, 255, 0.18);
  --clock-font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", sans-serif;
  --transition-speed: 0.5s;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #000000;
  font-family: var(--clock-font);
  color: var(--text-main);
  touch-action: manipulation;
}

/* === 主容器與安全區域 (iOS Notch / Home Bar) === */
.app-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  background-color: var(--bg-color);
  padding: calc(env(safe-area-inset-top, 20px) + 8px) 
           calc(env(safe-area-inset-right, 20px) + 16px) 
           calc(env(safe-area-inset-bottom, 20px) + 12px) 
           calc(env(safe-area-inset-left, 20px) + 16px);
  transition: background-color var(--transition-speed) ease, filter var(--transition-speed) ease;
}

/* === 頂部列 === */
.top-bar {
  width: 100%;
  max-width: 800px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
  transition: opacity 0.4s ease;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text-muted);
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: all 0.3s ease;
}

.badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: #64748b;
}

.badge.badge-active {
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.3);
}

.badge.badge-active .dot {
  background-color: #38bdf8;
  box-shadow: 0 0 6px #38bdf8;
}

.badge.badge-listening {
  color: #a855f7;
  background: rgba(168, 85, 247, 0.15);
  border-color: rgba(168, 85, 247, 0.4);
}

.badge.badge-listening .dot {
  background-color: #a855f7;
  box-shadow: 0 0 8px #a855f7;
  animation: pulse-dot 1.2s infinite ease-in-out;
}

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.6); opacity: 0.6; }
}

.icon-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn:active {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.2);
}

/* === 中央時鐘展示區 === */
.clock-display {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  width: 100%;
  max-width: 900px;
  cursor: pointer;
}

.time-wrapper {
  position: relative;
  display: flex;
  align-items: baseline;
  justify-content: center;
}

.ampm-text {
  font-size: clamp(14px, 3vw, 24px);
  font-weight: 600;
  color: var(--accent-cyan);
  margin-right: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.digits-box {
  display: flex;
  align-items: baseline;
  justify-content: center;
}

.time-digit {
  font-size: clamp(64px, 20vw, 160px);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -2px;
  font-variant-numeric: tabular-nums;
  transition: color var(--transition-speed) ease;
}

.time-colon {
  font-size: clamp(54px, 16vw, 130px);
  font-weight: 300;
  margin: 0 4px;
  color: var(--text-muted);
  animation: colon-blink 1s steps(1) infinite;
}

@keyframes colon-blink {
  50% { opacity: 0.2; }
}

.time-seconds-box {
  display: inline-flex;
  align-items: baseline;
}

.time-colon-sec {
  font-size: clamp(32px, 10vw, 80px);
  font-weight: 300;
  color: var(--text-muted);
  margin: 0 2px;
}

.time-digit-sec {
  font-size: clamp(34px, 11vw, 90px);
  font-weight: 600;
  color: var(--accent-cyan);
  font-variant-numeric: tabular-nums;
}

.date-wrapper {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  margin-top: 16px;
  font-size: clamp(14px, 3.5vw, 22px);
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.5px;
}

.weekday-text {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 10px;
  border-radius: 6px;
}

.wake-hint {
  margin-top: 24px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.35);
  letter-spacing: 0.5px;
  transition: opacity 0.4s ease;
}

.wake-hint strong {
  color: var(--accent-purple);
  font-weight: 600;
}

/* === 時鐘風格變體 === */
/* 科技現代 */
.style-modern .time-digit {
  font-weight: 700;
  text-shadow: 0 0 30px rgba(56, 189, 248, 0.25);
}

/* 極簡優雅 */
.style-minimal .time-digit {
  font-weight: 200;
  letter-spacing: 4px;
}
.style-minimal .time-colon {
  font-weight: 100;
}

/* 霓虹微光 */
.style-neon .time-digit {
  color: #38bdf8;
  text-shadow: 0 0 10px #38bdf8, 0 0 30px rgba(56, 189, 248, 0.6);
}
.style-neon .time-digit-sec {
  color: #c084fc;
  text-shadow: 0 0 10px #c084fc, 0 0 20px rgba(192, 132, 252, 0.5);
}

/* 經典等寬 */
.style-mono {
  font-family: "SF Mono", Menlo, Monaco, Consolas, "Courier New", monospace;
}

/* === 底部控制列 === */
.bottom-bar {
  width: 100%;
  max-width: 500px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 10;
  transition: opacity 0.4s ease;
}

.btn-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-main);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-pill:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.16);
}

.btn-pill.active {
  background: rgba(56, 189, 248, 0.2);
  border-color: rgba(56, 189, 248, 0.5);
  color: #38bdf8;
}

.btn-mic-glow {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #38bdf8, #a855f7);
  border: none;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(168, 85, 247, 0.35);
  transition: all 0.25s ease;
}

.btn-mic-glow:active {
  transform: scale(0.9);
  box-shadow: 0 2px 10px rgba(168, 85, 247, 0.5);
}

.btn-mic-glow.listening {
  animation: pulse-ring 1.5s infinite;
}

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(168, 85, 247, 0.6); }
  70% { box-shadow: 0 0 0 18px rgba(168, 85, 247, 0); }
  100% { box-shadow: 0 0 0 0 rgba(168, 85, 247, 0); }
}

/* === 語音互動懸浮卡 (Gemini Assistant Panel) === */
.voice-assistant-card {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 20px) + 80px);
  width: calc(100% - 40px);
  max-width: 520px;
  background: rgba(18, 18, 28, 0.88);
  border: 1px solid rgba(168, 85, 247, 0.3);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  border-radius: 20px;
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.6), 0 0 30px rgba(168, 85, 247, 0.2);
  z-index: 50;
  opacity: 0;
  transform: translateY(30px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.voice-assistant-card.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.voice-visualizer {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.orb {
  position: relative;
  width: 36px;
  height: 36px;
}

.core-glow {
  position: absolute;
  inset: 6px;
  background: radial-gradient(circle, #38bdf8 0%, #a855f7 100%);
  border-radius: 50%;
  box-shadow: 0 0 14px #a855f7;
}

.ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: #38bdf8;
  border-bottom-color: #a855f7;
  animation: spin-ring 2s linear infinite;
}

.ring-2 {
  inset: -4px;
  animation-duration: 3s;
  animation-direction: reverse;
  border-top-color: #c084fc;
  border-bottom-color: #60a5fa;
}

@keyframes spin-ring {
  100% { transform: rotate(360deg); }
}

.voice-feedback {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.voice-status {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--accent-purple);
  letter-spacing: 0.8px;
}

.voice-transcript {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-main);
  white-space: pre-wrap;
  word-break: break-word;
}

.voice-reply {
  font-size: 14px;
  line-height: 1.4;
  color: #cbd5e1;
  margin-top: 4px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow-y: auto;
}

.close-assistant-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

/* === 夜間極暗模式 (Auto-Dim & Manual Dim) === */
.dim-overlay {
  position: fixed;
  inset: 0;
  background-color: #000000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.2s ease-in-out;
  z-index: 5;
}

/* 當進入極暗模式時 */
.is-dimmed .dim-overlay {
  opacity: 0.88;
}

.is-dimmed .top-bar,
.is-dimmed .bottom-bar,
.is-dimmed .wake-hint {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s ease;
}

.is-dimmed .time-digit {
  color: rgba(255, 255, 255, 0.22) !important;
  text-shadow: none !important;
}

.is-dimmed .time-digit-sec {
  color: rgba(255, 255, 255, 0.15) !important;
  text-shadow: none !important;
}

.is-dimmed .time-colon,
.is-dimmed .time-colon-sec {
  color: rgba(255, 255, 255, 0.1) !important;
  animation: none !important;
}

.is-dimmed .date-wrapper {
  color: rgba(255, 255, 255, 0.15);
}

.is-dimmed .weekday-text {
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.2);
}

/* 夜間風格變體 */
/* 琥珀夜光 */
body.dim-amber.is-dimmed .time-digit,
body.dim-amber.is-dimmed .time-digit-sec {
  color: rgba(251, 146, 60, 0.28) !important;
}
body.dim-amber.is-dimmed .date-wrapper {
  color: rgba(251, 146, 60, 0.2) !important;
}

/* 極夜暗紅 */
body.dim-red.is-dimmed .time-digit,
body.dim-red.is-dimmed .time-digit-sec {
  color: rgba(248, 113, 113, 0.28) !important;
}
body.dim-red.is-dimmed .date-wrapper {
  color: rgba(248, 113, 113, 0.2) !important;
}

/* 點擊暫時喚醒狀態 */
.temp-awake .top-bar,
.temp-awake .bottom-bar,
.temp-awake .wake-hint {
  opacity: 1 !important;
  pointer-events: auto !important;
}

.temp-awake .dim-overlay {
  opacity: 0.3 !important;
}

/* === 設定彈窗 (iOS Frosted Modal) === */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  background: #12131c;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.8);
  transform: translateY(20px) scale(0.96);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-backdrop.open .modal-card {
  transform: translateY(0) scale(1);
}

.modal-header {
  padding: 18px 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.modal-body {
  padding: 20px 22px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.settings-group {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.settings-group legend {
  padding: 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-cyan);
}

.setting-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.label-title {
  font-size: 14px;
  font-weight: 500;
  color: #e2e8f0;
}

.label-desc {
  font-size: 12px;
  color: #64748b;
}

.toggle-row {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

.auto-model-info {
  margin-top: 6px;
  padding: 8px 12px;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 10px;
  font-size: 13px;
  color: #38bdf8;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

.btn-pill-small {
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #f8fafc;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-pill-small:active {
  transform: scale(0.94);
  background: rgba(255, 255, 255, 0.18);
}

input[type="text"],
input[type="password"],
select {
  width: 100%;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  color: var(--text-main);
  font-size: 14px;
  outline: none;
  margin-top: 6px;
  transition: border-color 0.2s ease;
}

input[type="text"]:focus,
input[type="password"]:focus,
select:focus {
  border-color: var(--accent-cyan);
}

input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent-purple);
  cursor: pointer;
}

/* 滑桿與光感指示條 */
.slider-header {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent-cyan);
  margin-top: 8px;
}

.meter-bar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
  margin: 6px 0;
}

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

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  justify-content: flex-end;
}

.btn-primary {
  padding: 10px 24px;
  background: linear-gradient(135deg, #38bdf8, #818cf8);
  border: none;
  border-radius: 10px;
  color: #000;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

/* 橫向模式 (iPhone 橫置在桌上當鬧鐘/桌鐘) 優化 */
@media (orientation: landscape) {
  .app-container {
    padding: calc(env(safe-area-inset-top, 10px) + 4px)
             calc(env(safe-area-inset-right, 24px) + 20px)
             calc(env(safe-area-inset-bottom, 10px) + 4px)
             calc(env(safe-area-inset-left, 24px) + 20px);
  }

  .time-digit {
    font-size: clamp(60px, 22vh, 150px);
  }

  .time-colon {
    font-size: clamp(50px, 18vh, 120px);
  }

  .date-wrapper {
    margin-top: 6px;
    font-size: clamp(12px, 3.5vh, 18px);
  }

  .wake-hint {
    margin-top: 8px;
    font-size: 12px;
  }

  .voice-assistant-card {
    bottom: calc(env(safe-area-inset-bottom, 10px) + 50px);
  }
}
