/* ============================================================
   Streakproof — визуальный язык: личный журнал, где каждый
   выполненный день — это чернильный штамп. Не стирается,
   не пропадает при смене устройства.
   ============================================================ */

:root {
  --paper: #EEEFE9;
  --paper-raised: #F6F7F2;
  --ink: #1C2321;
  --ink-soft: #4A544F;
  --stamp: #2F6F5E;
  --stamp-soft: #E3ECE8;
  --line: #D8D5C9;
  --missed: #B8574A;
  --missed-soft: #F3E4E0;

  --font-display: Iowan Old Style, Georgia, Cambria, "Times New Roman", serif;
  --font-ui: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", ui-monospace, "Cascadia Mono", "Roboto Mono", Consolas, monospace;

  --radius: 14px;
  --radius-sm: 8px;
  --tap: 44px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #15201C;
    --paper-raised: #1B2620;
    --ink: #EDEFE9;
    --ink-soft: #A9B3AC;
    --stamp: #6FBFA6;
    --stamp-soft: #22332C;
    --line: #2C3A33;
    --missed: #D98476;
    --missed-soft: #33221E;
  }
}

:root[data-theme="dark"] {
  --paper: #15201C;
  --paper-raised: #1B2620;
  --ink: #EDEFE9;
  --ink-soft: #A9B3AC;
  --stamp: #6FBFA6;
  --stamp-soft: #22332C;
  --line: #2C3A33;
  --missed: #D98476;
  --missed-soft: #33221E;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
}

button, input {
  font-family: inherit;
}

:focus-visible {
  outline: 2px solid var(--stamp);
  outline-offset: 2px;
}

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

/* ---------------- Layout shell ---------------- */

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px 96px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 20px 16px 14px;
  margin: 0 -16px;
  background: linear-gradient(var(--paper) 80%, transparent);
}

.wordmark {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.2px;
  color: var(--ink);
}

.wordmark small {
  display: block;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-soft);
  margin-top: 2px;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line);
  display: inline-block;
  margin-right: 6px;
  transition: background 0.3s;
}
.sync-dot.online { background: var(--stamp); }
.sync-dot.pending { background: #C9A227; }

.sync-status {
  font-size: 12px;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
}

/* ---------------- Habit ledger rows ---------------- */

.ledger {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.habit-row {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 10px;
}

.habit-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.habit-name {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  background: none;
  border: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
}

.streak-count {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 20px;
  color: var(--stamp);
  white-space: nowrap;
}
.streak-count .unit {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--ink-soft);
  margin-left: 4px;
}

.days-strip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.day-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.day-label {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-soft);
}

.stamp-btn {
  width: var(--tap);
  height: var(--tap);
  border-radius: 50%;
  border: 2px solid var(--line);
  background: transparent;
  cursor: pointer;
  position: relative;
  padding: 0;
  transition: border-color 0.15s, background 0.15s;
}

.stamp-btn.today {
  border-style: dashed;
  border-color: var(--ink-soft);
}

.stamp-btn.done {
  border-color: var(--stamp);
  background: var(--stamp-soft);
}

.stamp-btn.done::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  border: 2px solid var(--stamp);
}

.stamp-btn.missed-past {
  border-color: var(--missed);
  background: var(--missed-soft);
  opacity: 0.7;
}

/* Момент "проставления штампа" — единственная анимация в интерфейсе */
.stamp-btn.stamping::after {
  animation: stamp-hit 0.32s ease-out;
}
@keyframes stamp-hit {
  0%   { transform: scale(0.4); opacity: 0; }
  60%  { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--ink-soft);
}
.empty-state h2 {
  font-family: var(--font-display);
  color: var(--ink);
  font-size: 20px;
  margin: 0 0 8px;
}
.empty-state p {
  font-size: 14px;
  line-height: 1.5;
  max-width: 34ch;
  margin: 0 auto;
}

/* ---------------- Floating add button ---------------- */

.fab {
  position: fixed;
  right: 20px;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--stamp);
  color: var(--paper-raised);
  border: none;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.22);
}

/* ---------------- Sheets / modals ---------------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 22, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.sheet {
  width: 100%;
  max-width: 640px;
  background: var(--paper-raised);
  border-radius: 18px 18px 0 0;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  border: 1px solid var(--line);
  border-bottom: none;
}

.sheet h2 {
  font-family: var(--font-display);
  margin: 0 0 16px;
  font-size: 19px;
}

.field {
  margin-bottom: 14px;
}
.field label {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
}

.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.btn {
  flex: 1;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary {
  background: var(--stamp);
  border-color: var(--stamp);
  color: var(--paper-raised);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.error-line {
  color: var(--missed);
  font-size: 13px;
  margin-top: 8px;
  min-height: 18px;
}

/* ---------------- Auth screen ---------------- */

.auth-screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px;
  max-width: 400px;
  margin: 0 auto;
}

.auth-screen .wordmark {
  text-align: center;
  margin-bottom: 28px;
  font-size: 28px;
}

.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
}
.auth-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.auth-tab.active {
  color: var(--ink);
  border-bottom-color: var(--stamp);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 50vh;
  overflow-y: auto;
  margin: -4px 0 4px;
}
.history-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.history-row .date {
  font-family: var(--font-mono);
  color: var(--ink-soft);
}
