:root {
  --bg: #faf9f5;
  --panel: #ffffff;
  --ink: #1f1e1d;
  --muted: #73706a;
  --faint: #a29e96;
  --line: #e8e5dc;
  --line-strong: #d6d2c6;
  --hover: #f2f0e8;
  --accent: #c96442;
  --accent-soft: #f6e8e1;
  --danger: #b3261e;
  --ok: #3d7a4f;
  --desk: #ecebe4;
  --warn-bg: #fbf3e1;
  --warn-line: #e6cb92;
  --warn-ink: #6b4e16;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #262624;
    --panel: #30302d;
    --ink: #ecebe6;
    --muted: #aaa69d;
    --faint: #7f7c74;
    --line: #3c3c38;
    --line-strong: #4c4b46;
    --hover: #393935;
    --accent: #d97757;
    --accent-soft: #43322b;
    --danger: #f2877e;
    --ok: #8cc79c;
    --desk: #1d1d1b;
    --warn-bg: #3a3122;
    --warn-line: #6b5630;
    --warn-ink: #ecd9a8;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
code { font-size: 0.92em; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- шапка ---------- */

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.top-inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px 14px;
  flex-wrap: wrap;
}
.title {
  flex: 1 1 220px;
  min-width: 0;
  margin-left: -8px;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  font: 600 22px/1.25 ui-serif, Georgia, "Times New Roman", serif;
}
.title:hover { background: var(--hover); }
.title:focus { outline: none; background: var(--panel); border-color: var(--line-strong); }
.tabs { display: flex; padding: 3px; border-radius: 10px; background: var(--hover); }
.tab-btn { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; color: var(--muted); }
.tab-btn[aria-selected="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.status { min-width: 90px; font-size: 13px; color: var(--muted); }
.status.ok { color: var(--ok); }
.status.error { color: var(--danger); }
.ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
}
.ghost:hover { background: var(--hover); color: var(--ink); }

main { max-width: 880px; margin: 0 auto; padding: 20px 16px 32px; }
.warning {
  max-width: 848px;
  margin: 16px auto 0;
  padding: 10px 14px;
  border: 1px solid var(--warn-line);
  border-radius: 10px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 14px;
}
.foot {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 16px 28px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 16px;
  font-size: 13px;
  color: var(--faint);
}
.link { border: 0; background: none; padding: 0; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong); font-size: 13px; }
.link:hover { color: var(--ink); }

/* ---------- сегодня ---------- */

.today { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.today-day { padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.today-head { font-size: 14px; color: var(--muted); }
.today-head b { color: var(--ink); font-weight: 600; }
.today-groups { margin: 2px 0 8px; font-size: 13px; color: var(--accent); }
.today-tasks { display: flex; flex-wrap: wrap; gap: 4px 6px; margin: 0; padding: 0; list-style: none; }
.today-tasks li { padding: 2px 8px; border-radius: 6px; background: var(--hover); font-size: 13px; }
.intro { margin: 0 0 16px; color: var(--muted); font-size: 14px; }

/* ---------- блоки и дела ---------- */

.groups { display: flex; flex-direction: column; gap: 14px; }
.group { padding: 10px 12px 10px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.group-head { display: flex; align-items: center; gap: 8px; }
.group-name { flex: 1; font: 600 17px/1.3 ui-serif, Georgia, serif; }
.tools { display: flex; flex: none; gap: 2px; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}
.icon-btn:hover:not(:disabled) { background: var(--hover); color: var(--ink); }
.icon-btn.danger:hover:not(:disabled) { color: var(--danger); }
.icon-btn:disabled { opacity: 0.28; }
.icon { display: inline-flex; }

.rule-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 12px;
  padding: 0 8px 8px;
  border: 0;
  background: transparent;
  text-align: left;
  font-size: 14px;
  color: var(--muted);
}
.rule-text { color: var(--accent); font-weight: 500; }
.rule-edit { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
.rule-line:hover .rule-edit { color: var(--ink); }

.rule-editor {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 0 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}
.rule-col { display: flex; flex-direction: column; gap: 8px; }
.rule-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; font-size: 14px; }
.rule-row input[type="number"] { width: 64px; }
.rule-hint { margin: 0; color: var(--muted); font-size: 13px; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.seg-btn {
  padding: 5px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 14px;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.on { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.wd .seg-btn { width: 44px; padding: 5px 0; }
.field { padding: 5px 8px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--panel); }

.tasks { margin: 0; padding: 0; list-style: none; }
.task {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  border-top: 1px solid var(--line);
  transition: transform 0.6s ease, box-shadow 0.6s ease;
}
.task:first-child { border-top: 0; }
.quiet {
  width: 100%;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
}
.quiet:hover { background: var(--hover); }
.quiet:focus { outline: none; border-color: var(--line-strong); background: var(--panel); }
.task-hint { color: var(--muted); font-size: 13px; }
.quiet::placeholder { color: var(--faint); }
.add-task {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  padding: 2px 4px 2px 10px;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  color: var(--faint);
}
.btn { padding: 6px 12px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--panel); font-size: 14px; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.primary { padding: 8px 22px; border-color: var(--accent); background: var(--accent); color: #fff; font-weight: 500; }
.btn.primary:hover { filter: brightness(0.95); }
.add-group {
  width: 100%;
  margin-top: 14px;
  padding: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
  background: transparent;
  color: var(--muted);
}
.add-group:hover { background: var(--hover); color: var(--ink); }
.empty { padding: 24px; text-align: center; color: var(--muted); }

@media (max-width: 640px) {
  .today { grid-template-columns: 1fr; }
  .task { grid-template-columns: minmax(0, 1fr) auto; row-gap: 0; }
  .task-name { grid-column: 1; grid-row: 1; }
  .task-tools { grid-column: 2; grid-row: 1; }
  .task-hint { grid-column: 1 / -1; grid-row: 2; margin-top: -4px; }
  .status { order: 5; min-width: 0; }
}

/* ---------- настройки печати ---------- */

.print-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}
.ctl { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; font-size: 14px; }
.ctl-label { width: 90px; color: var(--muted); }
.ctl-print { justify-content: space-between; padding-top: 12px; border-top: 1px solid var(--line); }
.muted { color: var(--muted); font-size: 14px; }

.sheets {
  --zoom: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 18px 12px;
  border-radius: 14px;
  background: var(--desk);
  overflow: hidden;
}

/* ---------- лист A4 (всегда чёрным по белому) ---------- */

.sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: none;
  width: 210mm;
  height: 296mm;
  padding: 9mm 10mm;
  overflow: hidden;
  zoom: var(--zoom);
  background: #fff;
  color: #111;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 6px 20px rgba(0, 0, 0, 0.06);
  font: 9pt/1.25 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.sheet-head {
  display: flex;
  align-items: baseline;
  gap: 4mm;
  height: 14mm;
  margin-bottom: 3mm;
  padding-top: 2mm;
  border-bottom: 0.35mm solid #111;
}
.sheet-title { font: 600 16pt/1 ui-serif, Georgia, "Times New Roman", serif; }
.sheet-period { font-size: 12pt; }
.legend { display: flex; align-items: center; gap: 1.5mm; margin-left: auto; font-size: 8pt; color: #444; }
.legend .box + span { margin-right: 3mm; }
.box { display: inline-block; flex: none; width: 3.8mm; height: 3.8mm; border: 0.3mm solid #111; border-radius: 0.6mm; background: #fff; }
.box.off { border-color: #999; background: #e2e2e2; }
.sheet-empty { margin: 20mm 0; text-align: center; font-size: 12pt; color: #666; }
.sheet-page { position: absolute; right: 10mm; bottom: 4mm; font-size: 7pt; color: #999; }

.sheet-foot { margin-top: auto; padding-top: 2.5mm; font-size: 8pt; color: #333; }
.foot-total { font-size: 9pt; color: #111; }
.blank { display: inline-block; width: 18mm; border-bottom: 0.3mm solid #111; }
.memo { margin-top: 1.5mm; columns: 2; column-gap: 6mm; }
.memo div { margin-bottom: 0.8mm; break-inside: avoid; }
.joke { margin-top: 1.5mm; font: italic 9pt ui-serif, Georgia, serif; color: #555; }

/* таблица: месяц на листе */
.grid { width: 100%; border-collapse: collapse; table-layout: fixed; }
.grid col.c-date { width: 19mm; }
.grid th, .grid td { padding: 0; border: 0.2mm solid #8a8a8a; }
.grid .gh th { height: 6mm; background: #efefef; font-size: 8pt; font-weight: 600; text-align: center; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding: 0 1mm; }
.grid .gh .corner { background: #fff; vertical-align: bottom; padding-bottom: 1.5mm; font-weight: 400; color: #555; }
.grid .th th { height: 34mm; padding: 1.2mm 0; vertical-align: bottom; font-weight: 500; }
.grid .th span {
  display: inline-block;
  max-height: 31mm;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 8.5pt;
  line-height: 1.1;
  text-align: left;
}
.grid.narrow .th span { font-size: 7.5pt; }
.grid td.d { padding: 0 1.5mm; white-space: nowrap; font-size: 9pt; }
.grid td.d b { display: inline-block; width: 6mm; margin-right: 1.5mm; text-align: right; }
.grid td.off { background: #e2e2e2; }
.grid tr.we td.d { background: #ededed; font-weight: 600; }
.grid tr.wk td { border-top: 0.55mm solid #111; }
.grid .gs { border-left: 0.55mm solid #111; }

/* список: неделя на листе */
.week-list { flex: 1; min-height: 0; display: grid; grid-template-rows: repeat(7, minmax(0, 1fr)); gap: 2mm; }
.band { display: grid; grid-template-columns: 25mm 1fr; overflow: hidden; border: 0.3mm solid #222; border-radius: 1.5mm; }
.band-date { display: flex; flex-direction: column; padding: 1.5mm 2.2mm; border-right: 0.3mm solid #222; }
.band.we .band-date { background: #ededed; }
.band-day { font: 600 18pt/1 ui-serif, Georgia, serif; }
.band-wd { margin-top: 0.5mm; font-size: 9pt; font-weight: 600; }
.band-month { font-size: 8pt; color: #555; }
.band-tags { margin-top: auto; font-size: 7pt; line-height: 1.15; color: #555; }
.band-tasks { margin: 0; padding: 2mm 3mm; list-style: none; columns: 3; column-gap: 4mm; font-size: calc(9.5pt * var(--fs, 1)); }
.band-tasks li { display: flex; align-items: center; gap: 1.8mm; padding: 0.7mm 0; break-inside: avoid; line-height: 1.2; }
.band-free { align-self: center; padding: 0 4mm; color: #777; font-style: italic; }

/* ---------- случайные события ---------- */

#fun-layer { position: fixed; inset: 0; z-index: 50; overflow: hidden; pointer-events: none; }
.fun-sprite { position: absolute; left: 0; top: 0; will-change: transform; }
.fun-sprite svg { display: block; overflow: visible; }
.fun-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.fun-sprite .leg { transform-box: fill-box; transform-origin: 50% 8%; }
.walking .leg-a { animation: fun-leg 0.45s ease-in-out infinite alternate; }
.walking .leg-b { animation: fun-leg 0.45s ease-in-out infinite alternate-reverse; }
.fun-sprite .tail { transform-box: fill-box; transform-origin: 100% 100%; animation: fun-tail 1.4s ease-in-out infinite alternate; }
.fun-bubble {
  position: absolute;
  left: 96px;
  top: -26px;
  padding: 2px 9px;
  border: 1px solid #ddd;
  border-radius: 10px;
  background: #fff;
  color: #333;
  font-size: 13px;
  animation: fun-pop 0.25s ease-out;
}
.vacuum svg { transform-origin: 50% 90%; animation: fun-wobble 0.5s ease-in-out infinite alternate; }
.fun-sprite .led, .ufo-lights circle { animation: fun-blink 0.8s steps(1) infinite; }
.ufo-lights circle { fill: #ffe27a; }
.ufo-lights circle:nth-child(even) { animation-delay: 0.4s; }
.miner svg { animation: fun-bob 0.3s steps(1) infinite; }
.miner .fa { animation: fun-frame-a 0.3s steps(1) infinite; }
.miner .fb { animation: fun-frame-b 0.3s steps(1) infinite; }
.miner .pick { transform-box: fill-box; transform-origin: 0% 100%; animation: fun-swing 0.3s ease-in-out infinite alternate; }
.sun .rays { transform-box: view-box; transform-origin: 100px 100px; animation: fun-spin 14s linear infinite; }
.garland .bulb { animation: fun-glow 1.4s ease-in-out infinite alternate; }
.fun-beam {
  position: absolute;
  background: rgba(255, 233, 140, 0.38);
  clip-path: polygon(38% 0, 62% 0, 100% 100%, 0 100%);
  animation: fun-fade 0.4s ease-out;
}
.fun-lifted { transform: translateY(-8px) rotate(-0.8deg); box-shadow: 0 10px 18px rgba(0, 0, 0, 0.08); position: relative; z-index: 2; background: var(--panel); }
.fun-rank { position: fixed; top: 84px; right: 24px; text-align: right; font: italic 700 72px/1 ui-serif, Georgia, serif; }
.fun-rank small { display: block; margin-top: 4px; font: 600 12px/1 system-ui, sans-serif; letter-spacing: 0.14em; color: var(--muted); }

@keyframes fun-leg { from { transform: rotate(22deg); } to { transform: rotate(-22deg); } }
@keyframes fun-tail { from { transform: rotate(-10deg); } to { transform: rotate(12deg); } }
@keyframes fun-wobble { from { transform: rotate(-2deg); } to { transform: rotate(2deg); } }
@keyframes fun-blink { 50% { opacity: 0.25; } }
@keyframes fun-bob { 50% { transform: translateY(-3px); } }
@keyframes fun-frame-a { 0% { opacity: 1; } 50% { opacity: 0; } }
@keyframes fun-frame-b { 0% { opacity: 0; } 50% { opacity: 1; } }
@keyframes fun-swing { from { transform: rotate(-12deg); } to { transform: rotate(20deg); } }
@keyframes fun-spin { to { transform: rotate(360deg); } }
@keyframes fun-glow { from { opacity: 0.35; } to { opacity: 1; } }
@keyframes fun-fade { from { opacity: 0; } }
@keyframes fun-pop { from { transform: scale(0.6); opacity: 0; } }

#toast {
  position: fixed;
  left: 50%;
  top: 72px;
  z-index: 60;
  max-width: calc(100% - 32px);
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, -8px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}
#toast.show { opacity: 0.94; transform: translate(-50%, 0); }

/* ---------- печать: только листы ---------- */

@page { size: A4 portrait; margin: 0; }

@media print {
  html, body { background: #fff; }
  .top, .warning, .foot, #tab-plan, .print-controls, #fun-layer, #toast { display: none !important; }
  main { max-width: none; margin: 0; padding: 0; }
  #tab-print { display: block !important; }
  .sheets { display: block; gap: 0; padding: 0; border-radius: 0; background: none; }
  .sheet { zoom: 1 !important; box-shadow: none; break-after: page; }
  .sheet:last-child { break-after: auto; }
}
