:root {
  --bg: #F7F7FB;
  --surface: #FFFFFF;
  --ink: #1B1A2E;
  --muted: #55536B;
  --faint: #6B6982;
  --line: #ECEBF3;
  --line-2: #E2E0EE;
  --accent: #4B3FD6;
  --accent-ink: #2E2499;
  --accent-soft: #EEEBFF;
  --accent-tint: #F3F1FF;
  --accent-border: #C9C2FF;
  --track: #E9E7F4;
  --ok: #1E6B4A;
  --ok-soft: #E6F5EE;
  --danger: #B42318;
  --danger-soft: #FDECEA;
  --radius: 16px;
  --ease: cubic-bezier(.22, .61, .36, 1);
  --font: "Poppins", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
a:hover { color: var(--accent-ink); }
svg { flex: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid transparent; font-weight: 600; font-size: 14px; cursor: pointer; transition: transform 140ms var(--ease), box-shadow 160ms var(--ease), background 160ms var(--ease); }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .6; cursor: default; transform: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { box-shadow: 0 10px 22px -10px rgba(75, 63, 214, .6); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-dark:hover { box-shadow: 0 10px 22px -10px rgba(27, 26, 46, .55); }
.btn-ghost { background: var(--surface); border-color: var(--line-2); color: var(--ink); }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-block { width: 100%; }
.btn svg, .icon-btn svg, .nav-link svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn { width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; border: 0; background: transparent; color: var(--muted); cursor: pointer; transition: background 160ms var(--ease), color 160ms var(--ease); }
.icon-btn:hover { background: var(--accent-soft); color: var(--accent-ink); }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-weight: 500; }
.link-btn:hover { color: var(--accent-ink); text-decoration: underline; }

/* ---------- brand ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-size: 22px; font-weight: 600; letter-spacing: -.3px; }
.brand:hover { color: var(--ink); }

/* ---------- auth ---------- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: radial-gradient(1200px 600px at 80% -10%, #EEEBFF 0%, transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 36px 32px; box-shadow: 0 24px 60px -36px rgba(46, 36, 153, .35); }
.auth-card h1 { font-size: 26px; line-height: 1.25; letter-spacing: -.4px; margin: 28px 0 8px; }
.auth-card p { margin: 0 0 20px; }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
label { font-size: 13px; font-weight: 500; color: var(--muted); }
input, select { width: 100%; min-height: 46px; padding: 10px 14px; border: 1px solid var(--line-2); border-radius: 12px; background: var(--surface); transition: border-color 160ms, box-shadow 160ms; }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.auth-form .btn { margin-top: 8px; min-height: 50px; font-size: 15px; }
.otp-input { font-size: 28px; letter-spacing: 10px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.auth-alt { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; margin-top: 20px; font-size: 14px; color: var(--muted); }
.flash { padding: 10px 14px; border-radius: 12px; font-size: 14px; margin: 0 0 14px !important; }
.flash-error { background: var(--danger-soft); color: var(--danger); }
.flash-info { background: var(--accent-soft); color: var(--accent-ink); }

/* ---------- shell ---------- */
.shell { min-height: 100vh; display: flex; }
.sidebar { width: 260px; flex: none; position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--surface); border-right: 1px solid var(--line); padding: 28px 18px 18px; display: flex; flex-direction: column; gap: 28px; }
.sidebar .brand { padding: 0 8px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 14px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); font-weight: 500; font-size: 15px; cursor: pointer; text-align: left; transition: background 160ms var(--ease), color 160ms var(--ease), transform 160ms var(--ease); }
.nav-link:hover { background: var(--accent-soft); color: var(--accent-ink); transform: translateX(3px); }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.nav-count { margin-left: auto; font-size: 12px; font-weight: 600; background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 9px; }
.nav-count:empty { display: none; }

.cat-panel { display: flex; flex-direction: column; gap: 6px; }
.cat-head { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 0 14px; }
.cat-head h2 { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); }
.cat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.cat-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 14px; border: 0; border-radius: 10px; background: transparent; cursor: pointer; font-size: 14px; color: var(--ink); text-align: left; transition: background 160ms var(--ease); }
.cat-item:hover { background: var(--bg); }
.cat-item[aria-pressed="true"] { background: var(--accent-soft); font-weight: 600; }
.cat-item .meta { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }

.me { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 14px; background: var(--bg); }
.avatar { width: 38px; height: 38px; border-radius: 999px; background: var(--ink); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px; flex: none; text-transform: uppercase; }
.me-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.me-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-email { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; min-width: 0; padding: 32px 40px 56px; display: flex; flex-direction: column; gap: 26px; outline: none; }

/* ---------- header ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.page-head .eyebrow { font-size: 14px; font-weight: 500; color: var(--muted); }
.page-head h1 { margin: 0; font-size: 34px; font-weight: 700; letter-spacing: -.6px; line-height: 1.15; }
.head-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.pill { font-size: 13px; font-weight: 500; color: var(--muted); background: var(--surface); border: 1px solid var(--line); padding: 8px 14px; border-radius: 999px; white-space: nowrap; }
.export { position: relative; }
.export-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 190px; padding: 6px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 14px; box-shadow: 0 18px 40px -18px rgba(27, 26, 46, .35); display: flex; flex-direction: column; }
.export-menu[hidden] { display: none; }
.export-menu button { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 44px; padding: 0 12px; border: 0; border-radius: 10px; background: transparent; color: var(--ink); font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; text-align: left; }
.export-menu button:hover, .export-menu button:focus-visible { background: var(--accent-soft); outline: none; }
.export-menu .muted { font-size: 12px; font-weight: 600; }
.pill-ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.filter-pill { display: inline-flex; align-items: center; gap: 8px; background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; font-weight: 600; cursor: pointer; }
.filter-pill:hover { background: #E2DDFF; }

.banner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-radius: var(--radius); background: var(--accent-tint); border: 1px solid var(--accent-border); font-size: 14px; }

/* ---------- layout ---------- */
.grid { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 24px; }

/* ---------- timer ---------- */
.timer-card { flex: 1 1 420px; min-width: 0; padding: 30px 28px; display: flex; flex-direction: column; align-items: center; gap: 22px; position: sticky; top: 24px; }
.ring-wrap { position: relative; width: 100%; max-width: 380px; aspect-ratio: 1 / 1; }
.ring-wrap svg { width: 100%; height: 100%; display: block; }
.ring-seg { transition: stroke-dasharray 400ms var(--ease), opacity 200ms; cursor: pointer; }
.ring-seg:hover { opacity: .75; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center; padding: 0 18%; pointer-events: none; }
.ring-label { font-size: 12px; font-weight: 600; letter-spacing: 1.4px; text-transform: uppercase; color: var(--accent); }
.ring-label.over { color: #C2410C; }
.ring-title { font-size: 16px; font-weight: 600; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ring-cat { font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.ring-time { font-size: clamp(44px, 8vw, 64px); font-weight: 600; letter-spacing: -2px; line-height: 1.05; font-variant-numeric: tabular-nums; }
.ring-sub { font-size: 13px; font-weight: 500; color: var(--muted); }
.controls { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 12px; }
.round { width: 52px; height: 52px; border-radius: 999px; padding: 0; }
.play { min-height: 60px; padding: 0 34px; border-radius: 999px; font-size: 16px; }
svg.fill, .btn svg.fill, .icon-btn svg.fill { fill: currentColor; stroke: none; }
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 16px; font-size: 12px; font-weight: 500; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.timer-empty { text-align: center; color: var(--muted); max-width: 300px; }

/* breakdown */
.breakdown { width: 100%; display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--line); padding-top: 18px; }
.breakdown h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.stack-bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--track); gap: 2px; }
.stack-bar span { display: block; height: 100%; }
.break-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 16px; font-size: 13px; }
.break-list li { display: flex; align-items: center; gap: 8px; min-width: 0; }
.break-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.break-list .val { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- tasks ---------- */
.tasks { flex: 1 1 380px; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.tasks-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 2px; }
.tasks-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.task { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); transition: transform 180ms var(--ease), box-shadow 180ms var(--ease), border-color 180ms var(--ease); }
.task:hover { transform: translateY(-2px); box-shadow: 0 10px 24px -14px rgba(46, 36, 153, .35); border-color: #D9D4FF; }
.task.is-now { flex-wrap: wrap; background: var(--accent-tint); border: 1.5px solid var(--accent-border); }
.task-time { width: 46px; flex: none; font-size: 13px; font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }
.check { width: 28px; height: 28px; flex: none; border-radius: 999px; border: 2px solid #CFCCE0; background: var(--surface); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; color: #fff; transition: transform 160ms var(--ease), background 160ms, border-color 160ms; }
.check:hover { transform: scale(1.1); border-color: var(--accent); }
.check svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.check.done { background: var(--c, var(--accent)); border-color: var(--c, var(--accent)); }
.check.done svg { opacity: 1; }
.check.doing { border-color: var(--accent); }
.check.doing::after { content: ""; width: 10px; height: 10px; border-radius: 999px; background: var(--accent); }
.task-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; background: none; border: 0; padding: 4px 0; text-align: left; cursor: pointer; }
.task-title { font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task.is-done .task-title { color: var(--faint); text-decoration: line-through; }
.task-cat { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.task-cat .dot { width: 8px; height: 8px; border-radius: 2px; }
.dur { font-size: 12px; font-weight: 600; color: var(--muted); background: #F3F2F8; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.now-badge { font-size: 12px; font-weight: 600; color: #fff; background: var(--accent); padding: 4px 10px; border-radius: 999px; }
.task-play { width: 36px; height: 36px; }
.task-progress { flex-basis: 100%; display: flex; align-items: center; gap: 12px; padding-left: 98px; }
.bar { flex: 1; height: 6px; border-radius: 999px; background: #DDD8FF; overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 999px; background: var(--accent); transition: width 600ms linear; }
.task-progress .val { font-size: 12px; font-weight: 600; color: var(--accent-ink); font-variant-numeric: tabular-nums; }
.add-row { margin-top: 4px; min-height: 52px; border-radius: var(--radius); border: 1.5px dashed #CFCCE0; background: transparent; color: var(--accent); }
.add-row:hover { background: var(--accent-soft); border-color: var(--accent-border); }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); border: 1.5px dashed var(--line-2); border-radius: var(--radius); }

/* ---------- past ---------- */
.day-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.day-card { display: flex; flex-direction: column; gap: 12px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; cursor: pointer; text-align: left; transition: transform 180ms var(--ease), box-shadow 180ms var(--ease); }
.day-card:hover { transform: translateY(-3px); box-shadow: 0 14px 30px -16px rgba(46, 36, 153, .35); }
.day-card .d { font-size: 16px; font-weight: 600; }
.day-card .s { font-size: 13px; color: var(--muted); }
.day-card .prog { font-size: 13px; font-weight: 600; color: var(--ok); }

/* ---------- modals ---------- */
.modal { border: 0; padding: 0; border-radius: 22px; width: min(520px, calc(100vw - 32px)); box-shadow: 0 30px 80px -30px rgba(27, 26, 46, .45); color: var(--ink); }
.modal::backdrop { background: rgba(27, 26, 46, .35); backdrop-filter: blur(2px); }
.modal[open] { animation: pop 200ms var(--ease); }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
.modal-body { display: flex; flex-direction: column; gap: 8px; padding: 26px; }
.modal-body h2 { margin: 0 0 8px; font-size: 20px; }
.modal-body label { margin-top: 6px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-2 > div { display: flex; flex-direction: column; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.chip { min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; font-size: 13px; font-weight: 500; transition: background 140ms, border-color 140ms; }
.chip:hover { background: var(--accent-soft); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.modal-actions { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.spacer { flex: 1; }
.form-error { margin: 4px 0 0; min-height: 1em; font-size: 13px; color: var(--danger); }
.form-error:empty { display: none; }

.cat-edit-list { list-style: none; margin: 8px 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.cat-edit { display: flex; align-items: center; gap: 8px; }
.cat-edit input[type="text"] { flex: 1; min-height: 42px; }
.swatch-btn { width: 42px; height: 42px; flex: none; border-radius: 12px; border: 1px solid var(--line-2); padding: 0; cursor: pointer; position: relative; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 0 4px 50px; }
.swatch { width: 28px; height: 28px; border-radius: 8px; border: 2px solid transparent; cursor: pointer; padding: 0; transition: transform 120ms; }
.swatch:hover { transform: scale(1.12); }
.swatch[aria-pressed="true"] { border-color: var(--ink); }
.cat-add { display: flex; gap: 8px; margin-top: 6px; }
.cat-add input { flex: 1; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity 200ms, transform 200ms var(--ease); z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { position: static; width: 100%; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 12px; padding: 14px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar .brand { font-size: 19px; }
  .nav { flex-direction: row; order: 3; width: 100%; overflow-x: auto; }
  .nav-link { width: auto; padding: 9px 14px; white-space: nowrap; }
  .nav-link:hover { transform: none; }
  .cat-panel { order: 4; width: 100%; }
  .cat-head { padding: 0 4px; }
  .cat-list { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .cat-item { width: auto; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; }
  .cat-item .meta { display: none; }
  .me { margin: 0 0 0 auto; order: 2; background: transparent; padding: 0; }
  .me-text { display: none; }
  .main { padding: 22px 16px 48px; }
  .page-head h1 { font-size: 28px; }
  .timer-card { position: static; padding: 22px 16px; }
  .task-progress { padding-left: 0; }
  .controls { gap: 8px; }
  .play { padding: 0 22px; }
  .round { width: 46px; height: 46px; }
}
@media (max-width: 480px) {
  .row-2 { grid-template-columns: 1fr; }
  .task-time { width: 40px; font-size: 12px; }
}
@media (hover: none) {
  .task:hover, .day-card:hover, .btn:hover { transform: none; box-shadow: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; }
}
