/* ===== Theme tokens ===== */
:root {
  --bg: #f6f3ee;
  --bg-elev: #ffffff;
  --text: #1f2430;
  --text-soft: #5b6275;
  --text-mute: #8a90a2;
  --border: rgba(20, 24, 36, 0.08);
  --border-strong: rgba(20, 24, 36, 0.16);
  --shadow-sm: 0 2px 6px rgba(20, 24, 36, 0.04);
  --shadow-md: 0 8px 28px rgba(20, 24, 36, 0.08);
  --shadow-lg: 0 24px 60px rgba(20, 24, 36, 0.12);

  --primary: #ef5a4b;       /* tomato */
  --primary-hover: #e04938;
  --primary-soft: rgba(239, 90, 75, 0.12);
  --short: #4cb080;          /* mint  */
  --short-soft: rgba(76, 176, 128, 0.12);
  --long: #4a8fd6;           /* blue  */
  --long-soft: rgba(74, 143, 214, 0.12);
  --accent: var(--primary);
  --accent-soft: var(--primary-soft);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
}

[data-theme="dark"] {
  --bg: #14161d;
  --bg-elev: #1c1f29;
  --text: #ecedf2;
  --text-soft: #b6bac7;
  --text-mute: #7d8294;
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.14);
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 32px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 30px 80px rgba(0, 0, 0, 0.5);
  --primary-soft: rgba(239, 90, 75, 0.18);
  --short-soft: rgba(76, 176, 128, 0.18);
  --long-soft: rgba(74, 143, 214, 0.18);
}

/* mode-specific accent on body */
body[data-mode="focus"] { --accent: var(--primary); --accent-soft: var(--primary-soft); }
body[data-mode="short"] { --accent: var(--short);   --accent-soft: var(--short-soft); }
body[data-mode="long"]  { --accent: var(--long);    --accent-soft: var(--long-soft); }

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
    "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  transition: background-color 0.4s ease, color 0.3s ease;
}
button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input { font-family: inherit; }
ul { list-style: none; padding: 0; margin: 0; }
h2, h3, h4 { margin: 0; }

/* ===== Background orbs ===== */
.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.4;
  pointer-events: none;
  z-index: 0;
  transition: background 0.6s ease;
}
.orb-1 {
  width: 480px; height: 480px;
  top: -120px; left: -120px;
  background: var(--accent);
}
.orb-2 {
  width: 380px; height: 380px;
  bottom: -100px; right: -80px;
  background: var(--accent);
  opacity: 0.25;
}

/* ===== Top bar ===== */
.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 36px;
  max-width: 1240px;
  margin: 0 auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.3px;
}
.brand-icon { font-size: 22px; }
.brand-text .dot { color: var(--accent); }
.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}
.icon-btn:hover { background: var(--border); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }

[data-theme="light"] .icon-moon,
:root:not([data-theme="dark"]) .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }

/* ===== Layout ===== */
.layout {
  position: relative;
  z-index: 1;
  max-width: 1240px;
  margin: 8px auto 60px;
  padding: 0 36px;
  display: grid;
  grid-template-columns: minmax(380px, 1fr) minmax(420px, 1.1fr);
  gap: 28px;
}
@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; padding: 0 20px; }
  .topbar { padding: 18px 20px; }
}

/* ===== Card base ===== */
.timer-card,
.todo-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 28px;
  transition: background 0.3s ease, border-color 0.3s ease;
}

/* ===== Timer ===== */
.mode-tabs {
  display: inline-flex;
  background: var(--bg);
  padding: 4px;
  border-radius: 999px;
  border: 1px solid var(--border);
  gap: 2px;
}
.mode-tab {
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-soft);
  transition: all 0.25s ease;
}
.mode-tab:hover { color: var(--text); }
.mode-tab.active {
  background: var(--bg-elev);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.timer-ring-wrap {
  position: relative;
  width: 320px;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  margin: 32px auto 18px;
}
.timer-ring {
  width: 100%; height: 100%;
  transform: rotate(-90deg);
}
.ring-track {
  fill: none;
  stroke: var(--border);
  stroke-width: 8;
}
.ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 628.318;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.95s linear, stroke 0.4s ease;
  filter: drop-shadow(0 2px 6px var(--accent-soft));
}
.timer-display {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.time-text {
  font-size: 64px;
  font-weight: 300;
  letter-spacing: -2px;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  color: var(--text);
}
.phase-text {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-mute);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.active-task-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 16px;
  margin: 0 auto 18px;
  background: var(--accent-soft);
  border-radius: 999px;
  font-size: 13px;
  max-width: fit-content;
}
.active-task-row[hidden] { display: none; }
.active-task-label { color: var(--text-mute); }
.active-task-name {
  color: var(--accent);
  font-weight: 600;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timer-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 28px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  transition: transform 0.12s ease, background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn-ghost {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-soft);
  width: 44px; height: 44px;
  padding: 0;
  border-radius: 12px;
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); }
.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 12px 32px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.5px;
  box-shadow: 0 6px 16px var(--accent-soft);
  min-width: 130px;
}
.btn-primary:hover { background: var(--primary-hover); filter: brightness(1.02); }
body[data-mode="short"] .btn-primary:hover { background: #3e9d70; }
body[data-mode="long"]  .btn-primary:hover { background: #3a7fc5; }

.timer-stats {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding-top: 22px;
  border-top: 1px solid var(--border);
}
.stat { text-align: center; }
.stat-num {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.stat-label {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-mute);
}
.stat-divider {
  width: 1px;
  height: 28px;
  background: var(--border);
}

/* ===== Todo ===== */
.todo-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.todo-header h2 { font-size: 20px; font-weight: 600; }
.filter-tabs {
  display: inline-flex;
  background: var(--bg);
  border-radius: 999px;
  border: 1px solid var(--border);
  padding: 3px;
}
.filter-tab {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--text-soft);
  transition: all 0.2s ease;
}
.filter-tab:hover { color: var(--text); }
.filter-tab.active {
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.todo-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.todo-input,
.estimate-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.todo-input { flex: 1; }
.estimate-input { width: 64px; text-align: center; }
.todo-input:focus,
.estimate-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.btn-add {
  padding: 0 20px;
  min-width: 0;
  font-size: 14px;
}

.todo-list {
  max-height: 420px;
  overflow-y: auto;
  margin: 0 -6px;
  padding: 0 6px;
}
.todo-list::-webkit-scrollbar { width: 6px; }
.todo-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.todo-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid transparent;
  margin-bottom: 8px;
  transition: all 0.2s ease;
  animation: slideIn 0.25s ease;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.todo-item:hover {
  border-color: var(--border-strong);
}
.todo-item.active-task {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.todo-item.done .todo-text {
  color: var(--text-mute);
  text-decoration: line-through;
}

.checkbox {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.checkbox:hover { border-color: var(--accent); }
.checkbox.checked {
  background: var(--accent);
  border-color: var(--accent);
}
.checkbox.checked svg { display: block; color: #fff; }
.checkbox svg { display: none; }

.todo-text {
  flex: 1;
  font-size: 14.5px;
  color: var(--text);
  word-break: break-word;
  cursor: text;
}
.todo-text[contenteditable="true"] {
  outline: none;
  background: var(--bg-elev);
  padding: 2px 6px;
  border-radius: 6px;
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.pomo-count {
  font-size: 12px;
  color: var(--text-mute);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
}

.todo-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.todo-item:hover .todo-actions,
.todo-item.active-task .todo-actions { opacity: 1; }
.todo-actions .icon-btn {
  width: 30px; height: 30px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-mute);
  font-size: 13.5px;
}
.empty-state .empty-icon { font-size: 32px; margin-bottom: 8px; opacity: 0.5; }

.todo-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-mute);
}
.link-btn {
  font-size: 12.5px;
  color: var(--text-soft);
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s ease;
}
.link-btn:hover { color: var(--accent); background: var(--accent-soft); }

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
.modal[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 17, 25, 0.5);
  backdrop-filter: blur(4px);
}
.modal-panel {
  position: relative;
  width: min(440px, 92vw);
  background: var(--bg-elev);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  animation: zoomIn 0.22s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}
@keyframes zoomIn {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 17px; font-weight: 600; }
.modal-body { padding: 22px 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.modal-footer .btn-ghost {
  width: auto; height: auto;
  padding: 10px 18px;
}

.setting-group { margin-bottom: 18px; }
.setting-group:last-child { margin-bottom: 0; }
.setting-group h4 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-mute);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.setting-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.setting-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-soft);
}
.setting-grid input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: all 0.2s ease;
}
.setting-grid input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  font-size: 14px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.switch-row:last-child { border-bottom: 0; }
.switch-row input[type="checkbox"] {
  appearance: none;
  width: 38px;
  height: 22px;
  background: var(--border-strong);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s ease;
}
.switch-row input[type="checkbox"]::after {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  top: 3px; left: 3px;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.switch-row input[type="checkbox"]:checked { background: var(--accent); }
.switch-row input[type="checkbox"]:checked::after { left: 19px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg-elev);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 100;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Accessibility ===== */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}
input:focus-visible { outline: none; }

/* hide number input arrows */
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
  -webkit-appearance: none; margin: 0;
}
input[type=number] { -moz-appearance: textfield; }
