:root {
  --bg-card: rgba(255, 255, 255, 0.93);
  --text: #1e293b;
  --muted: #64748b;
  --soft: #6b7280;
  --border: rgba(0, 0, 0, 0.08);
  --input: rgba(255, 255, 255, 0.8);
  --accent: #2563eb;
  --green: #16a34a;
  --yellow: #d97706;
  --red: #dc2626;
  --fbtn: rgba(0, 0, 0, 0.06);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 24px 64px rgba(0, 0, 0, 0.18);
}

[data-theme="dark"] {
  --bg-card: rgba(15, 23, 42, 0.93);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --soft: #8895a8;
  --border: rgba(255, 255, 255, 0.08);
  --input: rgba(255, 255, 255, 0.05);
  --fbtn: rgba(255, 255, 255, 0.06);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', sans-serif;
  min-height: 100vh;
  color: var(--text);
  line-height: 1.6;
}

a {
  text-decoration: none;
  color: inherit;
}

button {
  cursor: pointer;
  font-family: inherit;
  border: none;
  background: none;
}

/* Visible keyboard focus ring — buttons above strip the browser default,
   so every interactive element needs an explicit :focus-visible style. */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* BACKGROUND — changes by time of day */
.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  transition: background 3s ease;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #312e81 100%);
}

.bg.morning {
  background: linear-gradient(135deg, #f97316 0%, #fb923c 40%, #fde68a 100%);
}

.bg.afternoon {
  background: linear-gradient(135deg, #1d4ed8 0%, #3b82f6 50%, #93c5fd 100%);
}

.bg.evening {
  background: linear-gradient(135deg, #7c3aed 0%, #be185d 50%, #f97316 100%);
}

.bg.night {
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #312e81 100%);
}

/* APP */
.app {
  position: relative;
  z-index: 1;
  max-width: 820px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* HEADER */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  color: white;
}

/* Window Controls Overlay (desktop installed PWAs) — when the OS draws its
   window controls over the top of the page, this pulls the header up into
   that reserved titlebar strip and lets the OS drag region live there too. */
body.wco-active {
  padding-top: 0;
}
body.wco-active .header {
  position: fixed;
  top: env(titlebar-area-y, 0);
  left: env(titlebar-area-x, 0);
  width: env(titlebar-area-width, 100%);
  height: env(titlebar-area-height, 40px);
  border-radius: 0;
  -webkit-app-region: drag;
  app-region: drag;
  z-index: 100;
}
body.wco-active .header button,
body.wco-active .header .name-input {
  -webkit-app-region: no-drag;
  app-region: no-drag;
}
body.wco-active .app {
  padding-top: calc(env(titlebar-area-height, 40px) + 16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 800;
}

.header-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.clock {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.greeting {
  font-size: 11px;
  opacity: 0.75;
  font-weight: 500;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.streak-badge {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 700;
  color: white;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 5px 10px;
  white-space: nowrap;
}

.hbtn.active {
  background: rgba(99, 102, 241, 0.5);
  border-color: rgba(99, 102, 241, 0.7);
}

.hbtn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.2s;
}

.hbtn:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* CARD */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* STATS */
.stats {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px;
}

.stat:first-child {
  padding-left: 0;
}

.snum {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
}

.snum.green {
  color: var(--green);
}

.snum.yellow {
  color: var(--yellow);
}

.slbl {
  font-size: 10px;
  color: var(--soft);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
}

.sdiv {
  width: 1px;
  height: 28px;
  background: var(--border);
}

.progress-stat {
  flex: 1;
  align-items: flex-start;
  padding-left: 20px;
  gap: 5px;
}

.pbar-wrap {
  width: 100%;
  height: 5px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.pbar {
  height: 100%;
  background: linear-gradient(90deg, #2563eb, #7c3aed);
  border-radius: 999px;
  width: 0%;
  transition: width 0.5s ease;
}

/* INPUT */
.input-area {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.tinput {
  flex: 1;
  min-width: 180px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: 0.2s;
}

.tinput::placeholder {
  color: var(--soft);
}

.tinput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.tsel {
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  cursor: pointer;
}

.tsel.small {
  padding: 7px 8px;
  font-size: 11px;
}

.addbtn {
  padding: 9px 18px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}

.addbtn:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
}

/* TOOLBAR */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.searchbox {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  flex: 1;
  min-width: 130px;
  transition: 0.2s;
}

.searchbox:focus-within {
  border-color: var(--accent);
}

.searchbox input {
  background: none;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  width: 100%;
}

.searchbox input::placeholder {
  color: var(--soft);
}

.chips {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.chip {
  padding: 5px 12px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  transition: 0.2s;
  cursor: pointer;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* TASK LIST */
.task-list {
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 60px;
}

.task-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 11px 12px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: 0.2s;
  animation: fadein 0.18s ease;
}

@keyframes fadein {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.task-item:hover {
  border-color: rgba(37, 99, 235, 0.25);
}

.task-item.done {
  opacity: 0.45;
}

.task-item.done .ttext {
  text-decoration: line-through;
  color: var(--muted);
}

.cbox {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  border: 2px solid var(--border);
  background: transparent;
  flex-shrink: 0;
  margin-top: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: transparent;
  transition: 0.2s;
  cursor: pointer;
}

.cbox:hover {
  border-color: var(--accent);
}

.cbox.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tbody {
  flex: 1;
  min-width: 0;
}

.ttext {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  word-break: break-word;
  display: block;
  margin-bottom: 4px;
}

.tmeta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.ttag {
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tag-work {
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
}

.tag-study {
  background: rgba(22, 163, 74, 0.1);
  color: #16a34a;
}

.tag-personal {
  background: rgba(124, 58, 237, 0.1);
  color: #7c3aed;
}

.tag-other {
  background: rgba(100, 116, 139, 0.1);
  color: #64748b;
}

.pdot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.p-high {
  background: var(--red);
}

.p-medium {
  background: var(--yellow);
}

.p-low {
  background: var(--green);
}

.tdue {
  font-size: 11px;
  color: var(--soft);
}

.tdue.late {
  color: var(--red);
  font-weight: 600;
}

.dragHandle {
  flex-shrink: 0;
  width: 16px;
  height: 20px;
  margin-top: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  color: var(--soft);
  cursor: grab;
  touch-action: none;
  /* prevents the page from scrolling while a finger drags this handle */
  user-select: none;
}

.dragHandle:active {
  cursor: grabbing;
  color: var(--accent);
}

.tactions {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
  opacity: 0;
  transition: 0.2s;
}

.task-item:hover .tactions,
.task-item:focus-within .tactions {
  opacity: 1;
}

.tabtn {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--fbtn);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.2s;
  cursor: pointer;
}

.tabtn:hover {
  background: rgba(37, 99, 235, 0.1);
  color: var(--accent);
  border-color: var(--accent);
}

.tabtn.del:hover {
  background: rgba(220, 38, 38, 0.1);
  color: var(--red);
  border-color: rgba(220, 38, 38, 0.3);
}

/* EMPTY */
.empty {
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.empty span {
  font-size: 28px;
  color: var(--accent);
}

.empty p {
  font-size: 13px;
}

/* FOOTER ACTIONS */
.footer-actions {
  display: flex;
  gap: 6px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.fbtn {
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  background: var(--fbtn);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  transition: 0.2s;
  cursor: pointer;
}

.fbtn:hover {
  background: rgba(37, 99, 235, 0.08);
  color: var(--accent);
  border-color: var(--accent);
}

.fbtn.red:hover {
  background: rgba(220, 38, 38, 0.08);
  color: var(--red);
  border-color: rgba(220, 38, 38, 0.3);
}

/* POMODORO */
.pom-card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  text-align: center;
}

.pom-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.timer {
  font-size: 52px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -2px;
  font-variant-numeric: tabular-nums;
  margin-bottom: 14px;
}

.pom-btns {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.pom-session-count {
  margin-top: 12px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

/* MODAL */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.open {
  display: flex;
}

.mbox {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  max-width: 400px;
  width: 100%;
  position: relative;
  box-shadow: var(--shadow);
  animation: pop 0.2s ease;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.96);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

.mclose {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--fbtn);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: 0.2s;
}

.mclose:hover {
  color: var(--text);
}

.mavatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 800;
  color: #fff;
  margin: 0 auto 10px;
}

.mbox h2 {
  font-size: 17px;
  font-weight: 800;
  text-align: center;
  color: var(--text);
  margin-bottom: 3px;
}

.msub {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  margin-bottom: 12px;
}

.mlinks {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.mlinks a {
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  background: var(--fbtn);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  transition: 0.2s;
}

.mlinks a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.mbox hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

.mdesc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.7;
  margin-bottom: 12px;
}

.mtags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 14px;
}

.mtags span {
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.1);
  border: 1px solid rgba(37, 99, 235, 0.2);
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
}

.mlive {
  display: block;
  text-align: center;
  padding: 9px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  transition: 0.2s;
}

.mlive:hover {
  background: #1d4ed8;
}

.mlive.danger {
  background: transparent;
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.mlive.danger:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #dc2626;
}

.shortcuts-box h2 {
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 14px;
}

.shortcuts-list {
  list-style: none;
  display: grid;
  gap: 10px;
}

.shortcuts-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  padding: 3px 7px;
  background: var(--fbtn);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

/* TOAST */
.toasts {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 10px 9px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  box-shadow: var(--shadow);
  animation: fadein 0.25s ease;
  max-width: 280px;
}

.toast-action {
  flex-shrink: 0;
  background: rgba(37, 99, 235, 0.1);
  color: var(--accent);
  border: 1px solid rgba(37, 99, 235, 0.3);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: 0.2s;
}

.toast-action:hover {
  background: rgba(37, 99, 235, 0.18);
}

/* INLINE EDIT (text + category + priority + due date) */
.tedit-wrap {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tedit {
  flex: 1 1 160px;
  min-width: 120px;
  background: var(--input);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  outline: none;
}

.tedit-sel {
  flex: 0 1 auto;
  font-size: 11px;
  padding: 6px 8px;
}

/* DRAG & DROP REORDERING */
.task-item.dragging {
  opacity: 0.4;
}

.task-item.drag-over {
  border-top: 2px solid var(--accent);
}

/* RESPONSIVE */
@media(max-width:600px) {
  .input-row {
    flex-direction: column;
  }

  .tinput,
  .addbtn {
    width: 100%;
  }

  .addbtn {
    justify-content: center;
  }

  .stats {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px;
  }

  .sdiv {
    display: none;
  }

  .progress-stat {
    width: 100%;
    padding-left: 0;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .header {
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }

  .header-right {
    flex-wrap: wrap;
    justify-content: center;
  }

  .tactions {
    opacity: 1;
  }

  .timer {
    font-size: 40px;
  }
}

/* NAME SCREEN */
.name-screen {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.15);
}

.name-box {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 20px;
  padding: 40px 36px;
  text-align: center;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.25);
  animation: pop 0.3s ease;
}

.name-logo {
  margin-bottom: 16px;
  display: flex;
  justify-content: center;
}

.name-box h1 {
  font-size: 26px;
  font-weight: 800;
  color: #1e293b;
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.name-box p {
  font-size: 15px;
  color: #64748b;
  margin-bottom: 24px;
}

.name-input {
  width: 100%;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 16px;
  font-family: inherit;
  color: #1e293b;
  outline: none;
  text-align: center;
  margin-bottom: 14px;
  transition: 0.2s;
}

.name-input::placeholder {
  color: #94a3b8;
}

.name-input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.name-btn {
  width: 100%;
  padding: 12px;
  background: #2563eb;
  color: white;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  transition: 0.2s;
  cursor: pointer;
}

.name-btn:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
}

.name-screen.hidden {
  display: none;
}

/* Respect the user's OS-level reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}