:root {
  --bg: #ffffff;
  --fg: #0f172a;
  --muted: #94a3b8;
  --accent: #2563eb;
  --line: #e5e7eb;
  --cell-bg: #f8fafc;
  --weekend-bg: #e2e8f0;
  --count-fg: #2563eb;
  --maxed-fg: #dc2626;
  --content-max: 800px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}
.lock {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.lock.hidden { display: none; }
.lock-form { width: 100%; max-width: 280px; }
.lock-form input {
  font: inherit;
  font-size: 1rem;
  width: 100%;
  padding: 0.6rem 0.8rem;
  border-radius: 0.5rem;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  -webkit-appearance: none;
  appearance: none;
  text-align: center;
}
.lock-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.lock-form input.shake { animation: shake 0.3s; border-color: var(--maxed-fg); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.page-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0);
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  max-width: var(--content-max);
  margin: 0 auto;
}
.topbar button {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0 0.85rem;
  height: 2.25rem;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.topbar button:active { transform: scale(0.96); background: var(--cell-bg); }
@media (hover: hover) {
  .topbar button:hover { background: var(--cell-bg); }
}
main {
  padding: 0.75rem;
  max-width: var(--content-max);
  margin: 0 auto;
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
}
.dow {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.25rem;
  padding: 0.5rem 0;
  position: sticky;
  top: var(--header-h, 60px);
  z-index: 1;
  background: var(--bg);
}
.dow > div {
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 600;
}
.months { display: block; }
.month { scroll-margin-top: calc(var(--total-header-h, 100px) + 12px); }
.month + .month { margin-top: 0.75rem; }
.month-name {
  margin: 1.25rem 0 0.5rem 0;
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  color: var(--fg);
  letter-spacing: -0.01em;
}
.month:first-child .month-name { margin-top: 0.25rem; }
.grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.25rem;
}
.cell {
  aspect-ratio: 1;
  background: var(--cell-bg);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0.3rem;
  font-size: 0.85rem;
  color: var(--fg);
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  touch-action: pan-y;
}
.cell .day {
  font-size: 0.65rem;
  font-weight: 600;
  line-height: 1;
  color: var(--muted);
  position: relative;
  z-index: 1;
}
.cell .count {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--count-fg);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cell.weekend { background: var(--weekend-bg); }
.cell.past { background: #eef2f7; cursor: default; }
.cell.past .day, .cell.past .count { color: #cbd5e1; }
.cell.today { outline: 2px solid var(--accent); outline-offset: -1px; }
.cell.today .day { color: var(--accent); }
@media (min-width: 600px) {
  .grid { gap: 0.5rem; }
  .cell { padding: 0.5rem; font-size: 1rem; }
  .cell .day { font-size: 0.75rem; }
  .cell .count { font-size: 1.75rem; }
}
