:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --text: #1b1d1c;
  --muted: #6b7470;
  --accent: #0b7a3b;
  --accent-2: #0e9248;
  --danger: #b3261e;
  --border: #e3e7e5;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.04);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --surface: #1d2226;
    --text: #ecefef;
    --muted: #9aa3a0;
    --accent: #29b466;
    --accent-2: #34c275;
    --border: #2a3035;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  overscroll-behavior-y: none;
}

button, input { font: inherit; color: inherit; }

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--accent);
  color: #fff;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  box-shadow: var(--shadow);
}
.header-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.header h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  flex: 1;
}
.nickname-btn {
  background: rgba(255,255,255,0.18);
  border: 0;
  color: #fff;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 500;
}
.connection {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 4px;
}
.connection .dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #ffd166;
  margin-right: 6px;
  vertical-align: middle;
}
.connection.online .dot { background: #b6f4cc; }
.connection.offline .dot { background: #ff8a80; }

/* Add bar */
.add-bar {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: calc(var(--safe-top) + 60px);
  z-index: 9;
}
.add-bar input {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius);
  padding: 12px 14px;
  outline: none;
}
.add-bar input:focus { border-color: var(--accent); }
.add-bar button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius);
  padding: 0 18px;
  font-weight: 600;
}
.add-bar button:disabled { opacity: 0.5; }

/* List */
.list {
  list-style: none;
  margin: 0;
  padding: 8px 12px calc(var(--safe-bottom) + 80px);
  flex: 1;
}
.item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}
.item.checked {
  opacity: 0.6;
}
.item.checked .text {
  text-decoration: line-through;
  color: var(--muted);
}
.checkbox {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  padding: 0;
}
.item.checked .checkbox {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.checkbox svg { width: 16px; height: 16px; }
.item-body {
  flex: 1;
  min-width: 0;
}
.text {
  display: block;
  word-break: break-word;
}
.meta {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.delete {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 22px;
  padding: 4px 8px;
  border-radius: 8px;
}
.delete:active { background: var(--border); }

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  margin: 16px 4px 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.clear-btn {
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
}

/* Modal / Login screens */
.center-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 6px;
  font-size: 22px;
}
.card p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 14px;
}
.card label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
.card input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
  margin-bottom: 12px;
}
.card input:focus { border-color: var(--accent); }
.card button[type="submit"] {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 12px;
  font-weight: 600;
}
.card .error {
  color: var(--danger);
  font-size: 13px;
  margin: 0 0 12px;
  min-height: 1em;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}
.modal {
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 340px;
  box-shadow: var(--shadow);
}
.modal h2 {
  color: var(--text);
}
.modal label {
  display: block;
  font-size: 13px;
  color: var(--text);
  font-weight: 600;
  margin-bottom: 6px;
}
.modal input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
}
.modal input:focus { border-color: var(--accent); }
.modal .row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.modal .row button {
  flex: 1;
  border-radius: 10px;
  border: 0;
  padding: 12px;
  font-weight: 600;
}
.modal .btn-cancel {
  background: var(--border);
  color: var(--text);
}
.modal .btn-ok {
  background: var(--accent);
  color: #fff;
}
