*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #f4f2fa;
  --card: #ffffff;
  --ink: #2b2540;
  --muted: #9a92b5;
  --muted-2: #7a719b;
  --chip-bg: #f4f2fa;
  --accent: #7a4fd0;
  --accent-bg: #ece4fb;
  --danger: #d0554f;
  --shadow: 0 2px 6px rgba(64, 49, 110, .07);
}

html, body { height: 100%; }

body {
  margin: 0 auto;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI Variable", "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 14px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- шапка ---------- */
.top { padding: calc(14px + env(safe-area-inset-top)) 16px 6px; }

.title-row { display: flex; align-items: center; gap: 10px; }

.title-row h1 { margin: 0; font-size: 17px; font-weight: 700; }

.score {
  margin-left: auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-bg);
  border-radius: 99px;
  padding: 5px 12px;
  white-space: nowrap;
}

/* ---------- аккордеон недели ---------- */
.acc {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.arow {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border-radius: 11px;
  padding: 12px 13px;
  box-shadow: 0 1px 3px rgba(64, 49, 110, .08);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted-2);
  cursor: pointer;
}
.arow small { font-weight: 400; font-size: 10.5px; color: #b6afce; }
.arow.today { color: var(--accent); }
.arow.today small { color: #a58ad8; }

.dots { display: flex; gap: 4px; margin-left: auto; align-items: center; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dc, #ccc); flex: none; }
.dot.open { background: transparent; border: 1.5px solid var(--dc, #ccc); }
.dots .more { font-size: 10px; color: #b6afce; font-weight: 400; }
.chev { color: #c4bdd8; font-size: 10px; margin-left: 2px; }

.aopen { background: var(--accent-bg); border-radius: 14px; padding: 8px; }
.ahead {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 2px 5px 8px;
  font-size: 12.5px;
  font-weight: 700;
  color: #5b34ad;
}
.ahead small { color: #a58ad8; font-weight: 400; font-size: 11px; }
.ahead .dcount { margin-left: auto; font-size: 11px; font-weight: 600; color: #7a4fd0; }
.cards-in { display: flex; flex-direction: column; gap: 7px; }
.day-hint {
  text-align: center;
  color: #a58ad8;
  font-size: 12px;
  padding: 10px 6px 12px;
  line-height: 1.5;
}

.dropping { outline: 2px dashed #f2a25c !important; outline-offset: -1px; }

/* ---------- карточка ---------- */
.card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px;
  border-radius: 13px;
  background: var(--card);
  box-shadow: var(--shadow);
  border-left: 5px solid var(--stripe, #ccc);
  cursor: pointer;
  position: relative;
}
.card.run { outline: 2px solid var(--stripe); outline-offset: -1px; }
.card.done { opacity: .55; cursor: default; }
.card.done .name { text-decoration: line-through; }

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

.name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rep-ico {
  font-size: 12px;
  font-weight: 700;
  color: var(--stripe);
  margin-right: 5px;
}

.sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

.bar {
  height: 6px;
  border-radius: 3px;
  background: var(--chip-bg);
  overflow: hidden;
  margin-top: 7px;
}
.bar b {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--stripe);
  transition: width .4s linear;
}

.time {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  color: var(--muted-2);
  background: var(--chip-bg);
  border-radius: 8px;
  padding: 5px 8px;
  flex: none;
}
.card.run .time { background: #fdeedd; color: #2b2540; font-weight: 600; }

.time.editable { cursor: pointer; }
.time.editing { outline: 1.5px solid var(--accent); }
.time input {
  width: 44px;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  text-align: right;
  color: inherit;
}
.time input::-webkit-outer-spin-button,
.time input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ---------- контекстное меню (долгое нажатие) ---------- */
.menu {
  position: fixed;
  z-index: 50;
  min-width: 220px;
  background: var(--card);
  border: 1px solid #e2ddf0;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(43, 37, 64, .22);
  padding: 5px;
  font-size: 13.5px;
}
.menu .mi { padding: 11px 12px; border-radius: 8px; cursor: pointer; }
.menu .mi:active { background: var(--chip-bg); }
.menu .mi.danger { color: var(--danger); }
.menu .msep { height: 1px; background: #eeeaf6; margin: 4px 6px; }

/* ---------- панель запущенной задачи ---------- */
.runbar[hidden] { display: none; }
.runbar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 16px;
  background: var(--card);
  border-radius: 14px;
  border-left: 5px solid var(--stripe, #8f7ee0);
  box-shadow: 0 6px 22px rgba(43, 37, 64, .25);
  padding: 10px 14px;
  cursor: pointer;
}
.rb-body { flex: 1; min-width: 0; }
.rb-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rb-state { font-size: 10.5px; color: var(--muted); margin-top: 1px; }
.rb-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--chip-bg);
  overflow: hidden;
  margin-top: 6px;
}
.rb-bar b {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--stripe, #8f7ee0);
  transition: width .4s linear;
}
.rb-time {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 17px;
  font-weight: 600;
  flex: none;
}
.runbar.paused .rb-bar b { background: #cfc9de; }
.runbar.paused .rb-time { color: var(--muted); }

/* ---------- форма добавления ---------- */
.add {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 16px calc(12px + env(safe-area-inset-bottom));
  border: 2px dashed #d5cdea;
  border-radius: 14px;
  padding: 8px 10px;
}
.add input[type="text"] {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  color: var(--ink);
}
.add input::placeholder { color: var(--muted); font-weight: 600; }
.add input[type="number"] {
  width: 56px;
  border: none;
  outline: none;
  background: var(--card);
  border-radius: 8px;
  padding: 7px 6px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
  text-align: center;
  color: var(--ink);
}
.add .unit { font-size: 12px; color: var(--muted); }
.add button {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 20px;
  font-weight: 300;
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
