:root {
  color-scheme: light dark;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --text: #1b1b1f;
  --muted: #6b6b76;
  --border: #e2e2e6;
  --accent: #3b5bdb;
  --accent-contrast: #ffffff;
  --danger: #c9384d;
  --success: #2f9e5b;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a;
    --surface: #1f1f24;
    --text: #eaeaef;
    --muted: #9a9aa5;
    --border: #303038;
    --accent: #7c93f7;
    --accent-contrast: #14142b;
  }
}

* { box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

a { color: var(--accent); }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar .brand {
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
  color: var(--text);
}

.nav-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
}

.topbar nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  flex: 1;
}

.topbar nav a {
  text-decoration: none;
  color: var(--muted);
  font-size: 0.92rem;
  padding: 0.35rem 0;
}

.topbar nav a:hover { color: var(--text); }

.logout-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

.whoami {
  font-size: 0.85rem;
  color: var(--muted);
}

.hamburger {
  display: none;
  width: 40px;
  height: 40px;
  padding: 0;
  background: transparent;
  border: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
}

.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 2rem 0 0.75rem; }

.login-box {
  max-width: 320px;
  margin: 3rem auto;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

form label {
  display: block;
  margin-bottom: 0.85rem;
  font-size: 0.9rem;
  color: var(--muted);
}

form input, form textarea, form select, form button {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.55rem 0.65rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}

form textarea { min-height: 4.5rem; resize: vertical; }

button, .actions button {
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  font-weight: 600;
}

button.danger { background: var(--danger); color: #fff; }

button:hover { filter: brightness(1.08); }

.error {
  color: var(--danger);
  padding-left: 1rem;
}

.success {
  color: var(--success);
  padding-left: 1rem;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 1rem;
}

.filters label { margin-bottom: 0; min-width: 140px; }
.filters button, .filters a { width: auto; align-self: center; }

.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  min-width: 480px;
  border-collapse: collapse;
  background: var(--surface);
}

th, td {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  overflow-wrap: break-word;
  word-break: break-word;
}

tr.archived { opacity: 0.55; }

.task-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.9rem;
}

.task-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.task-card h3 { margin: 0 0 0.4rem; font-size: 1.02rem; }
.task-card .meta { color: var(--muted); font-size: 0.85rem; margin: 0.3rem 0; }
.task-card .discipline-tag { color: var(--danger); font-size: 0.82rem; margin: 0.2rem 0; }
.task-card .reward-tag { color: var(--success); font-size: 0.82rem; margin: 0.2rem 0; }
.task-card .badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--bg);
  font-size: 0.8rem;
}

.task-card.status-completed { border-color: var(--success); }
.task-card.status-failed { border-color: var(--danger); }

.task-card .actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.task-card .actions button { width: auto; }

.counter-widget { margin-top: 0.75rem; }
.counter-widget form {
  display: inline-flex;
  gap: 0.4rem;
  margin: 0.35rem 0.4rem 0 0;
  width: auto;
}
.counter-widget input { width: 5rem; margin: 0; }
.counter-widget button { width: auto; margin: 0; }
.streak { font-size: 0.82rem; color: var(--muted); }

.progress-bar {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
  margin-top: 0.5rem;
}
.progress-fill { background: var(--accent); height: 100%; }
.progress-label { font-size: 0.78rem; color: var(--muted); margin: 0.25rem 0 0; }

.summary-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  text-align: center;
}
.tile-value { display: block; font-size: 1.4rem; font-weight: 700; }
.tile-label { display: block; font-size: 0.75rem; color: var(--muted); }

.manage-links { color: var(--muted); font-size: 0.9rem; }

@media (max-width: 700px) {
  .hamburger { display: flex; }

  .topbar { flex-direction: column; align-items: stretch; }

  .topbar-row { width: 100%; }

  .nav-panel {
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    width: 100%;
    border-top: 1px solid var(--border);
    padding-top: 0.5rem;
  }

  .nav-panel.open { display: flex; }

  .topbar nav {
    flex-direction: column;
    gap: 0;
  }

  .topbar nav a {
    padding: 0.7rem 0.25rem;
    border-bottom: 1px solid var(--border);
    font-size: 1rem;
  }

  #enable-push-btn {
    margin-top: 0.5rem;
    width: 100%;
  }

  .logout-form {
    margin-left: 0;
    margin-top: 0.75rem;
    justify-content: space-between;
  }
}

/* Comfortable touch targets and readable layout on small screens generally,
   not just inside the nav. */
@media (max-width: 600px) {
  button, .actions button, #enable-push-btn {
    min-height: 44px;
  }

  .task-card .actions {
    flex-direction: column;
  }

  .task-card .actions button { width: 100%; }

  .counter-widget form {
    display: flex;
    width: 100%;
    margin: 0.4rem 0 0;
  }

  .counter-widget input { flex: 1; width: auto; }
  .counter-widget button { flex: 0 0 auto; }

  .filters { flex-direction: column; align-items: stretch; }
  .filters label { min-width: 0; }
  .filters button, .filters a { width: 100%; text-align: center; }

  .summary-tiles { grid-template-columns: repeat(2, 1fr); }

  h1 { font-size: 1.25rem; }

  .login-box { margin: 1.5rem auto; max-width: none; }
}
