:root {
  color-scheme: dark;
  --bg: #141414;
  --surface: #1b1b1b;
  --text: #e8e6e1;
  --muted: #9a968f;
  --faint: #6f6b65;
  --border: #2b2926;
  --danger: #d08a7a;
  --radius: 6px;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f3ee;
  --surface: #fffefa;
  --text: #24221f;
  --muted: #6c6862;
  --faint: #96918a;
  --border: #dedad2;
  --danger: #a34d3d;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--muted);
  outline-offset: 2px;
}

.app {
  width: min(680px, 100%);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
}

.header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 0 14px;
}

.title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.tools {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.search {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  min-width: 0;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.search:focus-within {
  border-color: var(--muted);
}

.search svg {
  flex: none;
  width: 14px;
  height: 14px;
  fill: none;
  stroke: var(--faint);
  stroke-width: 1.6;
  stroke-linecap: round;
}

.search input {
  width: 140px;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 13px;
}

.search input::placeholder {
  color: var(--faint);
}

.icon-button {
  flex: none;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
}

.icon-button:hover {
  color: var(--text);
  border-color: var(--muted);
}

.icon-button[hidden] {
  display: none;
}

.icon-button svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.moon {
  display: none;
}

html[data-theme="light"] .sun {
  display: none;
}

html[data-theme="light"] .moon {
  display: block;
}

.lists {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  min-height: 38px;
  border-bottom: 1px solid var(--border);
}

.tabs {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: none;
  max-width: 180px;
  margin-bottom: -1px;
  padding: 9px 10px 8px;
  overflow: hidden;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text);
}

.tab[aria-current="true"] {
  color: var(--text);
  border-bottom-color: var(--text);
}

.new-list {
  flex: none;
  padding: 9px 2px 8px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.new-list:hover {
  color: var(--text);
}

.panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-top: 18px;
}

.panel-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
}

.list-title {
  flex: 1;
  min-width: 0;
  padding: 2px 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.list-title:focus {
  box-shadow: 0 1px 0 var(--muted);
}

.list-title::placeholder {
  color: var(--faint);
}

.panel-meta {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
}

.count {
  color: var(--faint);
  font-size: 12px;
  white-space: nowrap;
}

.text-button {
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--faint);
  font-size: 12px;
}

.text-button[hidden] {
  display: none;
}

.list-title[readonly] {
  cursor: default;
}

.text-button:hover {
  color: var(--danger);
}

.notes {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.notes::-webkit-scrollbar {
  width: 8px;
}

.notes::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.note {
  flex: none;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0 -6px;
  padding: 11px 6px;
  border-bottom: 1px solid var(--border);
}

.note:first-child {
  border-top: 1px solid var(--border);
}

.note:last-child {
  border-bottom: 0;
}

.check {
  position: relative;
  flex: none;
  width: 18px;
  height: 18px;
  margin-top: 2px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--faint);
  border-radius: 50%;
  background: transparent;
  color: transparent;
}

.check::after {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
}

.check:hover {
  border-color: var(--text);
}

.check svg {
  width: 11px;
  height: 11px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.note.done .check {
  border-color: var(--text);
  background: var(--text);
  color: var(--bg);
}

.note-copy {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.note-list {
  padding-bottom: 2px;
  color: var(--faint);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.note-title,
.note-detail {
  width: 100%;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
}

.note-title {
  color: var(--text);
  font-size: 14px;
}

.note-detail {
  color: var(--muted);
  font-size: 12px;
}

.note-title:focus-visible,
.note-detail:focus-visible {
  outline: 1px solid var(--muted);
  outline-offset: 2px;
  border-radius: 2px;
}

.note-title::placeholder,
.note-detail::placeholder {
  color: var(--faint);
}

.note.done .note-title {
  color: var(--faint);
  text-decoration: line-through;
}

.note.done .note-detail {
  opacity: 0.6;
}

.note-remove {
  flex: none;
  width: 24px;
  height: 24px;
  margin: -2px -4px 0 0;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  background: none;
  color: var(--faint);
  font-size: 17px;
  line-height: 1;
  opacity: 0;
}

.note:hover .note-remove,
.note:focus-within .note-remove {
  opacity: 1;
}

.note-remove:hover {
  color: var(--danger);
}

.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 40px 20px;
  color: var(--faint);
  font-size: 13px;
  text-align: center;
}

.empty strong {
  color: var(--muted);
  font-weight: 500;
}

.add-form {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
  padding: 14px 0 0;
  border-top: 1px solid var(--border);
}

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

.add-row input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 14px;
}

.add-row input:focus {
  outline: 0;
  border-color: var(--muted);
}

.add-row input::placeholder {
  color: var(--faint);
}

.add-row button {
  flex: none;
  height: 38px;
  padding: 0 16px;
  border: 1px solid var(--text);
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  font-weight: 600;
}

.add-row button:hover {
  opacity: 0.9;
}

.add-detail {
  height: 30px;
  padding: 0 2px;
  border: 0;
  border-bottom: 1px solid var(--border);
  outline: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

.add-detail:focus {
  border-bottom-color: var(--muted);
}

.add-detail::placeholder {
  color: var(--faint);
}

.local-note {
  flex: none;
  margin: 0;
  padding: 0 0 calc(10px + env(safe-area-inset-bottom));
  color: var(--faint);
  font-size: 11px;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100% - 32px);
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 24px #0005;
  color: var(--text);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 0.15s, transform 0.15s;
}

.toast.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

.toast button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font-weight: 600;
  text-decoration: underline;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (hover: none) {
  .note-remove {
    opacity: 1;
  }
}

@media (max-width: 560px) {
  .app {
    padding: 0 14px;
  }

  .header {
    padding: 16px 0 12px;
  }

  .search {
    flex: 1;
    max-width: 180px;
  }

  .search input {
    width: 100%;
  }

  .search input,
  .note-title,
  .note-detail,
  .add-row input,
  .add-detail {
    font-size: 16px;
  }

  .tab {
    max-width: 140px;
  }

  .list-title {
    font-size: 17px;
  }

  .note-remove {
    opacity: 1;
  }
}

@media (max-width: 400px) {
  .title {
    font-size: 16px;
  }

  .panel-meta .count {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
