:root {
  color-scheme: light dark;
  --bg: #f4f4f5;
  --card: #fff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --border: #e2e2e5;
  --accent: #2563eb;
  --danger: #dc2626;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181c;
    --card: #24262b;
    --text: #eee;
    --muted: #9ca3af;
    --border: #34363c;
  }
}

* { box-sizing: border-box; }

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

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  font-size: 1.1rem;
  margin: 0;
}

.list-switcher {
  font-size: 1.05rem;
  font-weight: 600;
  border: none;
  background: none;
  color: var(--text);
  max-width: 55%;
  min-height: 44px;
  padding: 0 4px;
}

#logoutBtn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.9rem;
  min-height: 44px;
  padding: 0 8px;
  cursor: pointer;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 80px;
}

.add-btn {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-bottom: 20px;
  padding: 12px;
  font-size: 1.05rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.category-group {
  margin-bottom: 20px;
}

.category-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 8px 4px;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 12px;
  background: var(--card);
  border-radius: 10px;
  margin-bottom: 6px;
  border: 1px solid var(--border);
}

.item-row .item-main {
  flex: 1;
  display: flex;
  flex-direction: row;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  min-height: 44px;
}

.item-row.checked .item-main {
  opacity: 0.5;
  text-decoration: line-through;
}

.item-name {
  font-size: 1rem;
}

.item-quantity {
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
}

.creator-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.delete-btn {
  min-width: 44px;
  min-height: 44px;
  background: none;
  border: none;
  color: var(--danger);
  font-size: 1.3rem;
  cursor: pointer;
}

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

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}

.chip:active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.chip-wrap {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding-right: 2px;
}

.chip-wrap .chip {
  border: none;
  padding-right: 6px;
}

.chip-icon-btn {
  min-width: 32px;
  min-height: 32px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.95rem;
  cursor: pointer;
  border-radius: 50%;
}

.chip-icon-btn:active {
  background: var(--border);
}

.chip-delete-btn {
  color: var(--danger);
  font-size: 1.1rem;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

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

.modal-card {
  background: var(--card);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.modal-card h2 {
  font-size: 1.1rem;
  margin: 0 0 20px;
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 24px;
}

.stepper button {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
}

#stepValue {
  font-size: 1.4rem;
  font-weight: 600;
  width: 80px;
  min-height: 44px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  padding: 4px;
}

#stepValue::-webkit-inner-spin-button,
#stepValue::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.unit-select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-actions button {
  flex: 1;
  min-height: 44px;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
}

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

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border) !important;
}

.hidden {
  display: none !important;
}

.browse-card {
  max-width: 480px;
  text-align: left;
  max-height: 85vh;
  overflow-y: auto;
}

.browse-header {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 16px;
}

.browse-header h2 {
  flex: 1;
  margin: 0;
  font-size: 1.05rem;
  text-align: center;
}

.browse-back,
.browse-close {
  min-width: 44px;
  min-height: 44px;
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--text);
  cursor: pointer;
}

.search-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 14px;
}

.browse-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 10px;
}

.category-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 84px;
  padding: 12px 8px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  text-align: center;
}

.category-btn:active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.category-icon {
  font-size: 1.8rem;
}

#newArticleForm {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

#newArticleForm input {
  flex: 1;
  min-height: 44px;
  padding: 10px 12px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}

#newArticleForm button {
  min-width: 44px;
  min-height: 44px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
}
