:root {
  --paper: #f3ead6;
  --paper-2: #ebe0c8;
  --sheet: #f7f1e4;
  --ink: #17233a;
  --ink-2: #3d4a63;
  --ink-3: #6b7385;
  --fade: #8a8170;
  --stamp: #c41e3a;
  --mark: #f5d76e;
  --line: rgba(23, 35, 58, 0.12);
  --line-strong: rgba(23, 35, 58, 0.22);
  --ok: #2c6b4f;
  --control: #e7dcc4;
  --veil: rgba(23, 35, 58, 0.35);
  --ballpoint: #1a4a8a;
  --rail: #c4b89a;
  --radius: 14px;
  --pad: 16px;
  --font: "Golos Text", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
}

html[data-theme="dark"] {
  --paper: #0c1018;
  --paper-2: #141a26;
  --sheet: #161d2c;
  --ink: #e8dcc4;
  --ink-2: #c4b89a;
  --ink-3: #8a8170;
  --fade: #6b6458;
  --stamp: #e23d55;
  --mark: #3a2e12;
  --line: rgba(232, 220, 196, 0.1);
  --line-strong: rgba(232, 220, 196, 0.2);
  --ok: #6db894;
  --control: #1c2434;
  --veil: rgba(0, 0, 0, 0.55);
  --ballpoint: #8ab4ff;
  --rail: #5c564c;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--rail) var(--paper);
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: var(--paper); }
*::-webkit-scrollbar-thumb {
  background: var(--rail);
  border: 2px solid var(--paper);
  border-radius: 99px;
}
*::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }
*::-webkit-scrollbar-corner { background: var(--paper); }

#app {
  max-width: 440px;
  margin: 0 auto;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
  overflow: hidden;
}
#app:has(.login) { height: auto; max-height: none; overflow: auto; min-height: 100dvh; }
button, input, textarea, a { touch-action: manipulation; }
a { color: var(--ink-2); text-underline-offset: 2px; }
a:visited { color: var(--ink-2); }

.top {
  padding: calc(12px + env(safe-area-inset-top)) var(--pad) 10px;
  border-bottom: 1px solid var(--line);
}
.kicker { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--stamp); font-weight: 600; }
.top h1 { margin: 4px 0 0; font-size: 22px; font-weight: 700; letter-spacing: -0.03em; }
.meta { margin-top: 6px; font-size: 12px; color: var(--ink-3); }

.scroll { flex: 1; min-height: 0; padding: 8px var(--pad) calc(88px + env(safe-area-inset-bottom)); overflow: auto; }

.day-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 18px 0 8px;
}
.day-head .name { font-size: 15px; font-weight: 700; }
.day-head .dow { font-size: 12px; color: var(--fade); text-transform: lowercase; }
.day-head.today .name { color: var(--stamp); }

.day-sheet section,
.week-board section {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
}

.pair {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  grid-template-areas:
    "num time cab"
    "num subj subj"
    "num who who"
    "num hw hw";
  gap: 0 10px;
  padding: 12px 14px;
  margin: 2px 0;
  border: 0;
  border-radius: 12px;
  box-shadow: inset 0 1px 0 var(--line);
  cursor: pointer;
  align-self: stretch;
  width: 100%;
  min-width: 100%;
  max-width: none;
  box-sizing: border-box;
  text-align: left;
  background: transparent;
  font: inherit; color: inherit;
  appearance: none;
  -webkit-appearance: none;
}
.pair:first-of-type { box-shadow: none; }
.pair.now {
  background: var(--mark);
  box-shadow: none;
}
.num {
  grid-area: num;
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--ink); color: var(--paper);
  display: grid; place-items: center;
  font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums;
  align-self: start;
}
.pair.now .num { background: var(--stamp); }
.time { grid-area: time; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.cab {
  grid-area: cab;
  font-weight: 600;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  line-height: 1.25;
  max-width: 46vw;
  text-align: right;
}
.cab:empty { display: none; }
.cab-lg { font-size: 16px; margin: 8px 0 2px; max-width: none; text-align: left; font-weight: 600; }
.subj { grid-area: subj; font-weight: 600; font-size: 15px; letter-spacing: -0.02em; line-height: 1.25; }
.who { grid-area: who; font-size: 12px; color: var(--ink-2); margin-top: 3px; }
.hw-dot { grid-area: hw; margin-top: 6px; font-size: 12px; color: var(--ballpoint); }
.hw-dot.done { color: var(--ok); text-decoration: line-through; }
.hw-dot.empty { display: none; }
.empty { color: var(--fade); font-size: 14px; padding: 24px 0; }
.split { font-size: 11px; color: var(--stamp); font-weight: 600; }

.card {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.card h3 { margin: 0 0 6px; font-size: 16px; }
.muted { color: var(--ink-3); font-size: 13px; }
label { display: block; font-size: 12px; color: var(--ink-3); margin: 10px 0 4px; }
input, textarea, select {
  width: 100%; font: inherit; font-size: 15px; color: var(--ink);
  background: var(--control); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px;
}
textarea { min-height: 88px; resize: vertical; }
button.primary, button.ghost {
  font: inherit; font-weight: 600; border-radius: 12px; padding: 12px 16px; cursor: pointer;
}
button.primary { background: var(--ink); color: var(--paper); border: 0; width: 100%; margin-top: 14px; }
button.ghost { background: transparent; border: 1px solid var(--line-strong); color: var(--ink); }

.nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(440px, 100%);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--paper);
  border-top: 1px solid var(--line);
  padding: 6px 2px calc(8px + env(safe-area-inset-bottom));
  z-index: 4;
}
.nav button {
  border: 0; background: none; font: inherit;
  font-size: 10px; font-weight: 600; letter-spacing: 0.01em;
  color: var(--ink-3); padding: 6px 0 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.nav svg { width: 22px; height: 22px; display: block; }
.nav button.on { color: var(--stamp); }
.nav-long { display: none; }
.rail-brand { display: none; }
.sync-btn { width: 100%; margin-top: 8px; }

.sheet-bg {
  position: fixed; inset: 0; background: var(--veil);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 6;
}
.sheet {
  width: min(440px, 100%);
  background: var(--sheet);
  border-radius: 18px 18px 0 0;
  padding: 4px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 88dvh; overflow: auto;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--rail) var(--sheet);
  transition: transform 0.2s ease;
}
.sheet::-webkit-scrollbar { width: 10px; height: 10px; }
.sheet::-webkit-scrollbar-track { background: var(--sheet); }
.sheet::-webkit-scrollbar-thumb {
  background: var(--rail);
  border: 2px solid var(--sheet);
  border-radius: 99px;
}
.sheet::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }
.sheet textarea {
  scrollbar-width: thin;
  scrollbar-color: var(--rail) var(--control);
}
.sheet textarea::-webkit-scrollbar { width: 10px; height: 10px; }
.sheet textarea::-webkit-scrollbar-track { background: var(--control); }
.sheet textarea::-webkit-scrollbar-thumb {
  background: var(--rail);
  border: 2px solid var(--control);
  border-radius: 99px;
}
.sheet textarea::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }
.sheet.dragging { transition: none; }
.sheet-handle { padding: 10px 0 12px; touch-action: none; }
.grab { width: 36px; height: 4px; background: var(--line-strong); border-radius: 99px; margin: 0 auto; }

.check {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
  font-size: 14px;
  cursor: pointer;
  width: fit-content;
}
.check input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  min-width: 22px;
  max-width: 22px;
  padding: 0;
  margin: 0;
  flex: 0 0 22px;
  border: 1.5px solid var(--line-strong);
  border-radius: 6px;
  background: var(--control);
  cursor: pointer;
  position: relative;
  box-sizing: border-box;
}
.check input[type="checkbox"]:checked {
  background: var(--ink);
  border-color: var(--ink);
}
.check input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  width: 5px;
  height: 10px;
  border: solid var(--paper);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.check input[type="checkbox"]:focus-visible { outline: 2px solid var(--stamp); outline-offset: 2px; }

.login { padding: 48px var(--pad); position: relative; z-index: 2; }
.login input, .login button { pointer-events: auto; }
.login h1 { font-size: 28px; margin: 8px 0 8px; letter-spacing: -0.04em; }
.boot .muted { animation: boot-pulse 1.2s ease-in-out infinite; }
@keyframes boot-pulse { 50% { opacity: 0.4; } }
.auth-tabs { display: flex; gap: 4px; margin: 16px 0 4px; }
.auth-tabs button {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  border: 0; background: transparent; color: var(--ink-3);
  padding: 8px 12px; border-radius: 999px;
}
.auth-tabs button.on { background: var(--ink); color: var(--paper); }

.hw-head { margin-bottom: 12px; }
.hw-card {
  width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer;
  border: 1px solid var(--line); background: var(--sheet);
}
.hw-card h3 { margin: 4px 0 6px; font-size: 16px; }
#hw-target, #task-subject, #task-due, #hw-due {
  width: 100%; font: inherit; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--control); color: var(--ink);
  margin-bottom: 8px;
}

.set { margin-bottom: 18px; }
.set h3 {
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--stamp);
  font-weight: 600;
}
.theme-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.theme-pick button {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line-strong);
  background: var(--control);
  color: var(--ink);
  border-radius: 12px;
  padding: 14px 12px;
  text-align: left;
}
.theme-pick button small { display: block; font-weight: 500; color: var(--ink-3); font-size: 12px; margin-top: 4px; }
.theme-pick button.on { border-color: var(--stamp); box-shadow: inset 0 0 0 1px var(--stamp); }
.hint { font-size: 13px; color: var(--ink-3); line-height: 1.45; margin: 0; }

@media (min-width: 900px) {
  html, body {
    height: 100%;
    overflow: hidden;
    background: var(--paper-2);
  }
  #app {
    max-width: 1180px;
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    min-height: 0;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 212px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "rail head" "rail main";
    background: var(--paper);
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    overflow: hidden;
  }
  #app:has(.login) {
    display: flex;
    max-width: none;
    height: 100dvh;
    border: 0;
    background: transparent;
    align-items: center;
    justify-content: center;
    overflow: auto;
  }
  .login {
    width: 380px;
    background: var(--sheet);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 40px 36px 36px;
  }
  .top {
    grid-area: head;
    min-width: 0;
    padding: 22px 28px 16px;
  }
  .top .kicker { display: none; }
  .top h1 { font-size: 26px; }
  .scroll {
    grid-area: main;
    min-width: 0;
    min-height: 0;
    padding: 8px 28px 28px;
    overflow: auto;
    scrollbar-gutter: stable;
  }
  .nav {
    grid-area: rail;
    position: relative;
    left: auto;
    transform: none;
    width: auto;
    min-width: 0;
    min-height: 0;
    height: auto;
    overflow: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    border-top: 0;
    border-right: 1px solid var(--line);
    padding: 20px 12px 24px;
    background: var(--paper);
  }
  .rail-brand { display: block; padding: 2px 10px 18px; }
  .rail-title { font-size: 20px; font-weight: 700; letter-spacing: -0.04em; margin: 2px 0 4px; }
  .nav button {
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
    font-size: 14px;
    padding: 9px 12px;
    border-radius: 10px;
  }
  .nav svg { width: 18px; height: 18px; }
  .nav-short { display: none; }
  .nav-long { display: inline; }
  .nav button.on { background: var(--control); }
  .nav button:hover { color: var(--ink); background: var(--paper-2); }
  .nav button.on:hover { background: var(--control); color: var(--stamp); }
  .day-sheet { max-width: 640px; }
  .week-board { display: block; }
  .week-board section { padding: 0 0 8px; }
  .week-board .empty { padding: 8px 0 16px; }
  .pair {
    grid-template-columns: 40px 9rem minmax(8rem, 0.9fr) minmax(10rem, 1.4fr) minmax(8rem, 1fr) minmax(4rem, 1fr);
    grid-template-areas: "num time cab subj who hw";
    align-items: start;
    column-gap: 14px;
    row-gap: 0;
    width: 100%;
    min-width: 0;
  }
  .num { align-self: start; }
  .cab {
    font-size: 13px;
    max-width: none;
    text-align: left;
  }
  .who { margin-top: 0; }
  .hw-dot { margin-top: 0; }
  .hw-dot.empty { display: block; visibility: hidden; }
  .card-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
  .card-grid .card { margin-bottom: 0; min-width: 0; }
  .desk-sets {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 16px;
    align-items: start;
  }
  .desk-sets > .set:first-child { grid-column: 1 / -1; }
  .theme-pick { max-width: 480px; }
  .scroll button.primary { width: auto; min-width: 200px; }
  .sync-btn { width: auto; }
  .sheet-bg { align-items: center; }
  .sheet {
    width: min(460px, calc(100% - 48px));
    border-radius: 16px;
    max-height: 82dvh;
    padding: 22px 24px 24px;
  }
  .sheet-handle { display: none; }
}

@media (hover: hover) {
  .pair:hover { background: var(--paper-2); box-shadow: none; }
  .pair.now:hover { background: var(--mark); }
}
