:root {
  --bg: #f1f3f4;
  --surface: #ffffff;
  --card: #ffffff;
  --border: #dadce0;
  --text: #202124;
  --text-dim: #5f6368;
  --accent: #1a73e8;
  --accent-strong: #1a73e8;
  --accent-text: #ffffff;
  --danger: #d93025;
  --input-bg: #f1f3f4;

  --note-default-bg: #ffffff;   --note-default-border: #e0e0e0;
  --note-red-bg: #fbe1df;       --note-red-border: #f2b8b5;
  --note-orange-bg: #fef0dc;    --note-orange-border: #f7d29c;
  --note-yellow-bg: #fef8d9;    --note-yellow-border: #f5e27a;
  --note-green-bg: #e6f4ea;     --note-green-border: #b6e2c4;
  --note-teal-bg: #e0f7f5;      --note-teal-border: #a8ded4;
  --note-blue-bg: #e3f1fb;      --note-blue-border: #aecdf2;
  --note-purple-bg: #f1e6fb;    --note-purple-border: #d9bdf0;
  --note-pink-bg: #fce8f0;      --note-pink-border: #f3c2dc;
}

:root[data-theme="dark"] {
  --bg: #202124;
  --surface: #202124;
  --card: #2d2e30;
  --border: #5f6368;
  --text: #e8eaed;
  --text-dim: #9aa0a6;
  --accent: #8ab4f8;
  --accent-strong: #4285f4;
  --accent-text: #ffffff;
  --danger: #f28b82;
  --input-bg: #303134;

  --note-default-bg: #2d2e30;   --note-default-border: #5f6368;
  --note-red-bg: #3f2020;       --note-red-border: #6b3232;
  --note-orange-bg: #3f2e14;    --note-orange-border: #6b4e22;
  --note-yellow-bg: #3f3820;    --note-yellow-border: #6b5f2f;
  --note-green-bg: #1f3823;     --note-green-border: #335c3b;
  --note-teal-bg: #16383a;      --note-teal-border: #285e60;
  --note-blue-bg: #16313f;      --note-blue-border: #275069;
  --note-purple-bg: #2c2140;    --note-purple-border: #4a3968;
  --note-pink-bg: #3c2130;      --note-pink-border: #613653;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 15px;
  line-height: 1;
}

/* ---------- Home page ---------- */
.home {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.home-card {
  width: 100%;
  max-width: 460px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
}

.home-card h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

.subtitle {
  color: var(--text-dim);
  margin: 0 0 28px;
  line-height: 1.5;
}

#create-form, #join-form {
  display: flex;
  gap: 10px;
}

input[type="text"] {
  flex: 1;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 15px;
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  background: var(--accent-strong);
  color: var(--accent-text);
}

button.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

button:hover { filter: brightness(1.1); }

.divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--text-dim);
  margin: 22px 0;
  font-size: 13px;
}

.divider::before, .divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--border);
}

.divider span { padding: 0 12px; }

.join-status {
  color: var(--text-dim);
  font-size: 14px;
  margin: 14px 0 0;
}
.join-status[hidden] { display: none; }

.join-results {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.join-results[hidden] { display: none; }

.join-results li button {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 500;
  text-align: left;
}
.join-results li button:hover {
  border-color: var(--accent);
}
.join-results .result-meta {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-dim);
}

.my-boards {
  width: 100%;
  max-width: 460px;
  margin-top: 20px;
}
.my-boards[hidden] { display: none; }
.my-boards h2 {
  font-size: 15px;
  color: var(--text-dim);
  margin: 0 0 10px;
  font-weight: 600;
}
.my-boards ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.my-boards li {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 4px 4px 14px;
}
.my-boards li button.open-board {
  flex: 1;
  background: transparent;
  border: none;
  padding: 8px 0;
  text-align: left;
  font-weight: 500;
  color: var(--text);
}
.my-boards li button.delete-board {
  background: transparent;
  color: var(--text-dim);
  padding: 8px 10px;
  font-size: 13px;
}
.my-boards li button.delete-board:hover {
  color: var(--danger);
}

/* ---------- Board page ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo { font-size: 22px; }

.board-title-input {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 20px;
  font-weight: 500;
  padding: 6px 8px;
  border-radius: 6px;
  min-width: 160px;
}

.board-title-input:hover, .board-title-input:focus {
  background: var(--input-bg);
  outline: none;
}

.presence {
  color: var(--text-dim);
  font-size: 14px;
}

.share-btn {
  background: var(--accent-strong);
}

.board-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 20px 80px;
}

.new-note {
  display: flex;
  gap: 10px;
  margin-bottom: 32px;
  max-width: 560px;
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 18px;
  align-items: start;
}

.empty-state {
  color: var(--text-dim);
  text-align: center;
  margin-top: 60px;
}

.note {
  background: var(--note-default-bg);
  border: 1px solid var(--note-default-border);
  border-radius: 10px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: pointer;
}
.note :is(input, textarea, button) {
  cursor: auto;
}

.note[data-color="red"]    { background: var(--note-red-bg); border-color: var(--note-red-border); }
.note[data-color="orange"] { background: var(--note-orange-bg); border-color: var(--note-orange-border); }
.note[data-color="yellow"] { background: var(--note-yellow-bg); border-color: var(--note-yellow-border); }
.note[data-color="green"]  { background: var(--note-green-bg); border-color: var(--note-green-border); }
.note[data-color="teal"]   { background: var(--note-teal-bg); border-color: var(--note-teal-border); }
.note[data-color="blue"]   { background: var(--note-blue-bg); border-color: var(--note-blue-border); }
.note[data-color="purple"] { background: var(--note-purple-bg); border-color: var(--note-purple-border); }
.note[data-color="pink"]   { background: var(--note-pink-bg); border-color: var(--note-pink-border); }

.note-title {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 19px;
  font-weight: 600;
  font-family: inherit;
  padding: 4px 2px;
  resize: none;
  overflow: hidden;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  line-height: 1.3;
}
.note-title:focus { outline: none; }

.note-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 4px;
}

.note-item {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}
.note-item.dragging {
  opacity: 0.4;
}

.drag-handle {
  flex-shrink: 0;
  width: 16px;
  margin-top: 4px;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1;
  cursor: grab;
  visibility: hidden;
  user-select: none;
  background: transparent;
  border: none;
  padding: 2px 0;
}
.note-item:hover .drag-handle { visibility: visible; }

.note-item input[type="checkbox"] {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  margin-top: 6px;
  accent-color: var(--accent-strong);
}

.note-item .item-text {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 17px;
  padding: 4px 2px;
  resize: none;
  overflow: hidden;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  line-height: 1.45;
}
.note-item .item-text:focus { outline: none; }
.note-item.checked .item-text {
  text-decoration: line-through;
  color: var(--text-dim);
}

.note-item .remove-item-btn {
  background: transparent;
  padding: 2px 6px;
  margin-top: 2px;
  color: var(--text-dim);
  font-size: 13px;
  visibility: hidden;
  flex-shrink: 0;
}
.note-item:hover .remove-item-btn { visibility: visible; }

.add-item-form { display: flex; }
.add-item-input {
  width: 100%;
  background: transparent;
  border: none;
  border-top: 1px dashed transparent;
  color: var(--text-dim);
  font-size: 14px;
  padding: 4px 2px;
}
.add-item-input:focus { outline: none; color: var(--text); }

.completed-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  padding: 6px 2px;
  margin-top: 2px;
  cursor: pointer;
}
.completed-toggle[hidden] { display: none; }

.completed-toggle .chevron {
  display: inline-block;
  transition: transform 0.15s ease;
}
.completed-toggle.expanded .chevron {
  transform: rotate(-180deg);
}

.completed-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.completed-items[hidden] { display: none; }

.note-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.note-footer button {
  background: transparent;
  padding: 4px 6px;
  font-size: 14px;
}

.pin-btn.active { filter: none; opacity: 1; }
.pin-btn { opacity: 0.5; margin-left: auto; }
.pin-btn.active { opacity: 1; }

.color-swatches {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--border);
  cursor: pointer;
  padding: 0;
}

.swatch[data-color="default"] { background: #2d2e30; }
.swatch[data-color="red"]     { background: #5c2b2b; }
.swatch[data-color="orange"]  { background: #5c421d; }
.swatch[data-color="yellow"]  { background: #5c5029; }
.swatch[data-color="green"]   { background: #2b4f32; }
.swatch[data-color="teal"]    { background: #1e4f52; }
.swatch[data-color="blue"]    { background: #1e4459; }
.swatch[data-color="purple"]  { background: #3c2f57; }
.swatch[data-color="pink"]    { background: #542d47; }

.swatch.selected { outline: 2px solid var(--accent); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 26px;
  width: 100%;
  max-width: 440px;
}

.modal h2 { margin-top: 0; }
.modal p { color: var(--text-dim); line-height: 1.5; }

.share-link-row {
  display: flex;
  gap: 8px;
  margin: 16px 0 20px;
}

.share-link-row input {
  flex: 1;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
}

.modal.note-detail {
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 0;
}
.modal.note-detail .note {
  border: none;
  border-radius: 12px;
  padding: 24px;
  cursor: default;
}
.modal.note-detail .note-title {
  font-size: 22px;
}
.modal.note-detail .item-text {
  font-size: 16px;
}
.detail-close-row {
  display: flex;
  justify-content: flex-end;
  padding: 10px 16px;
  border-top: 1px solid rgba(0,0,0,0.08);
}

.delete-board-btn {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}

.danger-btn {
  background: var(--danger);
  color: #fff;
}
