:root {
  --bg: #fff;
  --fg: #000;
  --muted: #666;
  --line: #111;
  --soft: #f4f4f4;
  --tap: 48px;
  --nav-h: 56px;
  --top-h: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
*, *::before, *::after {
  box-sizing: border-box;
  border-radius: 0 !important;
}
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--fg);
  min-height: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
[hidden], .hidden { display: none !important; }
button, input, textarea, label { touch-action: manipulation; font-family: inherit; }
body.app-locked {
  padding: calc(24px + var(--safe-t)) 16px calc(24px + var(--safe-b));
}
body.app-main {
  padding-top: calc(var(--top-h) + var(--safe-t));
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 72px);
}
.app { max-width: 480px; margin: 0 auto; }

.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: calc(var(--top-h) + var(--safe-t));
  padding: var(--safe-t) 12px 0;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 2px solid var(--fg); background: var(--bg); z-index: 50;
}
.topbar h1 {
  margin: 0; font-size: 18px; font-weight: 800; letter-spacing: 0.04em;
}
.topbar-actions { display: flex; gap: 0; }
.tb-btn {
  appearance: none; background: transparent; border: 0;
  min-height: var(--tap); min-width: var(--tap);
  padding: 0 10px; font-size: 13px; font-weight: 600; color: var(--fg); cursor: pointer;
}
.tb-btn:active { background: var(--soft); }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: 1fr 1fr;
  border-top: 2px solid var(--fg); background: var(--bg); z-index: 50;
}
.nav-btn {
  appearance: none; background: transparent; border: 0;
  border-right: 1px solid #ddd;
  font-size: 14px; font-weight: 700; min-height: var(--nav-h);
  cursor: pointer; color: var(--muted);
}
.nav-btn:last-child { border-right: 0; }
.nav-btn.active {
  color: var(--fg); background: var(--soft);
  box-shadow: inset 0 -3px 0 var(--fg);
}

.fab {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-b) + 12px);
  z-index: 40; width: calc(100% - 32px); max-width: 448px;
}
.fab .btn { width: 100%; }

.brand { text-align: center; margin: 40px 0 28px; }
.brand h1 { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: 0.12em; }
.brand p { margin: 10px 0 0; color: var(--muted); font-size: 13px; font-weight: 600; }

.card {
  border: 2px solid var(--fg); background: var(--bg); padding: 16px; margin-bottom: 12px;
}
.card.soft { background: var(--soft); border-color: var(--fg); }

.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: 12px; font-weight: 700; color: var(--muted);
  margin-bottom: 6px; letter-spacing: 0.04em;
}
input[type="password"], input[type="text"], input[type="datetime-local"], textarea {
  width: 100%; background: var(--bg); border: 2px solid var(--fg);
  color: var(--fg); padding: 12px 14px; font-size: 16px; outline: none;
  min-height: var(--tap);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, textarea:focus { background: var(--soft); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 100%; min-height: var(--tap);
  border: 2px solid var(--fg); background: var(--fg); color: var(--bg);
  font-size: 15px; font-weight: 700; cursor: pointer; padding: 0 16px;
}
.btn:active { opacity: 0.85; }
.btn.outline {
  background: var(--bg); color: var(--fg);
}
.btn.soft {
  background: var(--soft); color: var(--fg); border-color: var(--fg);
}
.btn + .btn { margin-top: 10px; }
.row-btns { display: flex; gap: 10px; }
.row-btns .btn { margin-top: 0; flex: 1; }

.err {
  color: var(--fg); font-size: 13px; font-weight: 600; min-height: 18px;
  margin: 0 0 10px; padding: 8px 10px; border: 2px solid var(--fg);
  background: var(--soft);
}
.err:empty { display: none; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.55; margin-top: 12px; font-weight: 500; }

.latest .label { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: 0.08em; }
.latest .time {
  font-size: 36px; font-weight: 800; font-variant-numeric: tabular-nums;
  margin: 4px 0 2px; line-height: 1.1;
}
.latest .sub { font-size: 13px; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.latest .note {
  margin-top: 10px; padding-top: 10px; border-top: 2px solid var(--fg);
  font-size: 14px; font-weight: 500;
}

.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 18px 0 8px; font-size: 12px; font-weight: 700; color: var(--muted);
  letter-spacing: 0.06em;
}
.section-head .n { color: var(--fg); font-variant-numeric: tabular-nums; font-weight: 800; }

.empty {
  border: 2px dashed var(--fg); padding: 28px 16px; text-align: center;
  color: var(--muted); font-size: 13px; line-height: 1.7; font-weight: 600;
  background: var(--soft);
}

.list { display: flex; flex-direction: column; gap: 0; border: 2px solid var(--fg); }
.item {
  padding: 14px; border-bottom: 2px solid var(--fg); cursor: pointer; background: var(--bg);
}
.item:last-child { border-bottom: 0; }
.item:active { background: var(--soft); }
.item-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.item-date { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
.item-rel { font-size: 12px; font-weight: 700; color: var(--muted); }
.item-time { font-size: 13px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; font-weight: 600; }
.item-note {
  margin-top: 6px; font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.item-thumbs {
  display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap;
}
.item-thumbs img {
  width: 48px; height: 48px; object-fit: cover;
  border: 2px solid var(--fg); display: block; background: var(--soft);
}

/* Calendar */
.cal-head {
  display: flex; align-items: center; justify-content: space-between;
  border: 2px solid var(--fg); margin-bottom: 0;
}
.cal-head button {
  appearance: none; background: var(--bg); border: 0; border-right: 2px solid var(--fg);
  min-width: var(--tap); min-height: var(--tap); font-size: 18px; font-weight: 800; cursor: pointer;
}
.cal-head button:last-child { border-right: 0; border-left: 2px solid var(--fg); }
.cal-head .ym {
  flex: 1; text-align: center; font-size: 16px; font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.cal-week {
  display: grid; grid-template-columns: repeat(7, 1fr);
  border-left: 2px solid var(--fg); border-right: 2px solid var(--fg);
  background: var(--soft);
}
.cal-week span {
  text-align: center; font-size: 11px; font-weight: 700; color: var(--muted);
  padding: 8px 0; border-right: 1px solid #ddd;
}
.cal-week span:last-child { border-right: 0; }
.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  border: 2px solid var(--fg); border-top: 0;
}
.cal-cell {
  appearance: none; background: var(--bg); border: 0;
  border-right: 1px solid #ddd; border-bottom: 1px solid #ddd;
  min-height: 52px; padding: 6px 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-variant-numeric: tabular-nums;
}
.cal-cell:nth-child(7n) { border-right: 0; }
.cal-cell .d { font-size: 14px; font-weight: 700; }
.cal-cell.out .d { color: #bbb; }
.cal-cell.today { background: var(--soft); }
.cal-cell.today .d { font-weight: 800; }
.cal-cell.selected { background: var(--fg); color: var(--bg); }
.cal-cell.selected .d { color: var(--bg); }
.cal-cell .dot {
  width: 6px; height: 6px; background: var(--fg);
}
.cal-cell.selected .dot { background: var(--bg); }
.cal-cell.out .dot { background: #bbb; }
.cal-filter-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border: 2px solid var(--fg); border-top: 0;
  font-size: 13px; font-weight: 700; background: var(--soft);
}
.cal-filter-bar button {
  appearance: none; background: var(--bg); border: 2px solid var(--fg);
  padding: 6px 10px; font-size: 12px; font-weight: 700; cursor: pointer;
}

/* Modal / sheet */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0; z-index: 80;
}
.sheet {
  width: 100%; max-width: 480px; background: var(--bg);
  border-top: 2px solid var(--fg); max-height: 90vh; overflow: auto;
  padding: 16px 16px calc(16px + var(--safe-b));
}
.sheet h2 { margin: 0 0 14px; font-size: 18px; font-weight: 800; }
.sheet-actions { margin-top: 8px; }

.img-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.img-chip {
  position: relative; width: 72px; height: 72px; border: 2px solid var(--fg);
  background: var(--soft);
}
.img-chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-chip .rm {
  position: absolute; top: 0; right: 0; width: 24px; height: 24px;
  border: 0; border-left: 2px solid var(--fg); border-bottom: 2px solid var(--fg);
  background: var(--fg); color: var(--bg); font-size: 14px; font-weight: 800;
  cursor: pointer; line-height: 1; padding: 0;
}
.file-btn { position: relative; overflow: hidden; }
.file-btn input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0;
}

.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.92);
  z-index: 100; display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.lightbox img {
  max-width: 100%; max-height: 100%; object-fit: contain;
  border: 2px solid #fff;
}
.lightbox .close {
  position: absolute; top: calc(12px + var(--safe-t)); right: 12px;
  appearance: none; background: #fff; color: #000; border: 2px solid #fff;
  min-width: var(--tap); min-height: var(--tap); font-size: 14px; font-weight: 800;
  cursor: pointer;
}

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 80px);
  transform: translateX(-50%);
  background: var(--fg); color: var(--bg);
  padding: 10px 16px; font-size: 13px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity 0.03s linear; z-index: 90;
  border: 2px solid var(--fg); white-space: nowrap;
}
.toast.show { opacity: 1; }
body.app-locked .toast { bottom: 40px; }

.page { padding: 12px; }
.settings-block {
  margin: 14px 0;
  padding: 12px;
  border: 2px solid var(--fg);
  background: var(--bg);
}
.settings-label {
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}
.settings-block .btn { width: 100%; }
.settings-block .row-btns { margin-top: 10px; }
.settings-block .row-btns .btn { width: auto; }
#api-token-status { margin-top: 8px; }

/* Cloud sync (Pair-style) */
.settings-block { margin-top: 14px; padding-top: 12px; border-top: 2px solid var(--fg); }
.settings-label { font-weight: 800; font-size: 14px; margin-bottom: 6px; }
.sync-status { margin: 0 0 8px; font-size: 14px; }
.sync-code-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px; letter-spacing: 0.04em;
  border: 2px solid var(--fg); padding: 10px 12px; background: var(--soft);
  word-break: break-all; user-select: all; margin-bottom: 8px;
}
.sync-bind-row { display: flex; gap: 8px; align-items: stretch; margin-top: 10px; }
.sync-bind-row input {
  flex: 1; min-height: var(--tap); border: 2px solid var(--fg);
  background: var(--bg); color: var(--fg); font-size: 15px; padding: 8px 10px;
}
.sync-bind-row .btn { flex-shrink: 0; width: auto; min-width: 72px; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.row-btns .btn { flex: 1; min-width: 96px; }
