:root {
  color-scheme: light dark;
  --bg: #f1f3f1;
  --panel: #f9faf9;
  --text: #101614;
  --muted: #5d6965;
  --head: #0b6b43;
  --line: #bfc9c4;
  --btn: #0b6b43;
  --btn-text: #fff;
  --select: #dceee4;
  --today: #ffe66b;
  --danger: #b33838;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151918;
    --panel: #202523;
    --text: #eef3f0;
    --muted: #aeb9b4;
    --head: #0d6f48;
    --line: #3d4843;
    --btn: #0d6f48;
    --btn-text: #fff;
    --select: #31463a;
    --today: #a88600;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, textarea, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--head);
  background: var(--btn);
  color: var(--btn-text);
  border-radius: 8px;
  padding: 9px 12px;
  min-height: 38px;
}
button:active { transform: translateY(1px); filter: brightness(.92); }
button.danger { border-color: var(--danger); background: var(--danger); }
button.light { background: var(--panel); color: var(--head); }
.screen { min-height: 100dvh; padding: max(14px, env(safe-area-inset-top)) 10px 14px; }
.login { display: grid; place-items: center; min-height: 100dvh; }
.pattern {
  width: min(72vw, 310px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
  touch-action: none;
}
.dot {
  border-radius: 50%;
  border: 2px solid var(--head);
  background: var(--panel);
  box-shadow: inset 0 0 0 10px var(--bg);
}
.dot.on { background: var(--head); }
.top {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: start;
  gap: 8px;
  margin-bottom: 8px;
}
.title {
  display: inline-block;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  padding: 4px 2px;
}
.subtitle { color: var(--muted); font-size: 13px; margin-top: 2px; }
.menu {
  position: absolute;
  z-index: 30;
  min-width: 150px;
  padding: 8px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
}
.menu a {
  display: block;
  color: var(--text);
  text-decoration: none;
  padding: 9px 14px;
}
.menu a:active { background: var(--select); }
.toolbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 10px;
}
.table-wrap {
  border: 1px solid var(--line);
  background: var(--panel);
  overflow: auto;
  max-height: calc(100dvh - 176px);
}
table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
th, td {
  border: 1px solid var(--line);
  padding: 5px 7px;
  height: 31px;
  vertical-align: top;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
th {
  position: sticky;
  top: 0;
  z-index: 4;
  color: #fff;
  background: var(--head);
  font-weight: 600;
}
td:first-child, th:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--panel);
}
th:first-child { z-index: 5; background: var(--head); }
tr.selected td { background: var(--select); }
tr.completed td { color: var(--muted); background: rgba(128,128,128,.16); }
tr.flash td { animation: flash 1s ease-in-out 2; }
@keyframes flash { 0%,100% { background: inherit; } 50% { background: #ffe66b; color: #111; } }
.sum {
  display: flex;
  gap: 16px;
  padding: 8px 3px 0;
  font-weight: 700;
}
.modal-back {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0,0,0,.38);
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal {
  width: min(94vw, 560px);
  max-height: 90dvh;
  overflow: auto;
  background: var(--panel);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 18px 60px rgba(0,0,0,.32);
}
.modal h2 { margin: 0 0 12px; font-size: 19px; }
.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 5px; color: var(--muted); }
.form input, .form textarea, .form select {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  padding: 10px;
  min-width: 0;
}
.form textarea { min-height: 90px; resize: vertical; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.calendar { display: grid; gap: 12px; max-height: calc(100dvh - 120px); overflow: auto; }
.month { background: var(--panel); border: 1px solid var(--line); }
.month h3 { margin: 0; padding: 8px; background: var(--head); color: #fff; }
.days { display: grid; grid-template-columns: repeat(7, 1fr); }
.day { min-height: 64px; padding: 5px; border: 1px solid var(--line); background: var(--panel); }
.day.hit { background: #d9f0df; color: #111; }
.day.today { background: var(--today); color: #111; }
.rmb { color: #c42020; }
.jpy { color: #1f66c2; }
.muted { color: var(--muted); }
@media (max-width: 520px) {
  .toolbar { grid-template-columns: repeat(2, 1fr); }
  .actions { grid-template-columns: 1fr; }
}
