:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --text: #1c1c1a;
  --muted: #8a8a85;
  --faint: #c9c9c4;
  --line: #ececea;
  --hover: #f2f2f0;
  --hot: #e2541b;
  --hot-bg: #fff6f1;
  --hot-line: #f7dccd;
  --accent: #1c1c1a;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161616;
    --surface: #1d1d1d;
    --text: #ececea;
    --muted: #8d8d88;
    --faint: #4a4a46;
    --line: #262626;
    --hover: #212121;
    --hot: #ff7a3d;
    --hot-bg: #22190f;
    --hot-line: #3a2716;
    --accent: #ececea;
    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

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

:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- Login ---------- */
.login {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-box {
  width: min(320px, 100%);
  display: grid;
  gap: 12px;
}

.login-box h1 {
  margin: 0 0 12px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-align: center;
}

.login-box input {
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 16px;
}

.login-box button {
  height: 48px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
}

.login-error {
  min-height: 1.5em;
  margin: 0;
  font-size: 14px;
  color: var(--hot);
  text-align: center;
}

/* ---------- Layout ---------- */
.app {
  width: min(680px, 100%);
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 96px);
}

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 44px;
}

.title {
  padding: 0;
  border: 0;
  background: none;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--faint);
}

.status[data-state='ok']::before {
  background: #3f9d63;
}

.status[data-state='busy']::before {
  background: var(--muted);
  animation: pulse 1s ease-in-out infinite;
}

.status[data-state='offline']::before,
.status[data-state='error']::before {
  background: var(--hot);
}

@keyframes pulse {
  50% {
    opacity: 0.3;
  }
}

.link {
  margin-left: auto;
  padding: 8px 2px;
  border: 0;
  background: none;
  font-size: 14px;
  color: var(--muted);
}

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

/* ---------- Capture ---------- */
.capture {
  margin: 8px 0 20px;
}

.capture textarea {
  display: block;
  width: 100%;
  min-height: 56px;
  max-height: 40vh;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  font-size: 17px;
  line-height: 1.5;
  resize: none;
  overflow-y: auto;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.capture textarea::placeholder {
  color: var(--muted);
}

.capture textarea:focus {
  outline: none;
  border-color: var(--faint);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

/* ---------- Sections and items ---------- */
.section + .section {
  margin-top: 20px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 6px 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--hot);
}

.flame-mini {
  width: 12px;
  height: 12px;
  background: currentColor;
  -webkit-mask: url('/icons/flame.svg') center / contain no-repeat;
  mask: url('/icons/flame.svg') center / contain no-repeat;
}

.list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.hot .list {
  border: 1px solid var(--hot-line);
  border-radius: var(--radius);
  background: var(--hot-bg);
  overflow: hidden;
}

.item {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 4px;
  min-height: 48px;
  padding: 4px 4px 4px 0;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  transition: background-color 0.12s;
}

.hot .item {
  background: transparent;
  border-bottom-color: var(--hot-line);
}

.hot .item:last-child,
.list .item:last-child {
  border-bottom: 0;
}

.item:hover,
.item.selected {
  background: var(--hover);
}

.hot .item:hover,
.hot .item.selected {
  background: rgba(226, 84, 27, 0.06);
}

.item.dragging {
  z-index: 5;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
  transition: none;
}

.item.leaving {
  opacity: 0;
  transform: translateX(16px);
  transition: opacity 0.2s, transform 0.2s;
}

.handle {
  flex: 0 0 28px;
  align-self: stretch;
  display: grid;
  place-items: center;
  border: 0;
  background: none;
  color: var(--faint);
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.handle svg {
  width: 10px;
  height: 16px;
}

.item:hover .handle {
  color: var(--muted);
}

.check {
  flex: 0 0 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: none;
}

.check span {
  width: 20px;
  height: 20px;
  border: 1.5px solid var(--faint);
  border-radius: 50%;
  transition: border-color 0.15s, background-color 0.15s;
}

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

.item.is-done .check span {
  border-color: var(--text);
  background: var(--text) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5.5 10.5l3 3 6-7' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 14px no-repeat;
}

.text {
  flex: 1;
  min-width: 0;
  padding: 9px 4px;
  font-size: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  cursor: text;
}

.edit {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 8px;
  padding: 4px 0;
}

.edit textarea {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--faint);
  border-radius: 8px;
  background: var(--surface);
  font-size: 16px;
  line-height: 1.45;
  resize: none;
  overflow: hidden;
}

.edit textarea:focus {
  outline: none;
  border-color: var(--muted);
}

.edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
}

.edit-actions button {
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  font-size: 14px;
  color: var(--muted);
}

.edit-actions button:hover {
  background: var(--hover);
  color: var(--text);
}

.edit-actions .danger:hover {
  color: var(--hot);
}

.icon-btn {
  flex: 0 0 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--faint);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.icon-btn:hover {
  color: var(--muted);
}

.flame.on {
  color: var(--hot);
}

.delete {
  opacity: 0;
}

.item:hover .delete,
.item.selected .delete,
.delete:focus-visible {
  opacity: 1;
}

.delete:hover {
  color: var(--hot);
}

@media (hover: none) {
  .delete {
    display: none;
  }
  .handle {
    color: var(--muted);
  }
}

.empty {
  margin: 28px 0;
  text-align: center;
  font-size: 15px;
  color: var(--muted);
}

/* ---------- Archive ---------- */
.archive-title {
  margin: 12px 0 12px 4px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.archive .item {
  padding-left: 4px;
}

.archive .text {
  color: var(--muted);
  cursor: default;
}

.archive .meta {
  align-self: center;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
}

.archive .restore {
  align-self: center;
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  font-size: 14px;
  color: var(--muted);
}

.archive .restore:hover {
  background: var(--hover);
  color: var(--text);
}

.archive-foot {
  margin-top: 40px;
  text-align: center;
}

.archive-foot .link {
  margin: 0;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: calc(100% - 32px);
  padding: 10px 10px 10px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 14.5px;
  transform: translateX(-50%);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  animation: toast-in 0.2s ease-out;
}

.toast button {
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: rgba(127, 127, 127, 0.25);
  color: inherit;
  font-weight: 600;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
}

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