/* styles.css — colors, sizes and layout. */

:root {
  --bg: #16181d;
  --surface: #1e2128;
  --row: #252830;
  --row-hover: #2c3039;
  --border: #323641;
  --text: #e8eaed;
  --muted: #959ba6;
  --accent: #6b9bff;
  --accent-text: #0e1420;
  --danger: #ff6b6b;
  --flag: #ff4d4f;
  --yellow: #b39a4c;
  --orange: #b9784a;
  --red: #b35a5e;
  --shadow: 0 10px 40px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f2f3f6;
  --surface: #ffffff;
  --row: #ffffff;
  --row-hover: #f5f6f9;
  --border: #dcdfe5;
  --text: #1c1e22;
  --muted: #6a707b;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --danger: #d6363b;
  --flag: #e5252a;
  --yellow: #c4a443;
  --orange: #c98250;
  --red: #c2585d;
  --shadow: 0 10px 40px rgba(0, 0, 0, .18);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="system"] {
    --bg: #f2f3f6;
    --surface: #ffffff;
    --row: #ffffff;
    --row-hover: #f5f6f9;
    --border: #dcdfe5;
    --text: #1c1e22;
    --muted: #6a707b;
    --accent: #2f6fed;
    --accent-text: #ffffff;
    --danger: #d6363b;
    --flag: #e5252a;
    --yellow: #c4a443;
    --orange: #c98250;
    --red: #c2585d;
    --shadow: 0 10px 40px rgba(0, 0, 0, .18);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { height: 100dvh; }
html { -webkit-text-size-adjust: 100%; }
button, .row { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
  user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; color: inherit; user-select: text; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 10px 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: .2px; }
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 8px;
  background: transparent; border: 0; color: var(--muted);
}
.icon-btn:hover:not(:disabled) { background: var(--row-hover); color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; }

/* ---------- Task list (scrolls, scroll bar hidden) ---------- */
.list {
  position: relative;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 8px 0 16px;
  scrollbar-width: none;
}
.list::-webkit-scrollbar { display: none; }

.row {
  display: grid;
  grid-template-columns: 70px 1fr 30px;
  align-items: center; gap: 10px;
  margin: 6px 10px; padding: 10px 8px 10px 12px;
  background: var(--row);
  border: 1px solid var(--border);
  border-radius: 9px;
  transition: background-color .4s, color .4s, border-color .4s;
  cursor: default;
  position: relative; z-index: 1;
}
@media (hover: hover) { .row:hover { background: var(--row-hover); } }
.countdown {
  font-variant-numeric: tabular-nums;
  font-weight: 650; font-size: 15px;
  color: var(--muted);
}
.row.timed .countdown { color: var(--text); }
.due { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; margin-top: 1px; }
.name { overflow-wrap: anywhere; }
.flag {
  width: 28px; height: 28px; border-radius: 50%;
  border: 0; background: transparent;
  font-weight: 900; font-size: 17px; line-height: 1;
  color: var(--muted); opacity: .35;
}
.flag:hover { opacity: .8; background: rgba(127, 127, 127, .15); }
.flag.on { color: var(--flag); opacity: 1; }

/* Deadline colors: shown as a border only. */
.row.st-yellow { --state: var(--yellow); }
.row.st-orange { --state: var(--orange); }
.row.st-red    { --state: var(--red); }
.row.st-yellow, .row.st-orange, .row.st-red {
  border-color: var(--state);
  box-shadow: inset 0 0 0 1px var(--state);
  /* A soft see-through fill in the same color (it doesn't flash). */
  background: color-mix(in srgb, var(--state) 16%, var(--row));
}
@media (hover: hover) {
  .row.st-yellow:hover, .row.st-orange:hover, .row.st-red:hover { background: color-mix(in srgb, var(--state) 24%, var(--row)); }
}
/* Flashes when a task changes color, until you click it once. */
.row.flash { animation: flash-border 1.2s ease-in-out infinite; cursor: pointer; }
@keyframes flash-border {
  0%, 100% { border-color: var(--state); box-shadow: inset 0 0 0 1px var(--state), 0 0 8px var(--state); }
  50%      { border-color: var(--border); box-shadow: inset 0 0 0 1px transparent, 0 0 0 transparent; }
}

.empty { text-align: center; color: var(--muted); margin: 48px 20px; }
.empty[hidden] { display: none; }

/* ---------- Completed section ---------- */
.completed-section { margin-top: 14px; }
.completed-toggle {
  display: flex; align-items: center; gap: 8px;
  width: calc(100% - 20px); margin: 0 10px; padding: 8px 6px;
  background: transparent; border: 0; border-top: 1px solid var(--border);
  color: var(--muted); font-weight: 600; text-align: left;
}
.completed-toggle:hover { color: var(--text); }
.chevron { display: inline-block; transition: transform .25s; }
.completed-toggle[aria-expanded="true"] .chevron { transform: rotate(90deg); }
.completed-body { overflow: hidden; display: none; }
.completed-body.open { display: block; }
.completed-body > .text-btn { margin: 4px 16px 4px; }
.row.done { background: transparent; opacity: .62; }
.row.done .name { text-decoration: line-through; }
.row.done .flag { pointer-events: none; }

.text-btn {
  background: transparent; border: 0; padding: 6px 4px;
  color: var(--accent); font-weight: 600;
}
.text-btn.danger { color: var(--danger); }
.text-btn:disabled { opacity: .4; cursor: default; }
.armed { outline: 2px solid currentColor; outline-offset: 1px; border-radius: 6px; }

/* ---------- Bottom bar (fixed) ---------- */
.bottombar {
  padding: 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
#new-task {
  width: 100%; padding: 11px 13px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 9px;
  outline: none;
}
#new-task:focus { border-color: var(--accent); }

/* Text that flies from the input box into the list */
.ghost {
  position: fixed; z-index: 50; pointer-events: none;
  white-space: nowrap; color: var(--text);
}

/* ---------- Dialogs ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 16px;
  background: rgba(0, 0, 0, .45);
  animation: fade-in .15s ease-out;
}
.dialog {
  width: 100%; max-width: 340px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 18px;
  box-shadow: var(--shadow);
  animation: pop-in .18s cubic-bezier(.2, .8, .2, 1);
}
.dialog h2 { margin: 0 0 4px; font-size: 16px; }
.dialog .sub { margin: 0 0 12px; color: var(--muted); overflow-wrap: anywhere; }
.dialog .field {
  width: 100%; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 9px;
  outline: none; font-size: 18px; font-variant-numeric: tabular-nums; text-align: center;
}
.dialog .field:focus { border-color: var(--accent); }
.dialog .field.bad { border-color: var(--danger); }
.dialog .hint { margin: 8px 0 0; font-size: 12px; color: var(--muted); text-align: center; }
.dialog .preview { margin: 8px 0 0; min-height: 20px; text-align: center; font-weight: 600; }
.dialog .preview.bad { color: var(--danger); }
.steps { display: grid; grid-template-columns: repeat(4, 1fr) 4px repeat(4, 1fr); gap: 4px; margin-top: 14px; }
.step:nth-child(5) { grid-column: 6; }
.step {
  padding: 8px 0; border-radius: 7px; min-width: 0;
  background: var(--row); border: 1px solid var(--border);
  font-variant-numeric: tabular-nums; font-weight: 600; font-size: 12px;
}
.step:hover { background: var(--row-hover); }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.actions.center { justify-content: center; }
.btn {
  padding: 8px 16px; border-radius: 8px;
  background: var(--row); border: 1px solid var(--border); font-weight: 600;
}
.btn:hover { background: var(--row-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.shake { animation: shake .3s; }

/* ---------- Settings panel ---------- */
.settings {
  position: fixed; inset: 0; z-index: 90;
  display: flex; flex-direction: column;
  background: var(--bg);
  animation: slide-up .22s cubic-bezier(.2, .8, .2, 1);
}
.settings header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 10px 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.settings header h2 { margin: 0; font-size: 17px; }
.settings .scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 16px 28px; scrollbar-width: none; }
.settings .scroll::-webkit-scrollbar { display: none; }
.settings h3 {
  margin: 20px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted);
}
.setting {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
  margin-bottom: 6px;
}
.setting label { flex: 1; }
.num {
  width: 64px; padding: 5px 8px; text-align: right;
  background: var(--bg); border: 1px solid var(--border); border-radius: 7px; outline: none;
}
.num:focus { border-color: var(--accent); }
.seg { display: flex; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 10px; border-radius: 6px; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--accent); color: var(--accent-text); }
.toggle { appearance: none; width: 38px; height: 22px; border-radius: 11px; background: var(--border); position: relative; cursor: pointer; flex: none; transition: background .2s; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; }
.toggle:checked { background: var(--accent); }
.toggle:checked::after { transform: translateX(16px); }
.preset { display: flex; align-items: center; gap: 6px; }
.preset .pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preset .pcount { color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); font-size: 12px; }
.button-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

/* Preset editor */
.dialog.wide { max-width: 420px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.pitems { overflow-y: auto; margin: 10px 0; scrollbar-width: none; }
.pitem { display: grid; grid-template-columns: 1fr 70px 30px 26px; gap: 6px; margin-bottom: 6px; align-items: center; }
.pitem input {
  min-width: 0; padding: 6px 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 7px; outline: none;
}
.pitem input:focus { border-color: var(--accent); }
.pitem input.bad { border-color: var(--danger); }
.pitem .x { border: 0; background: transparent; color: var(--muted); font-size: 16px; }
.dialog .text-input {
  width: 100%; padding: 8px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; outline: none;
}
.dialog .text-input:focus { border-color: var(--accent); }
.error { color: var(--danger); font-size: 12px; min-height: 16px; margin: 4px 0 0; }

/* Toast message */
.toast {
  position: fixed; left: 50%; bottom: 74px; z-index: 95;
  transform: translate(-50%, 10px); opacity: 0;
  padding: 7px 14px; border-radius: 18px;
  background: var(--text); color: var(--bg); font-weight: 600; font-size: 13px;
  pointer-events: none; transition: opacity .2s, transform .2s; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: scale(.95); } }
@keyframes slide-up { from { opacity: 0; transform: translateY(16px); } }
@keyframes shake { 25% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 75% { transform: translateX(-3px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
  .row.flash { animation: none; outline: 2px dashed var(--state); outline-offset: 2px; }
}

.text-field {
  flex: 1; min-width: 0; padding: 6px 9px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 7px; outline: none;
}
.text-field:focus { border-color: var(--accent); }

/* ---------- Swipe labels (touch screens) ---------- */
.swipe-hint {
  position: absolute; left: 10px; right: 10px; z-index: 0;
  display: flex; align-items: center; padding: 0 18px;
  border-radius: 9px; font-weight: 700; font-size: 14px;
  color: var(--muted); background: var(--surface); border: 1px dashed var(--border);
  transition: background-color .15s, color .15s, opacity .2s;
}
.swipe-hint.to-right { justify-content: flex-start; }
.swipe-hint.to-left { justify-content: flex-end; }
.swipe-hint.to-right.ready { background: #3f7a52; color: #fff; border-color: transparent; }
.swipe-hint.to-left.ready { background: var(--accent); color: var(--accent-text); border-color: transparent; }

/* ---------- Phone tweaks ---------- */
.touch #new-task, .touch .dialog .text-input, .touch .pitem input, .touch .num, .touch .text-field { font-size: 16px; } /* stops iPhone zooming in */
.touch .row { padding-top: 12px; padding-bottom: 12px; }
.touch .step { padding: 11px 0; }
.touch .flag { width: 36px; height: 36px; }
.touch .row { grid-template-columns: 70px 1fr 36px; }
.touch .settings header { padding-top: max(10px, env(safe-area-inset-top)); }
.touch .settings .scroll { padding-bottom: max(28px, env(safe-area-inset-bottom)); }
.empty .muted { display: inline-block; margin-top: 10px; }
.touch .overlay { place-items: start center; padding-top: calc(env(safe-area-inset-top) + 48px); } /* keep dialogs above the keyboard */

/* ---------- Drag to reorder ---------- */
.row { -webkit-touch-callout: none; }
.row.dragging {
  z-index: 5; cursor: grabbing;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .35);
  transition: box-shadow .15s;
}
.row.dragging.st-yellow, .row.dragging.st-orange, .row.dragging.st-red {
  box-shadow: inset 0 0 0 1px var(--state), 0 10px 28px rgba(0, 0, 0, .35);
}

/* ---------- Edit Task window ---------- */
.field-label { display: block; margin: 10px 0 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.dialog h2 + .field-label { margin-top: 8px; }
.delete-row { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); text-align: center; }
.delete-btn { width: 100%; }

/* ---------- Settings: updates + version number ---------- */
.update-status { flex: 1; color: var(--muted); }
.settings .version {
  padding: 8px 16px; padding-bottom: max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: var(--surface);
  color: var(--muted); font-size: 12px; text-align: left;
}
#settings-btn { position: relative; }
#settings-btn.has-update::after {
  content: ""; position: absolute; top: 6px; right: 6px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px var(--surface);
}

/* ---------- Tutorial ---------- */
.tutorial .step-count { margin: 0 0 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.tutorial h2 { font-size: 18px; margin-bottom: 8px; }
.tutorial-body { margin: 0; min-height: 84px; line-height: 1.5; }
.dots { display: flex; justify-content: center; gap: 6px; margin-top: 16px; }
.dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--border); transition: background .2s, transform .2s; }
.dots span.on { background: var(--accent); transform: scale(1.25); }
.tutorial .actions { align-items: center; }
