:root {
  --bg: #0f1115;
  --card: #171a21;
  --card-hover: #1c2029;
  --border: #262b36;
  --text: #e6e8ee;
  --muted: #8a91a0;
  --accent: #6c8cff;
  --accent-soft: rgba(108, 140, 255, 0.15);
  --danger: #ff6b6b;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 1100px;
  margin: 0 auto;
}

.clock { flex: 1; }
.clock-time { font-size: 28px; font-weight: 700; letter-spacing: 1px; }
.clock-date { font-size: 13px; color: var(--muted); }

.weather { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.weather-temp { font-size: 18px; font-weight: 600; color: var(--text); }

.icon-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--card-hover); }

.sync-status {
  max-width: 1100px;
  margin: 6px auto 0;
  font-size: 12px;
  color: var(--muted);
  min-height: 0;
}
.version {
  max-width: 1100px;
  margin: 2px auto 0;
  font-size: 11px;
  color: var(--muted);
  opacity: 0.6;
  text-align: right;
}
.sync-status.ok { color: #4ade80; }
.sync-status.err { color: var(--danger); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-height: 160px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-head h2 { font-size: 15px; font-weight: 600; color: var(--muted); letter-spacing: 0.5px; }

.mini-btn {
  background: var(--accent-soft);
  color: var(--accent);
  border: none;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}

.ai-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 10px;
}
.ai-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  transition: all 0.15s;
  position: relative;
}
.ai-item:hover { border-color: var(--accent); transform: translateY(-2px); }
.ai-item .favicon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  background: var(--accent-soft);
}
.ai-item .name { font-size: 12px; }
.ai-item .del {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 12px;
  color: var(--muted);
  opacity: 0;
  cursor: pointer;
  background: none;
  border: none;
}
.ai-item:hover .del { opacity: 1; }

.site-list { display: flex; flex-direction: column; gap: 8px; }
.site-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  position: relative;
}
.site-item:hover { border-color: var(--accent); }
.site-item .favicon { width: 22px; height: 22px; border-radius: 5px; }
.site-item .name { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-item .del { opacity: 0; color: var(--muted); background: none; border: none; cursor: pointer; font-size: 14px; }
.site-item:hover .del { opacity: 1; }

.todo-list { list-style: none; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.todo-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 10px;
  font-size: 14px;
}
.todo-item input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
.todo-item .text { flex: 1; }
.todo-item.done .text { text-decoration: line-through; color: var(--muted); }
.todo-item .del { color: var(--muted); background: none; border: none; cursor: pointer; opacity: 0; }
.todo-item:hover .del { opacity: 1; }

.todo-input-row { margin-top: 10px; }
.todo-input-row input {
  width: 100%;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.todo-input-row input:focus { border-color: var(--accent); }

.note-list { display: flex; flex-direction: column; gap: 8px; }
.note-item {
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  position: relative;
}
.note-item .note-text { font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.note-item .note-time { font-size: 11px; color: var(--muted); margin-top: 6px; }
.note-item .del { position: absolute; top: 8px; right: 10px; color: var(--muted); background: none; border: none; cursor: pointer; opacity: 0; }
.note-item:hover .del { opacity: 1; }

.modal[hidden] { display: none; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 440px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-box h3 { font-size: 16px; margin-bottom: 16px; }
.modal-field { margin-bottom: 14px; }
.modal-field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.modal-field input, .modal-field textarea {
  width: 100%;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.modal-field input:focus, .modal-field textarea:focus { border-color: var(--accent); }
.modal-field textarea { resize: vertical; min-height: 80px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.btn {
  padding: 9px 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }

@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; gap: 12px; padding: 12px; }
  .clock-time { font-size: 24px; }
}
