/* Минимализм в духе Anki: одна карточка по центру, системный шрифт, плоские кнопки. */
:root {
  --bg: #eeeeee;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #dcdce0;
  --field: #fafafa;
  --btn: #e9e9ec;
  --btn-press: #dcdce0;
  --accent: #3c6fd8;
  --accent-text: #ffffff;
  --ok: #2e7d32;
  --err: #c62828;
  --sleep: #6d8fd8;
  --grid: #e6e6ea;
  --grid-mid: #c9c9cf;
  color-scheme: light dark;
}
/* Тёмная тема: по системе или по теме Telegram (data-theme ставит JS). */
:root[data-theme=dark] {
  --bg: #1f1f1f;
  --card: #2b2b2b;
  --text: #e8e8e8;
  --muted: #9d9da3;
  --line: #3d3d40;
  --field: #232323;
  --btn: #3a3a3d;
  --btn-press: #47474b;
  --accent: #5b8cf0;
  --accent-text: #ffffff;
  --ok: #66bb6a;
  --err: #ef6c6c;
  --sleep: #7896dc;
  --grid: #363639;
  --grid-mid: #505055;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --bg: #1f1f1f;
    --card: #2b2b2b;
    --text: #e8e8e8;
    --muted: #9d9da3;
    --line: #3d3d40;
    --field: #232323;
    --btn: #3a3a3d;
    --btn-press: #47474b;
    --accent: #5b8cf0;
    --accent-text: #ffffff;
    --ok: #66bb6a;
    --err: #ef6c6c;
    --sleep: #7896dc;
    --grid: #363639;
    --grid-mid: #505055;
  }
}
:root[data-theme=light] { color-scheme: light; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 18px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(40px + env(safe-area-inset-bottom));
}
a { color: var(--accent); }

nav { display: flex; justify-content: center; flex-wrap: wrap; gap: 2px; margin-bottom: 12px; }
nav a {
  color: var(--muted); text-decoration: none; font-size: 16px;
  padding: 10px 12px; border-radius: 8px; min-height: 44px; display: inline-flex; align-items: center;
}
nav a.on { color: var(--text); background: var(--card); }

.card { background: var(--card); border-radius: 12px; padding: 24px 18px; overflow-wrap: anywhere; }
h1 { font-size: 24px; font-weight: 600; margin: 0 0 4px; text-align: center; line-height: 1.25; }
h1::first-letter { text-transform: uppercase; }
h2 { font-size: 15px; font-weight: 600; color: var(--muted); margin: 32px 0 4px; }
.sub { color: var(--muted); text-align: center; margin: 0 0 20px; }
.muted { color: var(--muted); }
.small { font-size: 15px; }
.center { text-align: center; }
.gap { margin-top: 28px; }
code { font-size: 14px; }

.btn {
  display: block; width: 100%; min-height: 52px; padding: 12px 16px;
  border: 0; border-radius: 10px; background: var(--btn); color: var(--text);
  font: inherit; font-size: 18px; text-align: center; text-decoration: none;
  cursor: pointer; -webkit-appearance: none; appearance: none; touch-action: manipulation;
}
.btn:active { background: var(--btn-press); }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.primary:active { filter: brightness(.92); }
.btn.big { min-height: 72px; font-size: 22px; font-weight: 600; }
.btn.small { width: auto; flex: 0 0 auto; min-height: 48px; font-size: 16px; padding: 8px 14px; }
.btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.btns .btn { font-size: 16px; padding: 12px 4px; }
.link { background: none; border: 0; padding: 12px 0; font: inherit; font-size: 16px; color: var(--accent); cursor: pointer; }
.link.danger { color: var(--err); }

.field { margin: 18px 0; min-width: 0; }
.field label, .lbl {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  color: var(--muted); font-size: 15px; margin-bottom: 6px;
}
input, textarea {
  display: block; width: 100%; min-width: 0; max-width: 100%; min-height: 48px;
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--field); color: var(--text);
  font: inherit; font-size: 18px; /* ≥16px: iOS не зумит при фокусе */
  -webkit-appearance: none; appearance: none;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input::-webkit-date-and-time-value { text-align: left; }
input[type=file] { padding: 10px; font-size: 16px; }
textarea { resize: vertical; line-height: 1.45; }
.row { display: flex; gap: 8px; align-items: flex-end; }
.row > * { flex: 1 1 0; min-width: 0; }
.row > .grow { flex: 2 1 0; }
.row .field { margin-bottom: 0; }
form.day > .row { margin: 18px 0; }

.st { font-size: 13px; opacity: 0; transition: opacity .4s; }
.field label, .lbl { white-space: nowrap; }
.field label > .st, .lbl > .st { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.st.show { opacity: 1; }
.st.ok { color: var(--ok); }
.st.err { color: var(--err); opacity: 1; }
.st.block { display: block; text-align: center; margin-top: 6px; min-height: 1em; }

.energy { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.energy button {
  min-height: 56px; border: 0; border-radius: 10px; background: var(--btn); color: var(--text);
  font: inherit; font-size: 20px; cursor: pointer; touch-action: manipulation; -webkit-appearance: none;
}
.energy button[aria-pressed=true] { background: var(--accent); color: var(--accent-text); }

.hello { padding: 24px 0 8px; text-align: center; }
.hello .btn { margin: 20px 0 10px; }

.notice { background: var(--field); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 12px 0 20px; font-size: 16px; }
.notice p { margin: 0 0 10px; }
.notice ul { margin: 0; padding-left: 20px; }
.notice.ok { border-color: var(--ok); }
.notice.err { border-color: var(--err); }

.list { margin-top: 8px; }
.item { display: block; padding: 14px 2px; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.item:last-child { border-bottom: 0; }
.item:active { background: var(--field); }
.item .top { display: flex; justify-content: space-between; gap: 8px; font-size: 17px; }
.item .meta { color: var(--muted); font-size: 15px; margin-top: 2px; }
.item .rep { font-size: 15px; margin-top: 4px; }

.pager { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; margin-bottom: 8px; }
.pager a { text-decoration: none; font-size: 22px; min-height: 44px; display: flex; align-items: center; justify-content: center; }
.pager.bottom { grid-template-columns: 1fr 1fr; margin-top: 16px; }
.pager.bottom a { font-size: 16px; }
.pager.bottom a:last-child { justify-content: flex-end; }

.seg { display: flex; justify-content: center; gap: 6px; margin: 12px 0 16px; }
.seg a { padding: 10px 14px; min-height: 44px; border-radius: 8px; background: var(--btn); color: var(--text); text-decoration: none; font-size: 16px; }
.seg a.on { background: var(--accent); color: var(--accent-text); }
.chart svg { display: block; width: 100%; height: auto; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .grid.mid { stroke: var(--grid-mid); }
.chart text { fill: var(--muted); font-size: 19px; font-family: inherit; }
.chart .bar { fill: var(--sleep); }
.chart .dot { fill: var(--muted); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 20px 0 0; }
.stats div { background: var(--field); border-radius: 10px; padding: 10px 12px; }
.stats dt { color: var(--muted); font-size: 14px; }
.stats dd { margin: 2px 0 0; font-size: 20px; }
.stats dd .muted { font-size: 14px; }

/* Экран PIN */
.pin { text-align: center; padding: 8px 0 4px; user-select: none; -webkit-user-select: none; }
.dots { display: flex; justify-content: center; gap: 18px; margin: 18px 0 30px; }
.dots span { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--text); box-sizing: border-box; }
.dots span.on { background: var(--text); }
.dots.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 16px 26px; justify-content: center; }
.keypad button {
  width: 76px; height: 76px; border-radius: 50%; border: 0; background: var(--btn); color: var(--text);
  font: inherit; font-size: 30px; cursor: pointer; touch-action: manipulation; -webkit-appearance: none;
}
.keypad button:active { background: var(--btn-press); }
.keypad button.ghost { background: none; font-size: 24px; }
.keypad button:disabled { opacity: .35; }
.lockbar { text-align: center; margin-top: 8px; }
.lockbar .link { color: var(--muted); font-size: 15px; }


/* Не показываем журнал и PIN, пока не сверили свежий запуск Telegram. */
#tg-status { display: none; margin: 2rem auto; text-align: center; }
.tg-checking #tg-status { display: block; }
.tg-checking #tg-content, .tg-checking .lockbar { display: none; }
