/* iOS 18 Component Library */

/* Container Layout */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--spacing-xl) var(--spacing-lg);
}

.container-narrow {
  max-width: 680px;
  margin: 0 auto;
  padding: var(--spacing-xl) var(--spacing-lg);
}

/* Page Headers */
.page-title {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -1px;
  color: var(--text-primary);
  margin-bottom: var(--spacing-lg);
  text-align: center;
}

.page-subtitle {
  font-size: 17px;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: var(--spacing-xl);
  letter-spacing: -0.4px;
}

/* Form Components */
.form-group {
  margin-bottom: var(--spacing-lg);
}

.form-label {
  display: block;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--spacing-xs);
  letter-spacing: -0.3px;
}

.form-error {
  font-size: 14px;
  color: var(--ios-red);
  margin-top: var(--spacing-xs);
  letter-spacing: -0.2px;
}

/* Task Card - iOS 18 Style (NO side border) */
.task-card {
  background: var(--bg-primary);
  backdrop-filter: blur(60px) saturate(180%);
  -webkit-backdrop-filter: blur(60px) saturate(180%);
  border: 0.5px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  margin-bottom: var(--spacing-md);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.task-card:hover {
  box-shadow: var(--shadow-lg);
}

.task-card:active {
  transform: none;
}

.task-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--spacing-sm);
  gap: var(--spacing-md);
}

.task-title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.5px;
  color: var(--text-primary);
  line-height: 1.3;
}

.task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-md);
  font-size: 15px;
  color: var(--text-tertiary);
  margin-top: var(--spacing-xs);
}

.task-meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: -0.3px;
}

.task-meta-item::before {
  content: '';
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-tertiary);
}

.task-meta-item:first-child::before {
  display: none;
}

/* Question Card - iOS 18 Style (NO side border) */
.question-card {
  background: var(--bg-primary);
  backdrop-filter: blur(60px) saturate(180%);
  -webkit-backdrop-filter: blur(60px) saturate(180%);
  border: 0.5px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--spacing-xl);
  margin-bottom: var(--spacing-lg);
  box-shadow: var(--shadow-sm);
}

.question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-lg);
  flex-wrap: wrap;
  gap: var(--spacing-sm);
}

.question-number {
  font-size: 15px;
  font-weight: 600;
  color: var(--ios-blue);
  letter-spacing: -0.3px;
}

.question-text {
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.5px;
  color: var(--text-primary);
  line-height: 1.5;
  margin-bottom: var(--spacing-lg);
}

/* Options List - iOS 18 Style */
.options-list {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.option-item {
  background: var(--bg-secondary);
  border: 2px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.option-item:hover {
  background: var(--bg-tertiary);
  border-color: var(--ios-blue);
  transform: scale(1.01);
}

.option-item:active {
  transform: scale(0.99);
}

.option-item.selected {
  background: rgba(0, 122, 255, 0.1);
  border-color: var(--ios-blue);
  border-width: 2px;
}

.option-label {
  font-weight: 600;
  color: var(--ios-blue);
  min-width: 28px;
  font-size: 17px;
  letter-spacing: -0.4px;
}

.option-text {
  flex: 1;
  font-size: 17px;
  color: var(--text-primary);
  letter-spacing: -0.4px;
  line-height: 1.4;
}

/* Timer Display - iOS Glass Time Chip */
.timer-display {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;

  display: inline-flex;
  align-items: center;
  gap: 10px;

  height: 44px;
  padding: 0 14px;

  background: var(--bg-primary);
  backdrop-filter: blur(60px) saturate(180%);
  -webkit-backdrop-filter: blur(60px) saturate(180%);

  border-radius: 999px;
  border: 0.5px solid var(--border-color);
  box-shadow:
    0 14px 44px rgba(0, 0, 0, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

/* hide label for minimal look */
.timer-label {
  display: none;
}

/* icon */
.timer-display::before {
  content: '';
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: rgba(60, 60, 67, 0.16);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
  display: inline-block;
}

.timer-value {
  font-size: 17px;
  font-weight: 800;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.4px;
}

/* warning / danger are applied to timerValue via className */
.timer-warning {
  color: var(--ios-orange);
}

.timer-danger {
  color: var(--ios-red);
}

/* subtle glow breathing on danger (low distraction) */
.timer-display:has(.timer-danger) {
  box-shadow:
    0 14px 44px rgba(0, 0, 0, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    0 0 0 6px rgba(255, 59, 48, 0.08);
  animation: timerGlow 2s ease-in-out infinite;
}

@keyframes timerGlow {
  0%, 100% {
    box-shadow:
      0 14px 44px rgba(0, 0, 0, 0.12),
      inset 0 1px 0 rgba(255, 255, 255, 0.45),
      0 0 0 6px rgba(255, 59, 48, 0.06);
  }
  50% {
    box-shadow:
      0 16px 54px rgba(0, 0, 0, 0.14),
      inset 0 1px 0 rgba(255, 255, 255, 0.50),
      0 0 0 8px rgba(255, 59, 48, 0.10);
  }
}

@media (max-width: 768px) {
  .timer-display {
    top: 12px;
    right: 12px;
    height: 42px;
  }
}

/* Progress Bar - iOS 18 Style */
.progress-bar {
  width: 100%;
  height: 6px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: calc(var(--radius-sm) - 13px);
  overflow: hidden;
  margin-bottom: var(--spacing-lg);
}

.progress-fill {
  height: 100%;
  background: var(--ios-blue);
  border-radius: calc(var(--radius-sm) - 13px);
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Navigation Bar - iOS 18 Style */
.navbar {
  background: var(--bg-primary);
  backdrop-filter: blur(60px) saturate(180%);
  -webkit-backdrop-filter: blur(60px) saturate(180%);
  border-bottom: 0.5px solid var(--border-color);
  padding: 16px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}

.navbar-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--spacing-lg);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.navbar-brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.navbar-actions {
  display: flex;
  gap: var(--spacing-sm);
  align-items: center;
}

.user-info {
  font-size: 15px;
  color: var(--text-secondary);
  letter-spacing: -0.3px;
  padding: 0 var(--spacing-sm);
}

/* Modal - iOS 18 Style */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-overlay);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  animation: modalFadeIn 0.18s ease-out;
}

.modal-content {
  background: var(--bg-primary);
  backdrop-filter: blur(60px) saturate(180%);
  -webkit-backdrop-filter: blur(60px) saturate(180%);
  border-radius: var(--radius-xl);
  padding: var(--spacing-xl);
  max-width: 480px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  border: 0.5px solid var(--border-color);
  /* 內高光讓玻璃更立體：淺色用亮、暗色用暗（避免白色高光） */
  box-shadow:
    0 22px 70px rgba(0, 0, 0, 0.24),
    inset 0 1px 0 var(--glass-highlight, rgba(255, 255, 255, 0.55)),
    inset 0 0 0 0.5px var(--glass-highlight-soft, rgba(255, 255, 255, 0.22));
  animation: modalScaleIn 0.18s cubic-bezier(0.2, 0.9, 0.2, 1);
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

/* 關閉動畫：由 JS 在 closeModal 時加上 fade-out / scale-out */
.fade-out {
  animation: modalFadeOut 0.14s ease-in forwards;
}

.scale-out {
  animation: modalScaleOut 0.14s ease-in forwards;
}

@keyframes modalFadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes modalScaleOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(6px) scale(0.985); }
}


.modal-header {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.8px;
  margin-bottom: var(--spacing-md);
  color: var(--text-primary);
}

.modal-body {
  font-size: 17px;
  color: var(--text-secondary);
  margin-bottom: var(--spacing-xl);
  line-height: 1.5;
  letter-spacing: -0.4px;
}

.modal-footer {
  display: flex;
  gap: var(--spacing-sm);
  justify-content: flex-end;
}

/* Modal Actions (used by Utils.confirm) */
.modal-actions {
  display: flex;
  gap: var(--spacing-sm);
  justify-content: flex-end;
}

/* Modal polish - closer to iOS glass */
.modal-overlay {
  background: rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(26px) saturate(140%);
  -webkit-backdrop-filter: blur(26px) saturate(140%);
}

.modal-content {
  /* keep existing vars but add subtle highlight edge */
  border: 0.5px solid var(--border-color);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.22);
}

.modal-header {
  line-height: 1.2;
}

.modal-body {
  line-height: 1.6;
}

.modal-actions .btn {
  min-width: 120px;
  height: 44px; /* iOS 常見觸控高度 */
  border-radius: var(--radius-sm);
  padding: 0 18px;
}

/* iOS 風格：取消灰底、確認藍底 */
.modal-actions .btn.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 0.5px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.modal-actions .btn.btn-secondary:hover {
  background: var(--bg-tertiary);
}

.modal-actions .btn.btn-primary {
  background: var(--ios-blue);
  color: white;
  box-shadow: 0 6px 18px rgba(10, 132, 255, 0.28);
}

.modal-actions .btn.btn-primary:hover {
  background: #0051D5;
}

.modal-actions .btn:active {
  transform: scale(0.98);
}

@media (max-width: 420px) {
  /* 行動端也保持與桌面一致：右下角水平排列，不置中 */
  .modal-actions {
    justify-content: flex-end;
    flex-direction: row;
    gap: 12px;
  }

  .modal-actions .btn {
    width: auto;
    flex: 0 0 auto;
    min-width: 112px;
  }
}

/* -------------------------------------------------
   Loading Layout Helper
------------------------------------------------- */

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
}

/* -------------------------------------------------
   HUD / Toast System (iOS Glass)
   - showLoading: .hud-overlay + .hud
   - showToast: .toast + variants
------------------------------------------------- */

.hud-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(18px) saturate(130%);
  -webkit-backdrop-filter: blur(18px) saturate(130%);
  animation: hudFadeIn 0.16s ease-out;
}

@keyframes hudFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.hud {
  width: min(520px, calc(100vw - 44px));
  background: var(--bg-primary);
  backdrop-filter: blur(60px) saturate(180%);
  -webkit-backdrop-filter: blur(60px) saturate(180%);
  border-radius: var(--radius-xl);
  border: 0.5px solid rgba(255, 255, 255, 0.62);
  box-shadow:
    0 22px 70px rgba(0, 0, 0, 0.20),
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    inset 0 0 0 0.5px rgba(255, 255, 255, 0.22);
  padding: 24px 22px;
  text-align: center;
  animation: hudScaleIn 0.16s cubic-bezier(0.2, 0.9, 0.2, 1);
}

/* Center loading content in HUD */
.hud .spinner-ring,
.hud .loading-spinner {
  display: block;
  margin: 0 auto;
}

@keyframes hudScaleIn {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.hud-title {
  margin-top: 12px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

.hud-subtitle {
  margin-top: 6px;
  font-size: 14px;
  letter-spacing: -0.2px;
  color: var(--text-tertiary);
}

.hud-overlay.is-hiding {
  animation: hudFadeOut 0.12s ease-in forwards;
}

.hud-overlay.is-hiding .hud {
  animation: hudScaleOut 0.12s ease-in forwards;
}

@keyframes hudFadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes hudScaleOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(4px) scale(0.985); }
}

/* Toast base */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10001;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  background: var(--bg-primary);
  backdrop-filter: blur(50px) saturate(170%);
  -webkit-backdrop-filter: blur(50px) saturate(170%);
  border: 0.5px solid rgba(255, 255, 255, 0.60);
  box-shadow:
    0 16px 46px rgba(0, 0, 0, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
  color: var(--text-primary);
  animation: toastSlideDownIn 0.18s ease-out;
}

.toast.toast--banner {
  top: 18px;
}

.toast.toast--capsule {
  bottom: 18px;
  border-radius: 999px;
  padding: 12px 16px;
}

@keyframes toastSlideDownIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toastSlideDownOut {
  from { opacity: 1; transform: translateX(-50%) translateY(0); }
  to { opacity: 0; transform: translateX(-50%) translateY(-8px); }
}

@keyframes toastSlideUpIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toastSlideUpOut {
  from { opacity: 1; transform: translateX(-50%) translateY(0); }
  to { opacity: 0; transform: translateX(-50%) translateY(8px); }
}

.toast.is-hiding.toast--banner {
  animation: toastSlideDownOut 0.14s ease-in forwards;
}

.toast.is-hiding.toast--capsule {
  animation: toastSlideUpOut 0.14s ease-in forwards;
}

.toast-icon {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  color: white;
  flex: 0 0 auto;
}

.toast--success .toast-icon { background: var(--ios-green); }
.toast--error .toast-icon { background: var(--ios-red); }
.toast--warning .toast-icon { background: var(--ios-orange); }

.toast-text {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.3px;
  line-height: 1.3;
}

/* -------------------------------------------------
   End HUD / Toast System
------------------------------------------------- */

/* Info Card - iOS 18 Style */
.info-card {
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  padding: var(--spacing-md);
  margin: var(--spacing-md) 0;
}

.info-card.primary {
  background: rgba(0, 122, 255, 0.08);
}

.info-card.success {
  background: rgba(52, 199, 89, 0.08);
}

.info-card.warning {
  background: rgba(255, 149, 0, 0.08);
}

.info-card.danger {
  background: rgba(255, 59, 48, 0.08);
}

/* Empty State Card (Reusable) */
.empty-state-card {
  position: relative;
  overflow: hidden;
  background: var(--bg-primary);
  backdrop-filter: blur(60px) saturate(180%);
  -webkit-backdrop-filter: blur(60px) saturate(180%);
  border-radius: var(--radius-xl);
  border: 0.5px solid rgba(255, 255, 255, 0.62);
  box-shadow:
    0 18px 60px rgba(0, 0, 0, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
  padding: 22px;
}

.empty-state-card::after {
  content: '';
  position: absolute;
  top: -40px;
  right: -40px;
  width: 180px;
  height: 180px;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 30%, rgba(10, 132, 255, 0.20), rgba(10, 132, 255, 0.0) 60%);
  pointer-events: none;
}

.empty-state-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.empty-state-title {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.4px;
  color: var(--text-primary);
  margin: 0;
}

.empty-state-subtitle {
  margin: 8px 0 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.2px;
  color: var(--text-tertiary);
}

.empty-state-actions {
  margin-top: 16px;
  display: flex;
  gap: 10px;
}

.empty-state-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: rgba(10, 132, 255, 0.12);
  border: 0.5px solid rgba(255, 255, 255, 0.55);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.empty-state-icon svg {
  width: 22px;
  height: 22px;
  fill: var(--ios-blue);
}

/* Stats Grid - iOS 18 Style */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--spacing-md);
  margin: var(--spacing-lg) 0;
}

.stat-item {
  background: var(--bg-secondary);
  backdrop-filter: blur(50px) saturate(150%);
  -webkit-backdrop-filter: blur(50px) saturate(150%);
  border: 0.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--spacing-lg);
  text-align: center;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -1.5px;
  color: var(--text-primary);
  margin-bottom: var(--spacing-xs);
}

.stat-label {
  font-size: 14px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

/* Responsive Design */
@media (max-width: 768px) {
  .navbar {
    padding: 10px 0;
  }

  .navbar-content {
    padding: 0 var(--spacing-md);
  }

  .glass-panel {
    padding: var(--spacing-lg);
    border-radius: var(--radius-md);
  }
  
  .page-title {
    font-size: 28px;
  }
  
  .task-header {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .timer-display {
    top: 16px;
    right: 16px;
    padding: 10px 16px;
  }
  
  .timer-value {
    font-size: 24px;
  }
  
  .question-card {
    padding: var(--spacing-lg);
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
  }
}
