:root {
  color-scheme: dark;
  --bg: #090b10;
  --panel: rgba(18, 22, 31, 0.88);
  --panel-strong: #131824;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #f2f5fb;
  --muted: #98a2b3;
  --soft: #1d2432;
  --accent: #4f8cff;
  --accent-2: #7c5cff;
  --success: #21c17a;
  --danger: #ff5e74;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(79, 140, 255, 0.18), transparent 30%),
    radial-gradient(circle at top right, rgba(124, 92, 255, 0.16), transparent 26%),
    linear-gradient(180deg, #0b0d13 0%, #090b10 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  padding: 18px;
  overflow-x: hidden;
}

body.locked {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  max-width: 1440px;
  margin: 0 auto;
}

.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at top, rgba(79, 140, 255, 0.18), transparent 30%),
    linear-gradient(180deg, rgba(9, 11, 16, 0.98), rgba(9, 11, 16, 0.98));
}

.lock-card {
  width: min(100%, 420px);
  padding: 24px;
  border-radius: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
}

.lock-card input {
  width: 100%;
  margin-top: 8px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #0d1119;
  color: var(--text);
  padding: 12px 14px;
  outline: none;
}

.lock-card input:focus {
  border-color: rgba(79, 140, 255, 0.65);
  box-shadow: 0 0 0 4px rgba(79, 140, 255, 0.12);
}

.lock-submit {
  width: 100%;
}

.lock-error {
  margin: 0;
  color: #ff9dac;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 4px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.28);
  flex: 0 0 auto;
}

.brand-copy {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 4px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  font-size: 11px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(26px, 4vw, 34px);
}

.content {
  display: grid;
  gap: 18px;
  grid-template-columns: 1fr;
  grid-template-areas:
    "hero"
    "toolbar"
    "calendar"
    "routines";
}

.hero-card,
.calendar-panel,
.routines-panel,
.dialog-card {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  border-radius: 24px;
}

.hero-card {
  padding: 18px;
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
  grid-area: hero;
}

.hero-label {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.hero-expected {
  margin-top: 8px;
  color: #d6dcf7;
  font-size: 15px;
  line-height: 1.3;
}

.hero-card strong {
  font-size: clamp(32px, 5vw, 42px);
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.hero-stats div {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
}

.hero-stats span,
.section-title p,
.hint,
.legend,
.calendar-meta,
.routine-meta,
.routine-note {
  color: var(--muted);
}

.hero-stats span {
  display: block;
  font-size: 12px;
  margin-bottom: 6px;
}

.hero-stats strong {
  font-size: 18px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  grid-area: toolbar;
}

.pill-btn,
.icon-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.pill-btn:hover,
.icon-btn:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--line-strong);
}

.pill-btn {
  padding: 11px 16px;
}

.pill-btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: white;
}

.pill-btn.active {
  background: linear-gradient(135deg, rgba(79, 140, 255, 0.24), rgba(124, 92, 255, 0.24));
  border-color: rgba(124, 92, 255, 0.55);
  color: #ffffff;
  box-shadow: 0 0 0 1px rgba(79, 140, 255, 0.12) inset;
}

#monthTodayBtn {
  min-width: 116px;
}

.pill-btn.danger {
  background: rgba(255, 94, 116, 0.08);
  border-color: rgba(255, 94, 116, 0.24);
  color: #ff9dac;
}

.icon-btn {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
}

.calendar-panel,
.routines-panel {
  padding: 18px;
  min-width: 0;
}

.calendar-title {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
  margin-bottom: 12px;
  text-align: center;
  flex-direction: column;
}

.calendar-title h2 {
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.05;
}

.calendar-panel {
  grid-area: calendar;
}

.routines-panel {
  grid-area: routines;
}

.calendar-head,
.section-title,
.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.calendar-head,
.section-title {
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title {
  flex-wrap: wrap;
}

.section-title .pill-btn {
  margin-left: auto;
}

.calendar-table {
  min-width: 100%;
}

.table-wrap {
  overflow: auto;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(8, 10, 15, 0.48);
}

.calendar-grid {
  display: grid;
  grid-template-columns: 220px repeat(var(--days), minmax(44px, 1fr));
}

.calendar-cell {
  min-height: 58px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

.calendar-cell.header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #131826;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.calendar-cell.sticky {
  position: sticky;
  left: 0;
  z-index: 4;
  justify-content: flex-start;
  gap: 10px;
  background: #121722;
}

.calendar-cell.sticky.header {
  z-index: 6;
}

.calendar-cell.day-header {
  flex-direction: column;
  font-size: 13px;
  line-height: 1;
}

.calendar-cell.day-header small {
  color: var(--muted);
  font-weight: 600;
  margin-top: 4px;
}

.calendar-cell.day-header.today {
  background: rgba(79, 140, 255, 0.15);
}

.calendar-cell.routine-name {
  justify-content: space-between;
}

.routine-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.routine-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.04);
}

.day-toggle {
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 23px;
  display: grid;
  place-items: center;
}

.day-toggle.done {
  color: #ffffff;
  text-shadow: 0 0 12px currentColor;
}

.day-toggle.today {
  background: rgba(79, 140, 255, 0.12);
}

.day-toggle:hover {
  background: rgba(255, 255, 255, 0.04);
}

.legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 13px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
}

.legend-dot.done {
  background: var(--success);
}

.legend-dot.empty {
  background: rgba(255, 255, 255, 0.16);
}

.routine-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.routine-card {
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  padding: 14px;
  display: grid;
  gap: 10px;
}

.routine-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.routine-card h3 {
  font-size: 18px;
}

.routine-card .meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.progress-bar {
  width: 100%;
  height: 10px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.routine-actions {
  display: flex;
  gap: 10px;
}

.routine-actions button {
  flex: 1;
}

.dialog {
  border: 0;
  padding: 0;
  background: transparent;
  width: min(92vw, 560px);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(3px);
}

.dialog-card {
  width: 100%;
  padding: 18px;
}

.dialog-card label {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.dialog-card input,
.dialog-card textarea {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #0d1119;
  color: var(--text);
  padding: 12px 14px;
  outline: none;
}

.dialog-card input:focus,
.dialog-card textarea:focus {
  border-color: rgba(79, 140, 255, 0.65);
  box-shadow: 0 0 0 4px rgba(79, 140, 255, 0.12);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.dialog-actions {
  margin-top: 18px;
}

.spacer {
  flex: 1;
}

.muted {
  color: var(--muted);
}

.note {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
}

@media (max-width: 820px) {
  body {
    padding: 12px;
  }

  .topbar {
    align-items: flex-start;
  }

  .brand-mark {
    width: 46px;
    height: 46px;
  }

  .hero-stats {
    grid-template-columns: 1fr;
  }

  .toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .toolbar .primary {
    grid-column: 1 / -1;
  }

  .content {
    grid-template-columns: 1fr;
    grid-template-areas:
      "hero"
      "toolbar"
      "calendar"
      "routines";
  }

  .calendar-table {
    min-width: 760px;
  }

  .calendar-grid {
    grid-template-columns: 150px repeat(var(--days), minmax(32px, 1fr));
  }

  .calendar-cell {
    min-height: 52px;
    padding: 6px;
  }

  .calendar-title {
    align-items: center;
    flex-direction: column;
    gap: 4px;
    text-align: center;
  }

  .calendar-title h2 {
    font-size: 24px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .calendar-head,
  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .section-title .pill-btn {
    margin-left: 0;
  }

  .routine-cards {
    grid-template-columns: 1fr;
  }

  .routine-card {
    padding: 12px;
    gap: 8px;
  }

  .routine-card h3 {
    font-size: 16px;
  }

  .routine-card .routine-note {
    display: none;
  }

  .routine-card .meta-row {
    font-size: 12px;
  }

  .routine-actions {
    gap: 8px;
  }

  .routine-actions button {
    padding: 10px 12px;
  }

  .calendar-cell.routine-name {
    padding: 6px 6px;
  }

  .routine-pill {
    gap: 8px;
  }

  .calendar-cell.routine-name strong {
    font-size: 14px;
    line-height: 1.15;
  }

  .routine-meta {
    font-size: 12px;
  }
}
