/* =========================================
   Phase Colors
   Default = focus red, .break = green
   ========================================= */
.phase-dot, .phase-bar { background-color: #e53e3e; }
.phase-dot.break, .phase-bar.break { background-color: #38a169; }

/* =========================================
   Transition guard — off during load
   ========================================= */
.no-transition .phase-dot,
.no-transition .phase-bar { transition: none; }

body.ready .phase-dot,
body.ready .phase-bar { transition: background-color 0.3s ease; }

.no-transition .toggle { transition: none; }
body.ready .toggle { transition: background-color 0.2s ease; }
body.ready .toggle-knob { transition: transform 0.2s ease; }

/* =========================================
   CSS Variables
   ========================================= */
:root {
  --body-padding: 24px;
  --body-gap: 20px;

  --card-width: 400px;
  --content-width: 560px;
  --nav-width: 560px;
  --card-radius: 16px;

  --timer-font: 80px;
  --timer-padding-v: 24px;
  --timer-padding-h: 32px;

  --btn-font: 16px;
  --btn-padding-v: 12px;

  --row-padding-v: 14px;
  --row-padding-h: 24px;
  --header-padding-v: 16px;
  --header-padding-h: 24px;
}

/* =========================================
   Reset & Base
   ========================================= */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
  gap: var(--body-gap);
  background-color: #f3f4f6;
  color: #1e1e1e;
  padding: clamp(40px, 8vh, 100px) var(--body-padding) 0 var(--body-padding);
}

/* =========================================
   Focus visible — keyboard a11y
   ========================================= */
:focus-visible {
  outline: 2px solid #1e1e1e;
  outline-offset: 2px;
}

/* =========================================
   Card base
   ========================================= */
.card, .nav-card {
  max-width: 100%;
  border-radius: var(--card-radius);
  background: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  overflow: hidden;
}

.card {
  width: var(--card-width);
}

.nav-card {
  width: var(--content-width);
  padding: 0;
}

/* =========================================
   ① Timer Card
   ========================================= */
.timer-card {
  text-align: center;
}

.phase-bar {
  height: 3px;
  width: 100%;
}

.timer-body {
  padding: var(--timer-padding-v) var(--timer-padding-h) var(--timer-padding-v);
}

.phase-indicator {
  display: none;
}

.task-label-wrap {
  position: relative;
  margin: 0 auto 12px;
  width: 180px;
  max-width: 100%;
}

.task-label-input {
  display: block;
  width: 100%;
  padding: 2px 0;
  font-size: 15px;
  font-weight: 400;
  font-family: inherit;
  color: #555;
  text-align: center;
  border: none;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  background: transparent;
  outline: none;
}

.task-label-input:focus {
  border-bottom-color: #d4d4d8;
}

.task-label-input[readonly] {
  color: #999;
  cursor: default;
  border-bottom-color: transparent;
}

.task-label-input::placeholder {
  color: #bbb;
}

.task-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 200px;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(4px);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  z-index: 10;
  padding: 4px 0;
}

.task-dropdown[hidden] {
  display: none;
}

.task-dropdown-option {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: none;
  color: #1e1e1e;
  font-size: 14px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}

.task-dropdown-option:hover,
.task-dropdown-option:focus {
  background: #f3f4f6;
  outline: none;
}

.timer-display {
  font-size: var(--timer-font);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 4px;
  line-height: 1.1;
  margin-bottom: 8px;
  color: #1e1e1e;
}

.rounds-info {
  font-size: 14px;
  color: #777;
  margin-bottom: 8px;
}

.message {
  font-size: 16px;
  font-weight: 500;
  min-height: 24px;
  color: #666;
  animation: fadeIn 0.3s ease;
}

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

/* =========================================
   ② Controls
   ========================================= */
.controls {
  display: flex;
  gap: 10px;
  width: var(--card-width);
  max-width: 100%;
}

.controls .btn {
  padding: var(--btn-padding-v) 0;
  font-size: var(--btn-font);
  font-weight: 600;
  border-radius: 12px;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease, transform 0.1s;
  text-align: center;
}

.btn-main { flex: 50; }
.btn-reset { flex: 25; }
.btn-skip  { flex: 25; }

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn-primary {
  background-color: #1e1e1e;
  color: #fff;
  border: none;
}
.btn-primary:hover:not(:disabled) {
  background-color: #333;
}

.btn-secondary {
  background-color: #fff;
  color: #1e1e1e;
  border: 1px solid #d4d4d8;
}
.btn-secondary:hover:not(:disabled) {
  background-color: #f5f5f5;
}

.btn:disabled {
  opacity: 0.35;
  cursor: default;
}

/* =========================================
   ③ Control Card (时长 / 提醒)
   ========================================= */
.settings-card {
  padding: 0;
}

.settings-header {
  font-size: 13px;
  font-weight: 600;
  color: #888;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: var(--header-padding-v) var(--header-padding-h) 12px;
  border-bottom: 1px solid #f0f0f0;
}

.stepper-list {
  display: flex;
  flex-direction: column;
  padding: 4px 0 8px;
}

.stepper-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--row-padding-v) var(--row-padding-h);
}

.stepper-label {
  font-size: 15px;
  font-weight: 500;
  color: #1e1e1e;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 4px;
}

.stepper-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: #f1f3f5;
  color: #1e1e1e;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, opacity 0.15s ease, transform 0.1s;
  flex-shrink: 0;
}
.stepper-btn:hover:not(:disabled) {
  background: #e4e7eb;
}
.stepper-btn:active:not(:disabled) {
  transform: scale(0.92);
}
.stepper-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.stepper-input {
  width: 40px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  font-family: inherit;
  color: #1e1e1e;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  outline: none;
  padding: 2px 0;
  -moz-appearance: textfield;
}
.stepper-input::-webkit-outer-spin-button,
.stepper-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.stepper-input:focus {
  border-bottom-color: #d4d4d8;
}

/* =========================================
   Toggle rows
   ========================================= */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--row-padding-v) var(--row-padding-h);
}

.toggle-label {
  font-size: 15px;
  font-weight: 500;
  color: #1e1e1e;
}

.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 11px;
  border: none;
  cursor: pointer;
  background: #d4d4d8;
  flex-shrink: 0;
  padding: 0;
}

.toggle[aria-checked="true"] {
  background: #e53e3e;
}
.toggle[aria-checked="true"].break {
  background: #38a169;
}

.toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle[aria-checked="true"] .toggle-knob {
  transform: translateX(18px);
}

.toggle:disabled {
  opacity: 0.4;
  cursor: default;
}

/* =========================================
   Page wrapper
   ========================================= */
.page {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--body-gap);
  width: 100%;
}

.page[hidden] {
  display: none;
}

/* =========================================
   Nav bar — bottom, all devices
   ========================================= */
.nav-bar {
  display: flex;
  width: var(--nav-width);
  max-width: 100%;
  height: 48px;
  background: #fff;
  flex-shrink: 0;
  margin-top: auto;
  border-radius: var(--card-radius) var(--card-radius) 0 0;
  border-top: 1px solid #f0f0f0;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  position: relative;
}

.nav-label {
  font-size: 13px;
  font-weight: 400;
  color: #888;
}

.nav-item-active .nav-label {
  font-weight: 500;
  color: #1e1e1e;
}

.nav-line {
  display: block;
  width: 0;
  height: 2px;
  border-radius: 1px;
  background: #1e1e1e;
  transition: width 0.2s ease;
}

.nav-item-active .nav-line {
  width: 24px;
}

/* =========================================
   Stats page
   ========================================= */
.page-title-bar {
  font-size: 13px;
  font-weight: 600;
  color: #888;
  letter-spacing: 2px;
  text-align: center;
  padding: var(--header-padding-v) var(--header-padding-h) 12px;
  border-bottom: 1px solid #f0f0f0;
}

.stats-body {
  padding: 16px var(--header-padding-h) 16px;
}

/* Today card */
.stats-today-card {
  background: #f5f6f8;
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  margin-bottom: 24px;
}

.stats-today-big {
  font-size: clamp(28px, 3vw, 36px);
  font-weight: 700;
  color: #1e1e1e;
  line-height: 1.2;
}

.stats-today-streak {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 400;
  color: #777;
}

.stats-empty {
  margin-top: 8px;
  font-size: 14px;
  color: #888;
  line-height: 1.6;
}

/* Sections */
.stats-section {
  margin-bottom: 24px;
}

.stats-section-title {
  font-size: 14px;
  font-weight: 600;
  color: #888;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

/* Weekly overview */
.stats-week-overview {
  font-size: 14px;
  font-weight: 400;
  color: #555;
  line-height: 1.5;
}

/* Task list */
.stats-task-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.task-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 15px;
  font-weight: 400;
  color: #1e1e1e;
}

/* Heatmap */
.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(7, clamp(14px, 2vw, 20px));
  gap: clamp(3px, 0.5vw, 5px);
  justify-content: start;
}

.heatmap-cell {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 3px;
  background: #ebedf0;
}

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  font-size: 11px;
  color: #888;
}

.heatmap-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* Divider + Total */
.stats-divider {
  height: 1px;
  background: #f0f0f0;
  margin: 0 0 12px;
}

.stats-total {
  font-size: 15px;
  font-weight: 400;
  color: #1e1e1e;
}

/* =========================================
   System settings page
   ========================================= */
.settings-body-page {
  padding: 4px 0 12px;
}

.settings-section-title {
  font-size: 13px;
  font-weight: 600;
  color: #888;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: var(--row-padding-v) var(--row-padding-h) 8px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--row-padding-v) var(--row-padding-h);
  font-size: 15px;
  font-weight: 500;
  color: #1e1e1e;
}

.btn-small {
  padding: 6px 16px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
}

.btn-confirm {
  background-color: #e53e3e !important;
  color: #fff !important;
  border-color: #e53e3e !important;
}

.about-text {
  padding: 8px var(--row-padding-h) 12px;
  font-size: 14px;
  color: #777;
  line-height: 1.6;
}

/* =========================================
   Immersive overlay
   ========================================= */
#immersive-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0d0d0d;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

#immersive-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.immersive-time {
  font-size: clamp(72px, 16vw, 200px);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  line-height: 0.92;
  color: #f0f0f0;
  transform: scale(0.97);
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

#immersive-overlay.active .immersive-time {
  transform: scale(1);
}

.immersive-quote {
  position: absolute;
  bottom: 22vh;
  left: 50%;
  transform: translateX(-50%);
  max-width: clamp(320px, 40vw, 600px);
  font-size: clamp(12px, 1.5vw, 20px);
  font-weight: 300;
  font-style: italic;
  color: #666;
  letter-spacing: 0.03em;
  line-height: 1.6;
  text-align: center;
  user-select: none;
}

.immersive-quote span {
  margin-left: 1.5em;
  font-style: normal;
  color: #555;
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  #immersive-overlay,
  .immersive-time {
    transition: none !important;
  }
}

/* =========================================
   Tablet: bottom nav + unified 400px widths
   ========================================= */
@media (max-width: 899px) {
  :root {
    --content-width: 400px;
    --nav-width: 400px;
  }
}

@media (min-width: 1200px) {
  :root {
    --content-width: 640px;
    --nav-width: 640px;
  }
}

/* =========================================
   Mobile: compact sizes
   ========================================= */
@media (max-width: 420px) {
  :root {
    --body-padding: 12px;
    --body-gap: 12px;
    --timer-font: 64px;
    --btn-font: 15px;
    --btn-padding-v: 10px;
    --timer-padding-v: 20px;
    --timer-padding-h: 20px;
    --row-padding-h: 20px;
    --header-padding-h: 20px;
    --card-radius: 12px;
  }
}
