:root {
  --bg: #ffffff;
  --fg: #0f172a;
  --muted: #94a3b8;
  --accent: #2563eb;
  --line: #e5e7eb;
  --cell-bg: #f8fafc;
  --weekend-bg: #e2e8f0;
  --vacation-bg: #e0e7ff;
  --vacation-fg: #4338ca;
  --payday-border: #10b981;
  --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%;
}
.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);
}
.config {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.5rem;
  padding: 0.75rem 1rem 0.5rem 1rem;
  max-width: var(--content-max);
  margin: 0 auto;
}
.config label { display: flex; flex-direction: column; gap: 0.2rem; }
.config span {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.config input {
  font: inherit;
  font-size: 0.95rem;
  padding: 0.45rem 0.6rem;
  border-radius: 0.5rem;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  min-height: 36px;
  -webkit-appearance: none;
  appearance: none;
}
.config input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0 1rem 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); }
.topbar .clear-btn { color: var(--maxed-fg); border-color: var(--maxed-fg); }
@media (hover: hover) {
  .topbar button:hover { background: var(--cell-bg); }
  .topbar .clear-btn:hover { background: rgba(220, 38, 38, 0.06); }
}
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, 80px);
  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, 120px) + 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;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  touch-action: pan-y;
}
@media (hover: hover) {
  .cell:not(.weekend):not(.holiday):hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  }
}
.cell:not(.weekend):active { transform: scale(0.96); box-shadow: none; }
.cell .day { font-weight: 600; line-height: 1.1; }
.cell .bank {
  font-size: 0.6rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  align-self: flex-end;
  line-height: 1;
}
.cell.weekend { background: var(--weekend-bg); cursor: default; }
.cell.holiday { background: #cbd5e1; }
.cell.holiday .day { color: #64748b; }
.cell.holiday .bank { color: #94a3b8; }
.cell.payday { border-color: var(--payday-border); border-width: 2px; padding: calc(0.3rem - 1px); }
.cell.vacation { background: var(--vacation-bg); }
.cell.vacation .day { color: var(--vacation-fg); font-weight: 700; }
.cell .accrual, .cell .spent {
  position: absolute;
  right: 0.25rem;
  font-size: 0.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.cell .accrual { top: 0.2rem; color: var(--payday-border); }
.cell .spent { top: 0.2rem; color: var(--vacation-fg); }
.cell.payday.vacation .spent { top: 0.85rem; }
.cell.impossible { border-color: var(--maxed-fg); border-width: 2px; padding: calc(0.3rem - 1px); }
.cell.impossible .day, .cell.impossible .bank { color: var(--maxed-fg); }
.cell.maxed .day, .cell.maxed .bank { color: var(--maxed-fg); }
.cell.maxed .bank { font-weight: 700; }
.cell.today { outline: 2px solid var(--accent); outline-offset: -1px; }
.cell.today .day { color: var(--accent); font-weight: 700; }
@media (min-width: 600px) {
  .grid { gap: 0.5rem; }
  .cell { padding: 0.5rem; font-size: 1rem; }
  .cell.payday { padding: calc(0.5rem - 1px); }
  .cell .bank { font-size: 0.8rem; }
  .cell .accrual, .cell .spent { font-size: 0.65rem; }
  .cell.payday.vacation .spent { top: 1.1rem; }
}
