:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eceff3;
  --text: #171a1f;
  --muted: #5d6673;
  --line: #dde1e7;
  --accent: #1f8a5c;
  --accent-text: #ffffff;
  --accent-soft: #dff3e9;
  --rep: #b8651a;
  --rep-soft: #fbeedd;
  --warn: #c8443b;
  --warn-bg: #fdeceb;
  --radius: 14px;
  --gutter: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171c; --surface: #1d2128; --surface-2: #272c35; --text: #eef0f3; --muted: #9aa3b0;
    --line: #333945; --accent: #4cc790; --accent-text: #06170e; --accent-soft: #1b3328;
    --rep: #f0a65a; --rep-soft: #3a2c1c; --warn: #ff8a80; --warn-bg: #3a2220;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; background: var(--bg); color: var(--text); }
body { font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body.noscroll { overflow: hidden; }
main { max-width: 900px; margin: 0 auto; height: 100%; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; padding: calc(12px + env(safe-area-inset-top)) var(--gutter) calc(24px + env(safe-area-inset-bottom)); }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 20px 0 8px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); font-size: .9rem; }
.hint { text-align: center; margin: 8px 0 0; font-size: .8rem; }
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 600;
}
.btn.small { min-height: 40px; padding: 0 14px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.block { display: flex; width: 100%; }
.btn.danger { color: var(--warn); }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid transparent; background: transparent;
  font-size: 1.5rem; line-height: 1; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); }
.row { display: flex; gap: 6px; align-items: center; }
.row.wrap { flex-wrap: wrap; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.notice { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.field select, .field input, .field textarea {
  width: 100%; min-height: 46px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
}
.field textarea { padding: 10px 12px; resize: vertical; line-height: 1.4; }

/* calendar */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.top h1 { white-space: nowrap; }
.year { color: var(--muted); font-weight: 500; }
.grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-template-rows: auto repeat(var(--weeks, 6), minmax(84px, 1fr)); gap: 4px; touch-action: pan-y; flex: 1; }
.dow { text-align: center; font-size: .75rem; font-weight: 600; color: var(--muted); padding: 4px 0; }
.cell {
  min-height: 0; padding: 4px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; align-items: stretch; gap: 2px; text-align: left; overflow: hidden;
}
.cell.blank { border: 0; background: transparent; }
.cell:not(.blank):hover { border-color: var(--accent); }
.cell .num { font-size: .85rem; font-weight: 600; align-self: flex-start; min-width: 24px; height: 24px; line-height: 24px; text-align: center; border-radius: 12px; }
.cell.today { border-color: var(--accent); }
.cell.today .num { background: var(--accent); color: var(--accent-text); }
.notes { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 2px; }
.chip {
  flex: 1 1 0; min-height: 0; overflow: hidden; padding: 2px 5px; border-radius: 5px; background: var(--accent-soft); color: var(--accent);
  font-size: .72rem; line-height: 1.25; font-weight: 600; overflow-wrap: anywhere;
}
.chip .t { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; line-clamp: 1; overflow: hidden; }
.chip.rep { background: var(--rep-soft); color: var(--rep); }
.more { font-size: .68rem; color: var(--muted); padding-left: 2px; }
@media (max-width: 520px) {
  .top { flex-direction: column; align-items: stretch; }
  .top .row { justify-content: space-between; }
}
@media (max-width: 480px) {
  .cell { padding: 3px; }
  .grid { grid-template-rows: auto repeat(var(--weeks, 6), minmax(68px, 1fr)); }
  .chip { font-size: .64rem; padding: 1px 3px; }
}

/* modal: a bottom sheet on phones, a centred card on wide screens */
.modal { position: fixed; inset: 0; background: rgba(10, 12, 16, .5); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.modal[hidden], .dialog[hidden], .toast[hidden] { display: none; }
.modal-card {
  background: var(--bg); width: 100%; max-width: 520px; max-height: 92vh; max-height: 92dvh; display: flex; flex-direction: column;
  border-radius: 20px 20px 0 0; outline: none; box-shadow: 0 -8px 30px rgba(0, 0, 0, .25);
}
@media (min-width: 600px) { .modal { align-items: center; } .modal-card { border-radius: 20px; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 8px 4px var(--gutter); }
.modal-head h1 { font-size: 1.1rem; }
.modal-body { padding: 8px var(--gutter) 12px; overflow-y: auto; }
.modal-foot { display: flex; gap: 10px; padding: 10px var(--gutter) calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.note {
  display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; margin-bottom: 8px;
}
.note-text { display: block; white-space: pre-wrap; overflow-wrap: anywhere; }
.tag { display: inline-block; margin-top: 6px; font-size: .78rem; font-weight: 600; color: var(--rep); background: var(--rep-soft); padding: 2px 8px; border-radius: 999px; }

/* dialog and toast */
.dialog { position: fixed; inset: 0; background: rgba(10, 12, 16, .55); display: flex; align-items: center; justify-content: center; padding: var(--gutter); z-index: 20; }
.dialog-card { background: var(--surface); border-radius: var(--radius); padding: 18px; max-width: 420px; width: 100%; }
.dialog-card h2 { margin-top: 0; }
.dialog-btns { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.dialog-error { color: var(--warn); }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; max-width: 90vw;
}
@media (prefers-reduced-motion: no-preference) { .modal-card { animation: rise .18s ease-out; } @keyframes rise { from { transform: translateY(24px); opacity: .6; } } }
