:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --text: #1c1c1e;
  --text-secondary: #8e8e93;
  --separator: #c6c6c8;
  --segment-bg: #e5e5ea;
  --segment-active: #ffffff;
  --accent: #007aff;
  --success: #34c759;
  --danger: #ff3b30;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  --radius-card: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
}

button,
input {
  font: inherit;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(12px + var(--safe-top)) 0 calc(24px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.top-bar {
  padding: 8px 20px 0;
}

.top-bar-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.top-bar h1 {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.user-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  padding-top: 6px;
  max-width: 45%;
}

.user-chip span {
  font-size: 0.85rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.logout-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0;
  cursor: pointer;
}

.login-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
}

.login-screen[hidden],
.app[hidden] {
  display: none !important;
}

.login-card {
  width: min(100%, 400px);
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px 22px;
  text-align: center;
}

.login-icon {
  border-radius: 16px;
  margin-bottom: 12px;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
}

.login-copy {
  margin: 0 0 20px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.provider-buttons {
  display: grid;
  gap: 10px;
}

.provider-btn {
  display: block;
  text-decoration: none;
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 650;
  color: #fff;
  background: #1c1c1e;
}

.provider-google {
  background: #fff;
  color: #1c1c1e;
  border: 1px solid #d2d2d7;
}

.provider-facebook {
  background: #1877f2;
}

.provider-apple {
  background: #000;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  margin: 0 16px;
  padding: 2px;
  background: var(--segment-bg);
  border-radius: 10px;
}

.segment {
  border: 0;
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.94rem;
  font-weight: 560;
  cursor: pointer;
}

.segment.is-active {
  background: var(--segment-active);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.add-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
}

.add-row.is-hidden {
  display: none;
}

#new-task {
  flex: 1;
  border: 0;
  outline: none;
  background: #e5e5ea;
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
}

#new-task::placeholder {
  color: var(--text-secondary);
}

.add-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 0;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.add-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.list-wrap {
  position: relative;
  flex: 1;
  min-height: 240px;
}

.task-list {
  list-style: none;
  margin: 0;
  padding: 4px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 14px 14px;
  touch-action: manipulation;
  user-select: none;
  transform: translateX(0) scale(1);
  opacity: 1;
  max-height: 120px;
  transition:
    transform 280ms cubic-bezier(0.22, 1, 0.36, 1),
    opacity 240ms ease,
    max-height 280ms ease,
    margin 280ms ease,
    padding 280ms ease,
    box-shadow 200ms ease;
}

.task-card.is-dragging {
  opacity: 0.55;
}

.task-card.is-leaving {
  pointer-events: none;
  opacity: 0;
  max-height: 0;
  margin-top: 0;
  margin-bottom: 0;
  padding-top: 0;
  padding-bottom: 0;
  box-shadow: none;
  overflow: hidden;
}

.task-card.is-leaving.exit-someday {
  transform: translateX(28px) scale(0.98);
}

.task-card.is-leaving.exit-today {
  transform: translateX(-28px) scale(0.98);
}

.task-card.is-entering {
  animation: task-enter 280ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes task-enter {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.drag-handle {
  width: 18px;
  color: var(--separator);
  cursor: grab;
  display: grid;
  gap: 3px;
  padding: 4px 2px;
}

.drag-handle span {
  display: block;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}

.check-btn,
.move-btn,
.delete-btn {
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0;
}

.check-btn {
  width: 28px;
  height: 28px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.check-btn.is-done {
  color: var(--success);
}

.task-title {
  flex: 1;
  min-width: 0;
  font-size: 1rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 0;
  cursor: text;
}

.task-title.is-done {
  color: var(--text-secondary);
  text-decoration: line-through;
}

.task-edit {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 2px solid var(--accent);
  outline-offset: 0;
  background: #e5e5ea;
  border-radius: 8px;
  padding: 8px 10px;
  color: #1c1c1e;
  -webkit-text-fill-color: #1c1c1e;
  caret-color: #1c1c1e;
  font: inherit;
  color-scheme: light;
}

.move-btn {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--text);
  background: #e5e5ea;
  border-radius: 6px;
  padding: 6px 8px;
  transition:
    transform 160ms ease,
    background-color 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease;
}

.move-btn:hover {
  background: #d7ebff;
  color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 122, 255, 0.18);
}

.move-btn:active,
.move-btn.is-pressed {
  background: var(--accent);
  color: #fff;
  transform: scale(0.96);
  box-shadow: none;
}

@media (hover: none) {
  .move-btn:hover {
    background: #e5e5ea;
    color: var(--text);
    transform: none;
    box-shadow: none;
  }
}

.delete-btn {
  flex-shrink: 0;
  color: var(--danger);
  font-size: 0.75rem;
  padding: 6px 4px;
  opacity: 0.85;
}

.empty-state {
  position: absolute;
  inset: 48px 24px auto;
  text-align: center;
  color: var(--text-secondary);
}

.empty-state[hidden] {
  display: none;
}

.empty-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  opacity: 0.55;
}

.empty-state h2 {
  margin: 0 0 6px;
  font-size: 1.2rem;
  color: var(--text);
  font-weight: 650;
}

.empty-state p {
  margin: 0;
  font-size: 0.95rem;
}

.status {
  margin: 0 16px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fff3cd;
  color: #664d03;
  font-size: 0.9rem;
}

.status[hidden] {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --text: #f5f5f7;
    --text-secondary: #8e8e93;
    --separator: #3a3a3c;
    --segment-bg: #1c1c1e;
    --segment-active: #2c2c2e;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }

  #new-task,
  .move-btn {
    background: #2c2c2e;
  }

  .move-btn:hover {
    background: #1a3a5c;
    color: #7cc4ff;
  }

  .move-btn:active,
  .move-btn.is-pressed {
    background: var(--accent);
    color: #fff;
  }

  .task-edit {
    background: #2c2c2e;
    color: #f5f5f7;
    -webkit-text-fill-color: #f5f5f7;
    caret-color: #f5f5f7;
    color-scheme: dark;
  }

  .segmented {
    border: 1px solid #2c2c2e;
  }
}

@media (prefers-reduced-motion: reduce) {
  .task-card,
  .move-btn,
  .task-card.is-entering {
    transition: none !important;
    animation: none !important;
  }
}
