@import url("https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&family=DM+Sans:ital,wght@0,300;0,400;0,500;1,300&display=swap");

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

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
  touch-action: pan-y;
  overscroll-behavior-x: none;
}

:root {
  --bg: #F5F2ED;
  --surface: #FFFFFF;
  --ink: #1A1714;
  --ink-muted: #8A8480;
  --accent: #C8502A;
  --accent-pale: #F5E8E3;
  --border: rgba(26,23,20,0.1);
  --shadow: 0 2px 24px rgba(26,23,20,0.07);
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  padding: 48px 24px 32px;
}

[data-app-root] {
  width: 100%;
  max-width: min(480px, 100%);
}

/* Header */
.page-header {
  width: 100%;
  margin-bottom: 40px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.logo {
  font-family: 'DM Serif Display', serif;
  font-size: 28px;
  letter-spacing: -0.5px;
  color: var(--ink);
}

.logo em {
  font-style: italic;
  color: var(--accent);
}

.count-badge {
  font-size: 13px;
  font-weight: 300;
  color: var(--ink-muted);
  letter-spacing: 0.02em;
}

.utility-footer {
  width: 100%;
  margin: 6px 0 18px;
  display: flex;
  justify-content: flex-start;
}

.utility-link {
  border: none;
  background: transparent;
  color: var(--ink-muted);
  padding: 0;
  font: inherit;
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.utility-feedback {
  margin: -10px 0 20px;
  color: var(--ink-muted);
  font-size: 12px;
}

/* Random Pick Section */
.random-section {
  width: 100%;
  margin-bottom: 32px;
}

.random-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.random-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.spin-btn {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--ink);
  border-radius: 100px;
  padding: 6px 14px 6px 11px;
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  letter-spacing: 0.02em;
}

.spin-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-pale);
}

.spin-btn:active { transform: scale(0.95); }

.spin-btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.spin-btn[disabled]:hover {
  border-color: var(--border);
  color: var(--ink);
  background: transparent;
}

.spin-icon {
  display: inline-block;
  font-size: 15px;
  line-height: 1;
}

.spin-btn.spinning .spin-icon {
  animation: spin-once 0.45s ease;
}

@keyframes spin-once {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* Random card */
.random-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 64px;
  border: 1.5px solid var(--border);
  transition: border-color 0.2s ease, background 0.2s ease;
}

.random-card.has-task {
  border-color: var(--accent);
  background: var(--accent-pale);
}

.random-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

.random-card.has-task .random-dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(200,80,42,0.15);
}

.random-task {
  flex: 1;
  font-size: 16px;
  font-weight: 400;
  color: var(--ink);
  line-height: 1.4;
}

.random-task-placeholder {
  color: var(--ink-muted);
  font-weight: 300;
  font-style: italic;
  font-size: 14px;
}

.done-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  border-radius: 100px;
  padding: 7px 14px;
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
  flex-shrink: 0;
  letter-spacing: 0.01em;
}

.done-btn:hover { background: #B8411E; }
.done-btn:active { transform: scale(0.93); }

/* Section label */
.section-label {
  width: 100%;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 14px;
}

/* Todo list */
.todo-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 24px;
  list-style: none;
}

.todo-item {
  background: var(--surface);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: background 0.15s ease, opacity 0.3s ease, transform 0.3s ease;
  animation: slide-in 0.25s ease;
}

@keyframes slide-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.todo-item:hover { background: #FAFAF8; }

.todo-item--editing {
  display: block;
}

.check-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  color: transparent;
  padding: 0;
}

.check-btn:hover {
  border-color: var(--accent);
  background: var(--accent-pale);
  color: var(--accent);
}

.check-btn svg { width: 11px; height: 11px; stroke-width: 2.5; }

.todo-text-button {
  flex: 1;
  border: none;
  background: transparent;
  text-align: left;
  padding: 0;
  cursor: pointer;
  min-width: 0;
}

.todo-text {
  flex: 1;
  font-size: 15px;
  font-weight: 300;
  color: var(--ink);
  line-height: 1.4;
}

.todo-delete {
  opacity: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--ink-muted);
  padding: 4px;
  border-radius: 6px;
  transition: opacity 0.15s ease, color 0.15s ease;
  display: flex;
  align-items: center;
}

.todo-item:hover .todo-delete { opacity: 1; }
.todo-delete:hover { color: var(--accent); }
.todo-delete svg { width: 14px; height: 14px; }

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

.check-btn--completed:hover {
  border-color: var(--accent);
  background: transparent;
  color: transparent;
}

.todo-item--completed .todo-text {
  color: var(--ink-muted);
  text-decoration: line-through;
}

.edit-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.edit-input {
  flex: 1;
  min-width: 0;
  border: 1.5px solid var(--accent);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  padding: 10px 12px;
  outline: none;
}

.edit-action {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--ink-muted);
  border-radius: 999px;
  padding: 8px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
}

.edit-action--save {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.edit-error {
  margin-top: 8px;
  color: var(--accent);
  font-size: 13px;
}

/* Empty state */
.empty-state {
  width: 100%;
  text-align: center;
  padding: 32px 0 20px;
  color: var(--ink-muted);
  font-size: 14px;
  font-weight: 300;
  font-style: italic;
}

/* Add input (fixed bottom) */
.add-section {
  width: 100%;
  max-width: 480px;
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  padding: 16px 24px 28px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.add-row {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  display: flex;
  align-items: center;
  padding: 4px 4px 4px 18px;
  gap: 10px;
  box-shadow: var(--shadow);
  transition: border-color 0.2s ease;
}

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

.add-input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  font-weight: 300;
  color: var(--ink);
  outline: none;
  padding: 10px 0;
}

.add-input::placeholder { color: var(--ink-muted); }

.add-submit {
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: 10px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.1s ease;
}

.add-submit:hover { background: var(--accent); }
.add-submit:active { transform: scale(0.92); }
.add-submit svg { width: 16px; height: 16px; }

.form-error {
  margin: 6px 0 0;
  padding: 0 18px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 400;
}

/* Shake animation for empty pick */
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

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

@media (max-width: 640px) {
  body {
    padding: 28px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  }

  .page-header {
    margin-bottom: 28px;
  }

  .random-trigger {
    flex-wrap: wrap;
    gap: 10px;
  }

  .random-card {
    align-items: flex-start;
    padding: 16px;
  }

  .done-btn {
    align-self: flex-start;
  }

  .todo-delete {
    opacity: 1;
  }

  .edit-row {
    flex-wrap: wrap;
  }

  .add-section {
    position: sticky;
    left: auto;
    bottom: 0;
    transform: none;
    margin-top: 18px;
    padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .spin-btn,
  .todo-item,
  .random-card,
  .done-btn,
  .add-submit,
  .check-btn {
    transition: none;
  }
  .spin-btn.spinning .spin-icon { animation: none; }
  .todo-item { animation: none; }
}
