/* ─── Reset & Variables ──────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-hover: #1c2129;
  --border: #30363d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --green: #3fb950;
  --red: #f85149;
  --red-hover: #ff7b72;
  --radius: 8px;
  --ease: 150ms ease;
}

/* ─── Base ───────────────────────────────────── */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Cascadia Code', ui-monospace, monospace;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── App Shell ──────────────────────────────── */
#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 1rem;
  padding-bottom: env(safe-area-inset-bottom, 2rem);
}

header {
  padding: 1.5rem 0 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
}

header h1 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.08em;
}

header h1 .prompt {
  color: var(--accent);
  margin-right: 0.25em;
}

/* ─── Add Form (shared) ─────────────────────── */
.add-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.add-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
  padding: 0.75rem 1rem;
  min-height: 48px;
  outline: none;
  transition: border-color var(--ease);
}

.add-input:focus {
  border-color: var(--accent);
}

.add-input::placeholder {
  color: var(--text-dim);
  opacity: 0.6;
}

.add-btn {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 1.25rem;
  font-weight: 700;
  min-width: 48px;
  min-height: 48px;
  cursor: pointer;
  transition: background var(--ease);
  display: flex;
  align-items: center;
  justify-content: center;
}

.add-btn:hover { background: var(--accent-hover); }
.add-btn:active { transform: scale(0.95); }

/* ─── List Cards ─────────────────────────────── */
.list-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0.875rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  transition: border-color var(--ease), background var(--ease);
}

.list-card:hover {
  border-color: var(--text-dim);
}

.list-link {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  min-height: 36px;
  overflow: hidden;
}

.list-link .name {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-link .count {
  font-size: 0.75rem;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

.list-link .count .done-count {
  color: var(--green);
}

/* ─── Drag Handle ────────────────────────────── */
.drag-handle {
  color: var(--text-dim);
  opacity: 0.4;
  cursor: grab;
  font-size: 0.875rem;
  padding: 0.25rem;
  user-select: none;
  touch-action: none;
  transition: opacity var(--ease);
  letter-spacing: -0.05em;
}

.drag-handle:hover,
.drag-handle:active {
  opacity: 0.8;
}

/* ─── Icon Buttons ───────────────────────────── */
.icon-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  padding: 0.375rem;
  border-radius: 4px;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--ease), background var(--ease);
  opacity: 0.5;
}

.icon-btn:hover {
  opacity: 1;
  color: var(--red);
  background: rgba(248, 81, 73, 0.1);
}

/* ─── Todos View Header ─────────────────────── */
.todos-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.back-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  padding: 0.375rem 0.625rem;
  min-width: 40px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--ease), color var(--ease);
  flex-shrink: 0;
}

.back-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.list-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  min-width: 0;
  outline: none;
  border-bottom: 1px solid transparent;
  padding: 0.25rem 0;
  transition: border-color var(--ease);
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-title:focus {
  border-bottom-color: var(--accent);
}

.list-title:hover {
  border-bottom-color: var(--border);
}

/* ─── Todo Items ─────────────────────────────── */
.todo-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.625rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.375rem;
  transition: opacity var(--ease), background var(--ease);
}

.todo-item.done {
  opacity: 0.45;
}

.todo-item.done .todo-text {
  text-decoration: line-through;
}

/* Checkbox */
.todo-check {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  min-width: 20px;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  margin-top: 2px;
  transition: all var(--ease);
  position: relative;
}

.todo-check:checked {
  background: var(--green);
  border-color: var(--green);
}

.todo-check:checked::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--bg);
  font-size: 0.75rem;
  font-weight: 700;
}

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

/* Todo text */
.todo-text {
  flex: 1;
  font-size: 0.875rem;
  line-height: 1.5;
  min-width: 0;
  padding: 1px 0;
  outline: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--ease);
  word-break: break-word;
}

.todo-text:focus {
  border-bottom-color: var(--accent);
}

/* ─── Completed Section ──────────────────────── */
.completed-divider {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0 0.5rem;
  margin-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.completed-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: lowercase;
  letter-spacing: 0.05em;
}

.clear-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: color var(--ease), background var(--ease);
}

.clear-btn:hover {
  color: var(--red);
  background: rgba(248, 81, 73, 0.1);
}

/* ─── Empty State ────────────────────────────── */
.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-dim);
  font-size: 0.875rem;
  opacity: 0.6;
}

/* ─── SortableJS ─────────────────────────────── */
.ghost {
  opacity: 0.3;
}

.sortable-drag {
  opacity: 0.9;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* ─── Transitions ────────────────────────────── */
.htmx-swapping {
  opacity: 0;
  transition: opacity 100ms ease;
}

.htmx-settling {
  opacity: 1;
  transition: opacity 150ms ease;
}

/* ─── View Transitions ───────────────────────── */
#main {
  view-transition-name: main;
}

::view-transition-old(main) {
  animation: 120ms ease both fade-out;
}

::view-transition-new(main) {
  animation: 120ms ease both fade-in;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@keyframes fade-out {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateY(-4px); }
}

/* ─── Responsive ─────────────────────────────── */
@media (max-width: 480px) {
  #app { padding: 0 0.75rem; }
  header { padding: 1.25rem 0 1rem; }
  .list-card { padding: 0.625rem 0.75rem; }
  .todo-item { padding: 0.5rem 0.625rem; }
}

/* ─── Scrollbar ──────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* Selection */
::selection {
  background: rgba(88, 166, 255, 0.3);
}
