:root {
  --bg: #1F2023; --raised: #2A2B2F; --line: #3A3B40; --text: #E8E6E1; --muted: #8E8D89;
  --blue: #4BA3E3; --green: #8FD694; --yellow: #F5C66B; --red: #FF6B6B; --magenta: #D78BE5; --cyan: #5FD3D9;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --paper: #F4EFE3; --paper-2: #ECE5D3; --ink: #2A2B2F; --ink-soft: #66635C; --rule: #d9d0bb; --accent: #C8453F;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--mono); overflow: hidden; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.wall { height: 100%; padding: 10px 12px 12px; background: radial-gradient(90% 70% at 50% 20%, #2a2b2f, #1F2023 70%); display: flex; }
.calendar { flex: 1; min-width: 0; display: flex; flex-direction: column; filter: drop-shadow(0 6px 10px rgba(0,0,0,.5)); }
.binding {
  position: relative; height: 22px; flex: none; display: flex; justify-content: space-around; align-items: flex-end; padding: 0 28px;
  background: linear-gradient(180deg, transparent 10px, var(--accent) 10px); border-radius: 4px 4px 0 0;
}
.binding i { width: 6px; height: 20px; border-radius: 3px; background: linear-gradient(90deg, #8a8b90, #e4e5e8 45%, #77787d); transform: translateY(-4px); box-shadow: 0 1px 1px rgba(0,0,0,.5); }
.binding::after { /* perforation where pages tear off */
  content: ""; position: absolute; left: 0; right: 0; bottom: -3px; height: 3px;
  background: radial-gradient(circle at 3px 1.5px, var(--bg) 1.1px, transparent 1.5px) 0 0 / 7px 3px repeat-x;
}
.page {
  flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.08fr) minmax(0, 1fr);
  background: var(--paper); color: var(--ink); border-radius: 0 0 4px 4px;
}

/* ---- month --------------------------------------------------------- */
.month { display: flex; flex-direction: column; padding: 10px 12px 12px 14px; border-right: 1px dashed var(--rule); min-height: 0; }
.month-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 6px; }
.month-head h2 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); text-align: center; flex: 1; }
.nav { width: 28px; height: 26px; border: 1px solid var(--rule); background: var(--paper-2); border-radius: 4px; cursor: pointer; font-size: 17px; line-height: 1; color: var(--ink); }
.nav:hover { background: #e3dbc6; }
.grid { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-template-rows: auto repeat(6, minmax(0, 1fr)); gap: 2px; }
.wd { font-size: 10px; text-align: center; color: var(--ink-soft); text-transform: uppercase; align-self: end; padding-bottom: 3px; }
.day {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 2px;
  border-top: 1px solid var(--rule); padding-top: 3px; font-size: 12px; color: var(--ink); min-height: 0; background: none; border-left: 0; border-right: 0; border-bottom: 0; border-radius: 0;
}
.day.out { color: #b4ad9c; }
button.day { cursor: pointer; }
button.day:hover { background: rgba(200,69,63,.08); }
.day.today .num { background: var(--ink); color: var(--paper); border-radius: 50%; }
.day .num { width: 20px; height: 20px; line-height: 20px; text-align: center; font-variant-numeric: tabular-nums; }
.dots { display: flex; gap: 2px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.dots i.past { background: #8a8478; }
.day.picked { background: rgba(200,69,63,.14); }
.day.picked .num { font-weight: 700; }
.wd.first { grid-column-start: 1; }

/* ---- side panel --------------------------------------------------- */
.side { display: flex; flex-direction: column; min-height: 0; padding: 10px 12px 10px; position: relative; }
.switch { display: flex; gap: 0; flex: none; border: 1px solid var(--rule); border-radius: 5px; overflow: hidden; align-self: flex-start; }
.switch button { border: 0; background: var(--paper-2); padding: 4px 12px; font-size: 12px; cursor: pointer; color: var(--ink-soft); }
.switch button + button { border-left: 1px solid var(--rule); }
.switch button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.switch button:focus-visible { outline-offset: -3px; }
.switch .n { opacity: .7; margin-left: 4px; }
.filter-note { margin-top: 6px; font-size: 11.5px; color: var(--ink-soft); display: flex; align-items: center; gap: 6px; }
.filter-note[hidden] { display: none; }
.filter-note button { border: 0; background: none; padding: 0 2px; color: var(--accent); cursor: pointer; text-decoration: underline; font-size: 11.5px; }

.list { list-style: none; margin: 8px 0 0; padding: 0 2px 0 0; overflow-y: auto; flex: 1; min-height: 0; scrollbar-width: thin; }
.list[hidden], .detail[hidden] { display: none; }
.item { display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--rule); padding: 7px 4px; cursor: pointer; color: var(--ink); border-radius: 3px; }
.item:hover { background: rgba(42,43,47,.05); }
.item:focus-visible { outline-offset: -2px; }
.leaf { flex: none; width: 40px; text-align: center; border: 1px solid var(--rule); border-radius: 3px; background: #fff9ee; overflow: hidden; }
.leaf .m { display: block; background: var(--accent); color: #fff; font-size: 9.5px; letter-spacing: .06em; text-transform: uppercase; padding: 1px 0; }
.leaf .d { display: block; font-size: 15px; font-weight: 700; line-height: 22px; }
.leaf.past .m { background: #8d887d; }
.leaf.none .d { font-size: 12px; color: var(--ink-soft); }
.item .t { min-width: 0; }
.item .name { display: block; font-family: var(--sans); font-size: 13px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.item .sub { display: block; font-size: 11px; color: var(--ink-soft); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { display: inline-block; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); border: 1px solid currentColor; border-radius: 3px; padding: 0 4px; margin-left: 4px; vertical-align: 1px; font-family: var(--mono); font-weight: 400; }
.empty { font-size: 12.5px; color: var(--ink-soft); padding: 12px 4px; line-height: 1.5; font-family: var(--sans); }

.detail { flex: 1; min-height: 0; overflow-y: auto; margin-top: 8px; padding-right: 4px; scrollbar-width: thin; }
.detail:focus { outline: none; }
.back { border: 0; background: none; padding: 2px 0; font-size: 12px; color: var(--accent); cursor: pointer; }
.detail h3 { margin: 6px 0 8px; font-family: var(--sans); font-size: 17px; line-height: 1.25; overflow-wrap: anywhere; }
.facts { margin: 0 0 10px; display: grid; grid-template-columns: max-content 1fr; gap: 4px 10px; font-size: 12px; line-height: 1.45; }
.facts dt { color: var(--ink-soft); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.desc { font-family: var(--sans); font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; border-top: 1px dashed var(--rule); padding-top: 8px; }

.loading { font-size: 12px; color: var(--ink-soft); padding: 12px 4px; }

@media (max-width: 520px) {
  .page { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .month { border-right: 0; border-bottom: 1px dashed var(--rule); padding: 8px 10px 8px; }
  .grid { grid-template-rows: auto repeat(6, 24px); }
  .day { padding-top: 1px; flex-direction: row; justify-content: center; gap: 1px; font-size: 11px; }
  .day .num { width: 18px; height: 18px; line-height: 18px; }
  .dots i { width: 4px; height: 4px; }
  .dots { flex-direction: column; }
  .wd { padding-bottom: 1px; }
  .side { padding: 8px 10px; }
  .binding { padding: 0 14px; }
}
@media (max-width: 520px) and (max-height: 420px) { .grid { grid-template-rows: auto repeat(6, 21px); } .month-head { margin-bottom: 2px; } .nav { height: 22px; } }
@media (min-width: 760px) { .day { font-size: 13px; } .item .name { font-size: 14px; } }
