:root {
  --sans: "Golos Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  --serif: "Literata", "PT Serif", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --paper: #f8f7f3;
  --ink: #16181b;
  --muted: #6f7378;
  --rule: #e2e0d9;
  --rule-strong: #c5c3ba;
  --hover: #efede6;
  --accent: #2b4ed8;
  --math: #2b4ed8;
  --rus: #b23a2e;
  --it: #1c7a57;
  --other: #8a7b68;
}

html[data-theme="dark"] {
  --paper: #0f1113;
  --ink: #ebe8e1;
  --muted: #8b9096;
  --rule: #24282c;
  --rule-strong: #3d434a;
  --hover: #171a1d;
  --accent: #93a8ff;
  --math: #93a8ff;
  --rus: #ef9582;
  --it: #6fd1a8;
  --other: #b3a894;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font-family: inherit; }
button { color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

.page {
  max-width: 1060px;
  margin: 0 auto;
  padding: 0 32px 64px;
}

/* ---------- auth ---------- */

.auth-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.auth-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  width: min(460px, 100%);
  margin: 0 auto;
  padding: 48px 24px 0;
}

.auth-header h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 38px;
  line-height: 1.05;
  letter-spacing: -0.025em;
}

.auth-header p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.auth-panel {
  width: min(460px, 100%);
  margin: 0 auto;
  padding: 28px 24px 64px;
}

.auth-tabs {
  display: flex;
  gap: 22px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--rule);
}

.auth-tab {
  position: relative;
  padding: 10px 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.auth-tab:hover { color: var(--ink); }
.auth-tab.is-active { color: var(--ink); }

.auth-tab.is-active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--ink);
}

.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-form .field { margin: 0; }
.auth-form .field input { font-size: 15px; }
.auth-hint { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.auth-error { min-height: 16px; margin: 0; color: var(--rus); font-size: 12px; }

.auth-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px 16px;
  margin-top: 2px;
}

.auth-links button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
  text-decoration: underline;
  text-decoration-color: var(--rule-strong);
  text-underline-offset: 2px;
  cursor: pointer;
}

.auth-links button:hover { color: var(--ink); }

/* ---------- app masthead ---------- */

.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 40px 0 16px;
}

.masthead h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 27px;
  line-height: 1.1;
  letter-spacing: -0.015em;
}

.masthead p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.save-status {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
}

.pill {
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--rule);
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.pill:hover { color: var(--ink); border-color: var(--rule-strong); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-btn:hover { color: var(--ink); border-color: var(--rule-strong); }
html[data-theme="light"] .icon-sun { display: none; }
html[data-theme="dark"] .icon-moon { display: none; }

/* ---------- planner bar ---------- */

.planner-bar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 10px;
}

.planner-title {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: -0.015em;
  cursor: pointer;
  text-align: left;
}

.planner-title:hover { color: var(--muted); }
.planner-title svg { flex: 0 0 auto; opacity: 0.55; }

.planner-actions { display: flex; align-items: center; gap: 12px; }

.ghost {
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.ghost:hover { color: var(--ink); }

.menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 30;
  width: min(300px, calc(100vw - 36px));
  padding: 6px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.14);
}

.menu button {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.menu button:hover { background: var(--hover); }
.menu button.is-active { font-weight: 600; }
.menu__sep { height: 1px; margin: 6px 4px; background: var(--rule); }
.menu__danger { color: var(--rus) !important; }
.menu__hint { padding: 8px 10px 4px; color: var(--muted); font-size: 11px; }

/* ---------- weeks ---------- */

.weeks {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  min-width: 0;
  margin-top: 14px;
  border-bottom: 1px solid var(--rule);
}

.weeks__tabs {
  display: flex;
  gap: 2px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.weeks__tabs::-webkit-scrollbar { display: none; }

.tab {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 12px 15px;
  border: 0;
  background: none;
  color: var(--muted);
  font-family: var(--mono);
  cursor: pointer;
  white-space: nowrap;
}

.tab:first-child { padding-left: 0; }
.tab__num { font-size: 12.5px; letter-spacing: 0.01em; }
.tab__count { font-size: 10.5px; opacity: 0.8; font-variant-numeric: tabular-nums; }
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--ink); }

.tab.is-active::after {
  content: "";
  position: absolute;
  left: 15px;
  right: 15px;
  bottom: -1px;
  height: 2px;
  background: var(--ink);
}

.tab:first-child.is-active::after { left: 0; }
.tab:first-child.is-active { padding-right: 16px; }

.meter {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 14px;
  flex: 0 0 auto;
}

.meter__line {
  width: 88px;
  height: 2px;
  background: var(--rule);
  overflow: hidden;
}

.meter__fill {
  display: block;
  height: 100%;
  background: var(--ink);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.35s ease;
}

.meter__text {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.week-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  padding: 32px 0 10px;
}

.week-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(30px, 4vw, 40px);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.week-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ---------- days & tasks ---------- */

.day {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 24px;
  padding: 20px 0;
  border-top: 1px solid var(--rule);
}

.day:last-child { border-bottom: 1px solid var(--rule); }

.day__head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 1px;
}

.day__name {
  font-family: var(--serif);
  font-size: 25px;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.day.is-off .day__name { color: var(--muted); font-style: italic; }

.day__date {
  font-family: var(--mono);
  font-size: 10.5px;
  line-height: 1.4;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.day.is-today .day__date { color: var(--accent); font-weight: 500; }
.day.has-overdue .day__date { color: var(--rus); font-weight: 500; }

.day__stats {
  display: flex;
  flex-direction: column;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  line-height: 1.55;
}

.day__hours { opacity: 0.75; }

.day__tasks {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px 28px;
  align-content: start;
  min-width: 0;
}

.task {
  display: flex;
  gap: 11px;
  min-width: 0;
  padding: 10px 12px;
  margin: 0 -12px;
  border-radius: 8px;
}

.task:hover, .task:focus-within { background: var(--hover); }

.check {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin-top: 2px;
  padding: 0;
  border: 1.5px solid var(--rule-strong);
  border-radius: 5px;
  background: transparent;
  color: var(--paper);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.check:hover { border-color: var(--ink); }
.check svg { opacity: 0; }
.task.is-done .check { background: var(--ink); border-color: var(--ink); }
.task.is-done .check svg { opacity: 1; }
.task.is-overdue .check { border-color: var(--rus); }
.check:disabled { cursor: default; opacity: 0.55; }

.task__body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.task__meta { display: flex; align-items: center; gap: 7px; min-width: 0; }

.subject {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--other);
  flex: 0 0 auto;
}

.task__when {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.task__overdue {
  margin-left: auto;
  font-size: 10.5px;
  color: var(--rus);
  white-space: nowrap;
}

.task__title {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
}

.task__title:hover {
  text-decoration: underline;
  text-decoration-color: var(--rule-strong);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.task.is-done .task__title {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--rule-strong);
}

.task.is-done .subject, .task.is-done .task__when { opacity: 0.6; }
.task__title--static { cursor: default; }
.task__title--static:hover { text-decoration: none; }

.rest {
  grid-column: 1 / -1;
  margin: 10px 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  color: var(--muted);
}

.add {
  grid-column: 1 / -1;
  justify-self: start;
  padding: 9px 0 4px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.add:hover { color: var(--ink); }

.readonly-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
}

.readonly-banner strong { color: var(--ink); font-weight: 500; }

/* ---------- footer ---------- */

.foot {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding-top: 24px;
  color: var(--muted);
  font-size: 12px;
}

.foot p { margin: 0; }
.foot a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }

/* ---------- form controls ---------- */

.field { margin-top: 16px; }

.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11.5px;
}

.field textarea,
.field input,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--rule-strong);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}

.field textarea { min-height: 92px; resize: vertical; line-height: 1.5; }
.field textarea:focus, .field input:focus, .field select:focus { border-color: var(--ink); }
.field-row { display: grid; grid-template-columns: 1fr 140px; gap: 14px; }

.field-check {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.field-check input { width: 16px; height: 16px; accent-color: var(--ink); }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid var(--rule-strong);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
}

.btn:hover { border-color: var(--ink); }
.btn--primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn--primary:hover { opacity: 0.88; }
.btn--danger { padding-left: 0; border-color: transparent; color: var(--rus); }
.btn--danger:hover { text-decoration: underline; }
.btn--wide { width: 100%; }
.spacer { flex: 1; }

/* ---------- dialogs ---------- */

dialog {
  width: min(540px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.18);
}

dialog::backdrop { background: rgba(15, 17, 19, 0.4); }
#shareDialog { width: min(480px, calc(100vw - 32px)); }
#accountDialog { width: min(440px, calc(100vw - 32px)); }
#recoveryDialog { width: min(480px, calc(100vw - 32px)); }

.dialog-form {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 48px);
  padding: 0 24px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex: 0 0 auto;
  padding: 20px 0 4px;
}

.dialog-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 21px;
  letter-spacing: -0.01em;
}

.dialog-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 4px;
}

.dialog-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  margin-top: 0;
  padding: 16px 0 20px;
  border-top: 1px solid var(--rule);
  background: var(--paper);
}

.x {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.x:hover { color: var(--ink); background: var(--hover); }

/* ---------- categories editor ---------- */

.category-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }

.category-row {
  display: grid;
  grid-template-columns: 28px 1fr 28px;
  align-items: center;
  gap: 8px;
}

.category-row input[type="color"] {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--rule-strong);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}

.category-row input[type="text"] {
  padding: 8px 10px;
  border: 1px solid var(--rule-strong);
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

.category-row .x { width: 28px; height: 28px; font-size: 17px; }

/* ---------- share / recovery ---------- */

.share-link {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.share-link input {
  flex: 1;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--rule-strong);
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 11px;
}

.qr-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 18px;
  padding: 12px;
  border: 1px solid var(--rule);
  border-radius: 10px;
}

.qr-box {
  flex: 0 0 auto;
  width: 148px;
  height: 148px;
  display: grid;
  place-items: center;
  background: var(--paper);
}

.qr-box canvas, .qr-box img { max-width: 100%; height: auto; }
.qr-note { color: var(--muted); font-size: 12px; line-height: 1.5; }

.recovery-code {
  margin: 14px 0;
  padding: 14px 12px;
  border: 1px dashed var(--rule-strong);
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: 0.04em;
  text-align: center;
  user-select: all;
}

.recovery-warning {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.55;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
  visibility: hidden;
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0.2s;
}

.toast.is-visible {
  visibility: visible;
  opacity: 1;
  transform: translate(-50%, 0);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  .day__tasks { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .page { padding: 0 18px 48px; }
  .masthead { padding-top: 26px; }
  .masthead h1 { font-size: 23px; }
  .save-status { display: none; }
  .planner-title { font-size: 20px; }
  .planner-bar { gap: 10px; }
  .planner-actions .ghost { font-size: 11px; }
  .weeks { flex-direction: column; align-items: stretch; gap: 0; }
  .weeks__tabs { width: 100%; }
  .meter { width: 100%; padding: 0 0 12px; }
  .meter__line { flex: 1 1 auto; width: auto; }
  .week-head { flex-direction: column; gap: 5px; padding-top: 24px; }
  .week-head p { text-align: left; }
  .day { grid-template-columns: 1fr; gap: 10px; padding: 18px 0; }
  .day__head { flex-direction: row; align-items: baseline; gap: 10px; }
  .day__stats { flex-direction: row; gap: 10px; margin-left: auto; }
  .foot { flex-direction: column; gap: 6px; }
  .field-row { grid-template-columns: 1fr; }
  .auth-header { padding-top: 32px; }
  .auth-header h1 { font-size: 32px; }
  .share-link { flex-direction: column; }
  .qr-wrap { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
