:root {
  --bg: #ffffff; --surface: #f7f7f5; --border: #e3e3e0; --text: #1a1a1a;
  --muted: #6b6b6b; --accent: #2f6fed; --danger: #d64545;
}
body.dark {
  --bg: #191919; --surface: #232323; --border: #333; --text: #ececec; --muted: #9a9a9a;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
.muted { color: var(--muted); } .italic { font-style: italic; } .error { color: var(--danger); min-height: 1em; }
button { cursor: pointer; border: 1px solid var(--border); background: var(--text); color: var(--bg); border-radius: 6px; padding: 8px 14px; font-size: 14px; }
button.secondary { background: var(--surface); color: var(--text); }
button.small { padding: 4px 10px; }
button.ghost { background: transparent; color: inherit; border: none; }
button.danger { background: var(--danger); color: #fff; border: none; }
input { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); margin: 4px 0; }
a { cursor: pointer; display: block; padding: 4px 0; color: var(--text); text-decoration: none; }
a:hover { background: var(--surface); }

.auth-wrap { display: flex; justify-content: center; align-items: center; min-height: 100vh; padding: 16px; }
.auth-card { width: 360px; max-width: 100%; padding: 28px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.auth-card button { width: 100%; margin-top: 8px; }
.auth-card textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; resize: vertical; }
.mnemonic-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 12px; margin: 10px 0; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; list-style-position: inside; font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
.mnemonic-grid li { padding: 4px 2px; }
.check-row { display: flex; gap: 8px; align-items: flex-start; margin: 10px 0; font-size: 14px; cursor: pointer; }
.check-row input { width: auto; margin: 2px 0 0; flex-shrink: 0; }
.small-note { font-size: 12px; }
.user-code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.hamburger { display: none; background: transparent; border: none; color: var(--text); font-size: 20px; padding: 6px 8px; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 8; }

.topbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 18px; border-bottom: 1px solid var(--border); }
.tabs button { background: var(--surface); color: var(--muted); border: none; border-radius: 10px 10px 0 0; padding: 10px 26px; margin-right: 4px; font-size: 15px; }
.tabs button.active { background: #2b2b2b; color: #fff; }
.topbar-right { display: flex; gap: 10px; align-items: center; }
#themeToggle { background: transparent; border: none; font-size: 18px; padding: 2px; }

.layout { display: flex; min-height: calc(100vh - 57px); }
.sidebar { width: 240px; padding: 18px; border-right: 1px solid var(--border); flex-shrink: 0; }
.sidebar h4 { margin: 18px 0 8px; font-size: 13px; }
.quick { width: 100%; text-align: left; background: var(--surface); color: var(--text); margin: 4px 0; }
.nb-item { padding: 6px 8px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; }
.nb-item.active { background: var(--surface); font-weight: 600; }
.nb-item .share { border: none; background: transparent; color: var(--muted); padding: 0 4px; }

.main { flex: 1; padding: 24px 32px; max-width: 1100px; }
.main h1 { margin: 0 0 4px; }
.main h3 { margin: 26px 0 10px; font-size: 15px; }
.badge { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1px 8px; font-size: 12px; color: var(--muted); }
.cards { display: flex; gap: 12px; flex-wrap: wrap; }
.card { border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; min-width: 180px; background: var(--bg); cursor: pointer; }
.card:hover { background: var(--surface); }
.card .sub { color: var(--muted); font-size: 12px; margin-top: 6px; }
.note-row { display: flex; justify-content: space-between; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.note-row:hover { background: var(--surface); }
.note-row .tags { color: var(--muted); font-size: 12px; }
.task-group h4 { margin: 14px 0 6px; }
.task-item { display: flex; gap: 8px; align-items: center; padding: 6px 10px; }
.task-item input[type=checkbox] { width: auto; }
.task-item.done span { text-decoration: line-through; color: var(--muted); }
.subtask { margin-left: 30px; font-size: 13px; color: var(--muted); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; justify-content: center; align-items: flex-start; padding-top: 6vh; z-index: 10; }
.modal-card { background: var(--bg); color: var(--text); width: min(680px, 92vw); border-radius: 12px; padding: 24px 28px; max-height: 86vh; overflow-y: auto; }
.modal-card.dark { background: #202020; color: #ececec; }
.modal-card.dark input { background: #2a2a2a; color: #ececec; border-color: #3a3a3a; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-icon { font-size: 28px; }
.note-title { font-size: 30px; font-weight: 700; border: none; background: transparent; padding: 8px 0; }
.props div { display: flex; gap: 16px; align-items: center; margin: 6px 0; }
.props span:first-child { width: 130px; color: var(--muted); }
.props input { flex: 1; }
.bullets { list-style: disc; padding-left: 22px; }
.bullets input { border: none; background: transparent; padding: 2px 0; }
.comment { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.comment-add { display: flex; gap: 8px; } .comment-add input { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.random-code { font-family: ui-monospace, Menlo, monospace; font-size: 20px; letter-spacing: 2px; text-align: center; padding: 12px; margin: 10px 0; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; word-break: break-all; }

/* ---------- responsive / mobile ---------- */
html, body { overflow-x: hidden; }
img { max-width: 100%; }

@media (max-width: 768px) {
  .hamburger { display: block; }
  .topbar { padding: 6px 10px; gap: 6px; }
  .tabs { display: flex; overflow-x: auto; flex: 1; min-width: 0; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: 0 0 auto; padding: 10px 16px; min-height: 40px; }
  .topbar-right { gap: 6px; flex-shrink: 0; }
  #presence, #copyCodeBtn { display: none; }
  .user-code { font-size: 12px; }
  .layout { display: block; min-height: auto; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 9;
    width: min(280px, 82vw); background: var(--bg);
    transform: translateX(-100%); transition: transform .22s ease;
    overflow-y: auto; box-shadow: 2px 0 16px rgba(0,0,0,.25);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar a, .sidebar .quick, .nb-item { min-height: 40px; display: flex; align-items: center; }
  .main { padding: 16px; max-width: 100%; }
  .cards { flex-direction: column; }
  .card { min-width: 0; width: 100%; }
  .note-row { min-height: 44px; align-items: center; }
  .task-item { min-height: 40px; }
  .task-item input[type=checkbox] { width: 20px; height: 20px; }
  button { min-height: 40px; }
  button.small { min-height: 36px; }
  input, textarea { font-size: 16px; /* prevents iOS auto-zoom */ }
  .modal { padding-top: 0; align-items: stretch; }
  .modal-card {
    width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh;
    border-radius: 0; padding: 18px 16px;
  }
  .props div { flex-direction: column; align-items: stretch; gap: 4px; }
  .props span:first-child { width: auto; }
  .note-title { font-size: 24px; }
  .comment-add { flex-wrap: wrap; }
  .comment-add button { flex: 1; }
  .auth-card { padding: 20px 16px; }
}

@media (max-width: 480px) {
  .mnemonic-grid { grid-template-columns: repeat(2, 1fr); font-size: 13px; }
  .random-code { font-size: 16px; letter-spacing: 1px; }
  .topbar-right .user-code { display: none; }
  .tabs button { padding: 10px 12px; font-size: 14px; }
  .main h1 { font-size: 24px; }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions button { flex: 1; }
}
